Commit 4e6f6aac authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'fguibert/refactor-shared-board-actions' into 'master'

Refactor shared board action [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!60571
parents cc59a8c9 7a075fa2
import boardListsQuery from 'ee_else_ce/boards/graphql/board_lists.query.graphql';
import { __ } from '~/locale'; import { __ } from '~/locale';
import updateEpicSubscriptionMutation from '~/sidebar/queries/update_epic_subscription.mutation.graphql'; import updateEpicSubscriptionMutation from '~/sidebar/queries/update_epic_subscription.mutation.graphql';
import updateEpicTitleMutation from '~/sidebar/queries/update_epic_title.mutation.graphql'; import updateEpicTitleMutation from '~/sidebar/queries/update_epic_title.mutation.graphql';
import boardBlockingIssuesQuery from './graphql/board_blocking_issues.query.graphql'; import boardBlockingIssuesQuery from './graphql/board_blocking_issues.query.graphql';
import destroyBoardListMutation from './graphql/board_list_destroy.mutation.graphql'; import destroyBoardListMutation from './graphql/board_list_destroy.mutation.graphql';
import updateBoardListMutation from './graphql/board_list_update.mutation.graphql'; import updateBoardListMutation from './graphql/board_list_update.mutation.graphql';
import issueSetSubscriptionMutation from './graphql/issue_set_subscription.mutation.graphql'; import issueSetSubscriptionMutation from './graphql/issue_set_subscription.mutation.graphql';
import issueSetTitleMutation from './graphql/issue_set_title.mutation.graphql'; import issueSetTitleMutation from './graphql/issue_set_title.mutation.graphql';
...@@ -62,6 +64,12 @@ export const NOT_FILTER = 'not['; ...@@ -62,6 +64,12 @@ export const NOT_FILTER = 'not[';
export const flashAnimationDuration = 2000; export const flashAnimationDuration = 2000;
export const listsQuery = {
[issuableTypes.issue]: {
query: boardListsQuery,
},
};
export const blockingIssuablesQueries = { export const blockingIssuablesQueries = {
[issuableTypes.issue]: { [issuableTypes.issue]: {
query: boardBlockingIssuesQuery, query: boardBlockingIssuesQuery,
......
...@@ -37,6 +37,7 @@ import { ...@@ -37,6 +37,7 @@ import {
import { __ } from '~/locale'; import { __ } from '~/locale';
import sidebarEventHub from '~/sidebar/event_hub'; import sidebarEventHub from '~/sidebar/event_hub';
import introspectionQueryResultData from '~/sidebar/fragmentTypes.json'; import introspectionQueryResultData from '~/sidebar/fragmentTypes.json';
import { fullBoardId } from './boards_util';
import boardConfigToggle from './config_toggle'; import boardConfigToggle from './config_toggle';
import mountMultipleBoardsSwitcher from './mount_multiple_boards_switcher'; import mountMultipleBoardsSwitcher from './mount_multiple_boards_switcher';
...@@ -135,6 +136,7 @@ export default () => { ...@@ -135,6 +136,7 @@ export default () => {
created() { created() {
this.setInitialBoardData({ this.setInitialBoardData({
boardId: $boardApp.dataset.boardId, boardId: $boardApp.dataset.boardId,
fullBoardId: fullBoardId($boardApp.dataset.boardId),
fullPath: $boardApp.dataset.fullPath, fullPath: $boardApp.dataset.fullPath,
boardType: this.parent, boardType: this.parent,
disabled: this.disabled, disabled: this.disabled,
......
...@@ -9,10 +9,11 @@ import { ...@@ -9,10 +9,11 @@ import {
subscriptionQueries, subscriptionQueries,
SupportedFilters, SupportedFilters,
deleteListQueries, deleteListQueries,
listsQuery,
updateListQueries, updateListQueries,
issuableTypes,
} from 'ee_else_ce/boards/constants'; } from 'ee_else_ce/boards/constants';
import createBoardListMutation from 'ee_else_ce/boards/graphql/board_list_create.mutation.graphql'; import createBoardListMutation from 'ee_else_ce/boards/graphql/board_list_create.mutation.graphql';
import boardListsQuery from 'ee_else_ce/boards/graphql/board_lists.query.graphql';
import issueMoveListMutation from 'ee_else_ce/boards/graphql/issue_move_list.mutation.graphql'; import issueMoveListMutation from 'ee_else_ce/boards/graphql/issue_move_list.mutation.graphql';
import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import createGqClient, { fetchPolicies } from '~/lib/graphql'; import createGqClient, { fetchPolicies } from '~/lib/graphql';
...@@ -21,7 +22,6 @@ import { s__ } from '~/locale'; ...@@ -21,7 +22,6 @@ import { s__ } from '~/locale';
import { import {
formatBoardLists, formatBoardLists,
formatListIssues, formatListIssues,
fullBoardId,
formatListsPageInfo, formatListsPageInfo,
formatIssue, formatIssue,
formatIssueInput, formatIssueInput,
...@@ -86,24 +86,22 @@ export default { ...@@ -86,24 +86,22 @@ export default {
} }
}, },
fetchLists: ({ dispatch }) => { fetchLists: ({ commit, state, dispatch }) => {
dispatch('fetchIssueLists'); const { boardType, filterParams, fullPath, fullBoardId, issuableType } = state;
},
fetchIssueLists: ({ commit, state, dispatch }) => {
const { boardType, filterParams, fullPath, boardId } = state;
const variables = { const variables = {
fullPath, fullPath,
boardId: fullBoardId(boardId), boardId: fullBoardId,
filters: filterParams, filters: filterParams,
...(issuableType === issuableTypes.issue && {
isGroup: boardType === BoardType.group, isGroup: boardType === BoardType.group,
isProject: boardType === BoardType.project, isProject: boardType === BoardType.project,
}),
}; };
return gqlClient return gqlClient
.query({ .query({
query: boardListsQuery, query: listsQuery[issuableType].query,
variables, variables,
}) })
.then(({ data }) => { .then(({ data }) => {
...@@ -137,7 +135,7 @@ export default { ...@@ -137,7 +135,7 @@ export default {
{ state, commit, dispatch, getters }, { state, commit, dispatch, getters },
{ backlog, labelId, milestoneId, assigneeId, iterationId }, { backlog, labelId, milestoneId, assigneeId, iterationId },
) => { ) => {
const { boardId } = state; const { fullBoardId } = state;
const existingList = getters.getListByLabelId(labelId); const existingList = getters.getListByLabelId(labelId);
...@@ -150,7 +148,7 @@ export default { ...@@ -150,7 +148,7 @@ export default {
.mutate({ .mutate({
mutation: createBoardListMutation, mutation: createBoardListMutation,
variables: { variables: {
boardId: fullBoardId(boardId), boardId: fullBoardId,
backlog, backlog,
labelId, labelId,
milestoneId, milestoneId,
...@@ -296,11 +294,11 @@ export default { ...@@ -296,11 +294,11 @@ export default {
fetchItemsForList: ({ state, commit }, { listId, fetchNext = false }) => { fetchItemsForList: ({ state, commit }, { listId, fetchNext = false }) => {
commit(types.REQUEST_ITEMS_FOR_LIST, { listId, fetchNext }); commit(types.REQUEST_ITEMS_FOR_LIST, { listId, fetchNext });
const { fullPath, boardId, boardType, filterParams } = state; const { fullPath, fullBoardId, boardType, filterParams } = state;
const variables = { const variables = {
fullPath, fullPath,
boardId: fullBoardId(boardId), boardId: fullBoardId,
id: listId, id: listId,
filters: filterParams, filters: filterParams,
isGroup: boardType === BoardType.group, isGroup: boardType === BoardType.group,
...@@ -429,7 +427,7 @@ export default { ...@@ -429,7 +427,7 @@ export default {
try { try {
const { itemId, fromListId, toListId, moveBeforeId, moveAfterId } = moveData; const { itemId, fromListId, toListId, moveBeforeId, moveAfterId } = moveData;
const { const {
boardId, fullBoardId,
boardItems: { boardItems: {
[itemId]: { iid, referencePath }, [itemId]: { iid, referencePath },
}, },
...@@ -440,7 +438,7 @@ export default { ...@@ -440,7 +438,7 @@ export default {
variables: { variables: {
iid, iid,
projectPath: referencePath.split(/[#]/)[0], projectPath: referencePath.split(/[#]/)[0],
boardId: fullBoardId(boardId), boardId: fullBoardId,
fromListId: getIdFromGraphQLId(fromListId), fromListId: getIdFromGraphQLId(fromListId),
toListId: getIdFromGraphQLId(toListId), toListId: getIdFromGraphQLId(toListId),
moveBeforeId, moveBeforeId,
......
...@@ -40,8 +40,9 @@ export const addItemToList = ({ state, listId, itemId, moveBeforeId, moveAfterId ...@@ -40,8 +40,9 @@ export const addItemToList = ({ state, listId, itemId, moveBeforeId, moveAfterId
export default { export default {
[mutationTypes.SET_INITIAL_BOARD_DATA](state, data) { [mutationTypes.SET_INITIAL_BOARD_DATA](state, data) {
const { boardType, disabled, boardId, fullPath, boardConfig, issuableType } = data; const { boardType, disabled, boardId, fullBoardId, fullPath, boardConfig, issuableType } = data;
state.boardId = boardId; state.boardId = boardId;
state.fullBoardId = fullBoardId;
state.fullPath = fullPath; state.fullPath = fullPath;
state.boardType = boardType; state.boardType = boardType;
state.disabled = disabled; state.disabled = disabled;
......
/* eslint-disable import/export */
import { issuableTypes } from '~/boards/constants'; import { issuableTypes } from '~/boards/constants';
import destroyBoardListMutation from '~/boards/graphql/board_list_destroy.mutation.graphql'; import destroyBoardListMutation from '~/boards/graphql/board_list_destroy.mutation.graphql';
import updateBoardListMutation from '~/boards/graphql/board_list_update.mutation.graphql'; import updateBoardListMutation from '~/boards/graphql/board_list_update.mutation.graphql';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import boardListsQuery from './graphql/board_lists.query.graphql';
import destroyEpicBoardListMutation from './graphql/epic_board_list_destroy.mutation.graphql'; import destroyEpicBoardListMutation from './graphql/epic_board_list_destroy.mutation.graphql';
import updateEpicBoardListMutation from './graphql/epic_board_list_update.mutation.graphql'; import updateEpicBoardListMutation from './graphql/epic_board_list_update.mutation.graphql';
import epicBoardListsQuery from './graphql/epic_board_lists.query.graphql';
export * from '~/boards/constants';
export const DRAGGABLE_TAG = 'div'; export const DRAGGABLE_TAG = 'div';
...@@ -61,6 +66,15 @@ export const ErrorMessages = { ...@@ -61,6 +66,15 @@ export const ErrorMessages = {
), ),
}; };
export const listsQuery = {
[issuableTypes.issue]: {
query: boardListsQuery,
},
[issuableTypes.epic]: {
query: epicBoardListsQuery,
},
};
export const updateListQueries = { export const updateListQueries = {
[issuableTypes.issue]: { [issuableTypes.issue]: {
mutation: updateBoardListMutation, mutation: updateBoardListMutation,
...@@ -79,22 +93,7 @@ export const deleteListQueries = { ...@@ -79,22 +93,7 @@ export const deleteListQueries = {
}, },
}; };
// re-export some FOSS constants so that lint does not yell
// https://gitlab.com/gitlab-org/gitlab/-/issues/329164
export {
BoardType,
ListType,
inactiveId,
flashAnimationDuration,
ISSUABLE,
titleQueries,
subscriptionQueries,
SupportedFilters,
} from '~/boards/constants';
export default { export default {
deleteListQueries,
updateListQueries,
DRAGGABLE_TAG, DRAGGABLE_TAG,
EpicFilterType, EpicFilterType,
}; };
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
query ListEpics($fullPath: ID!, $boardId: BoardsEpicBoardID!) { query ListEpics($fullPath: ID!, $boardId: BoardsEpicBoardID!) {
group(fullPath: $fullPath) { group(fullPath: $fullPath) {
epicBoard(id: $boardId) { board: epicBoard(id: $boardId) {
lists { lists {
nodes { nodes {
...EpicBoardListFragment ...EpicBoardListFragment
......
import { import {
formatBoardLists,
formatListIssues, formatListIssues,
formatListsPageInfo, formatListsPageInfo,
fullBoardId, fullBoardId,
...@@ -10,10 +9,9 @@ import { ...@@ -10,10 +9,9 @@ import {
import { BoardType, SupportedFilters } from '~/boards/constants'; import { BoardType, SupportedFilters } from '~/boards/constants';
import eventHub from '~/boards/eventhub'; import eventHub from '~/boards/eventhub';
import listsIssuesQuery from '~/boards/graphql/lists_issues.query.graphql'; import listsIssuesQuery from '~/boards/graphql/lists_issues.query.graphql';
import actionsCE from '~/boards/stores/actions'; import actionsCE, { gqlClient } from '~/boards/stores/actions';
import boardsStore from '~/boards/stores/boards_store'; import boardsStore from '~/boards/stores/boards_store';
import * as typesCE from '~/boards/stores/mutation_types'; import * as typesCE from '~/boards/stores/mutation_types';
import createGqClient, { fetchPolicies } from '~/lib/graphql';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { import {
historyPushState, historyPushState,
...@@ -36,7 +34,6 @@ import { ...@@ -36,7 +34,6 @@ import {
} from '../constants'; } from '../constants';
import epicQuery from '../graphql/epic.query.graphql'; import epicQuery from '../graphql/epic.query.graphql';
import createEpicBoardListMutation from '../graphql/epic_board_list_create.mutation.graphql'; import createEpicBoardListMutation from '../graphql/epic_board_list_create.mutation.graphql';
import epicBoardListsQuery from '../graphql/epic_board_lists.query.graphql';
import epicMoveListMutation from '../graphql/epic_move_list.mutation.graphql'; import epicMoveListMutation from '../graphql/epic_move_list.mutation.graphql';
import epicsSwimlanesQuery from '../graphql/epics_swimlanes.query.graphql'; import epicsSwimlanesQuery from '../graphql/epics_swimlanes.query.graphql';
import groupBoardAssigneesQuery from '../graphql/group_board_assignees.query.graphql'; import groupBoardAssigneesQuery from '../graphql/group_board_assignees.query.graphql';
...@@ -60,13 +57,6 @@ const notImplemented = () => { ...@@ -60,13 +57,6 @@ const notImplemented = () => {
throw new Error('Not implemented!'); throw new Error('Not implemented!');
}; };
export const gqlClient = createGqClient(
{},
{
fetchPolicy: fetchPolicies.NO_CACHE,
},
);
const fetchAndFormatListIssues = (state, extraVariables) => { const fetchAndFormatListIssues = (state, extraVariables) => {
const { fullPath, boardId, boardType, filterParams } = state; const { fullPath, boardId, boardType, filterParams } = state;
...@@ -117,6 +107,8 @@ const fetchAndFormatListEpics = (state, extraVariables) => { ...@@ -117,6 +107,8 @@ const fetchAndFormatListEpics = (state, extraVariables) => {
}); });
}; };
export { gqlClient };
export default { export default {
...actionsCE, ...actionsCE,
...@@ -161,7 +153,7 @@ export default { ...@@ -161,7 +153,7 @@ export default {
dispatch('resetEpics'); dispatch('resetEpics');
dispatch('resetIssues'); dispatch('resetIssues');
dispatch('fetchEpicsSwimlanes'); dispatch('fetchEpicsSwimlanes');
dispatch('fetchIssueLists'); dispatch('fetchLists');
} else if (gon.features.graphqlBoardLists || getters.isEpicBoard) { } else if (gon.features.graphqlBoardLists || getters.isEpicBoard) {
dispatch('fetchLists'); dispatch('fetchLists');
dispatch('resetIssues'); dispatch('resetIssues');
...@@ -351,7 +343,7 @@ export default { ...@@ -351,7 +343,7 @@ export default {
}), }),
); );
dispatch('fetchEpicsSwimlanes'); dispatch('fetchEpicsSwimlanes');
dispatch('fetchIssueLists'); dispatch('fetchLists');
} else if (!gon.features.graphqlBoardLists) { } else if (!gon.features.graphqlBoardLists) {
historyPushState(removeParams(['group_by']), window.location.href, true); historyPushState(removeParams(['group_by']), window.location.href, true);
boardsStore.create(); boardsStore.create();
...@@ -538,35 +530,6 @@ export default { ...@@ -538,35 +530,6 @@ export default {
); );
}, },
fetchLists: ({ getters, dispatch }) => {
if (!getters.isEpicBoard) {
dispatch('fetchIssueLists');
} else {
dispatch('fetchEpicLists');
}
},
fetchEpicLists: ({ commit, state }) => {
const { filterParams, fullPath, boardId } = state;
const variables = {
fullPath,
boardId: fullEpicBoardId(boardId),
filters: filterParams,
};
return gqlClient
.query({
query: epicBoardListsQuery,
variables,
})
.then(({ data }) => {
const { lists } = data.group?.epicBoard;
commit(types.RECEIVE_BOARD_LISTS_SUCCESS, formatBoardLists(lists));
})
.catch(() => commit(types.RECEIVE_BOARD_LISTS_FAILURE));
},
fetchMilestones({ state, commit }, searchTerm) { fetchMilestones({ state, commit }, searchTerm) {
commit(types.RECEIVE_MILESTONES_REQUEST); commit(types.RECEIVE_MILESTONES_REQUEST);
......
...@@ -6,7 +6,7 @@ import Vue from 'vue'; ...@@ -6,7 +6,7 @@ import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import { transformBoardConfig } from 'ee_component/boards/boards_util'; import { fullEpicBoardId, transformBoardConfig } from 'ee_component/boards/boards_util';
import BoardSidebar from 'ee_component/boards/components/board_sidebar'; import BoardSidebar from 'ee_component/boards/components/board_sidebar';
import toggleLabels from 'ee_component/boards/toggle_labels'; import toggleLabels from 'ee_component/boards/toggle_labels';
...@@ -99,6 +99,7 @@ export default () => { ...@@ -99,6 +99,7 @@ export default () => {
created() { created() {
this.setInitialBoardData({ this.setInitialBoardData({
boardId: $boardApp.dataset.boardId, boardId: $boardApp.dataset.boardId,
fullBoardId: fullEpicBoardId($boardApp.dataset.boardId),
fullPath: $boardApp.dataset.fullPath, fullPath: $boardApp.dataset.fullPath,
boardType: this.parent, boardType: this.parent,
disabled: this.disabled, disabled: this.disabled,
......
...@@ -2,7 +2,7 @@ import axios from 'axios'; ...@@ -2,7 +2,7 @@ import axios from 'axios';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import Vue from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { GroupByParamType } from 'ee/boards/constants'; import { BoardType, GroupByParamType, listsQuery, issuableTypes } from 'ee/boards/constants';
import actions, { gqlClient } from 'ee/boards/stores/actions'; import actions, { gqlClient } from 'ee/boards/stores/actions';
import boardsStoreEE from 'ee/boards/stores/boards_store_ee'; import boardsStoreEE from 'ee/boards/stores/boards_store_ee';
import * as types from 'ee/boards/stores/mutation_types'; import * as types from 'ee/boards/stores/mutation_types';
...@@ -10,8 +10,7 @@ import mutations from 'ee/boards/stores/mutations'; ...@@ -10,8 +10,7 @@ import mutations from 'ee/boards/stores/mutations';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import testAction from 'helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import { mockMoveIssueParams, mockMoveData, mockMoveState } from 'jest/boards/mock_data'; import { mockMoveIssueParams, mockMoveData, mockMoveState } from 'jest/boards/mock_data';
import { formatBoardLists, formatListIssues } from '~/boards/boards_util'; import { formatListIssues } from '~/boards/boards_util';
import { issuableTypes } from '~/boards/constants';
import listsIssuesQuery from '~/boards/graphql/lists_issues.query.graphql'; import listsIssuesQuery from '~/boards/graphql/lists_issues.query.graphql';
import * as typesCE from '~/boards/stores/mutation_types'; import * as typesCE from '~/boards/stores/mutation_types';
import * as commonUtils from '~/lib/utils/common_utils'; import * as commonUtils from '~/lib/utils/common_utils';
...@@ -137,7 +136,7 @@ describe('performSearch', () => { ...@@ -137,7 +136,7 @@ describe('performSearch', () => {
}); });
}); });
it('should dispatch setFilters, resetEpics, fetchEpicsSwimlanes, fetchIssueLists and resetIssues action when isSwimlanesOn', async () => { it('should dispatch setFilters, resetEpics, fetchEpicsSwimlanes, fetchLists and resetIssues action when isSwimlanesOn', async () => {
const getters = { isSwimlanesOn: true }; const getters = { isSwimlanesOn: true };
await testAction({ await testAction({
action: actions.performSearch, action: actions.performSearch,
...@@ -147,81 +146,61 @@ describe('performSearch', () => { ...@@ -147,81 +146,61 @@ describe('performSearch', () => {
{ type: 'resetEpics' }, { type: 'resetEpics' },
{ type: 'resetIssues' }, { type: 'resetIssues' },
{ type: 'fetchEpicsSwimlanes' }, { type: 'fetchEpicsSwimlanes' },
{ type: 'fetchIssueLists' }, { type: 'fetchLists' },
], ],
}); });
}); });
}); });
describe('fetchLists', () => { describe('fetchLists', () => {
it('should dispatch fetchIssueLists action when isEpicBoard is false', async () => {
const getters = { isEpicBoard: false };
await testAction({
action: actions.fetchLists,
state: { issuableType: issuableTypes.issue, ...getters },
expectedActions: [{ type: 'fetchIssueLists' }],
});
});
it('should dispatch fetchEpicLists action when isEpicBoard is true', async () => {
const getters = { isEpicBoard: true };
await testAction({
action: actions.fetchLists,
state: { issuableType: issuableTypes.epic, ...getters },
expectedActions: [{ type: 'fetchEpicLists' }],
});
});
});
describe('fetchEpicLists', () => {
const state = {
fullPath: 'gitlab-org',
boardId: '1',
filterParams: {},
};
const queryResponse = { const queryResponse = {
data: { data: {
group: { group: {
epicBoard: { board: {
hideBacklogList: true,
lists: { lists: {
nodes: mockLists, nodes: [mockLists[1]],
}, },
}, },
}, },
}, },
}; };
const formattedLists = formatBoardLists(queryResponse.data.group.epicBoard.lists); it.each`
issuableType | boardType | fullBoardId | isGroup | isProject
${issuableTypes.epic} | ${BoardType.group} | ${'gid://gitlab/Boards::EpicBoard/1'} | ${undefined} | ${undefined}
`(
'calls $issuableType query with correct variables',
async ({ issuableType, boardType, fullBoardId, isGroup, isProject }) => {
const commit = jest.fn();
const dispatch = jest.fn();
it('should commit mutations RECEIVE_BOARD_LISTS_SUCCESS on success', async () => { const state = {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse); fullPath: 'gitlab-org',
fullBoardId,
filterParams: {},
boardType,
issuableType,
};
await testAction({ const variables = {
action: actions.fetchEpicLists, query: listsQuery[issuableType].query,
state, variables: {
expectedMutations: [ fullPath: 'gitlab-org',
{ boardId: fullBoardId,
type: types.RECEIVE_BOARD_LISTS_SUCCESS, filters: {},
payload: formattedLists, isGroup,
isProject,
}, },
], };
});
});
it('should commit mutations RECEIVE_BOARD_LISTS_FAILURE on failure', async () => { jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
jest.spyOn(gqlClient, 'query').mockResolvedValue(Promise.reject());
await testAction({ await actions.fetchLists({ commit, state, dispatch });
action: actions.fetchEpicLists,
state, expect(gqlClient.query).toHaveBeenCalledWith(variables);
expectedMutations: [
{
type: types.RECEIVE_BOARD_LISTS_FAILURE,
}, },
], );
});
});
}); });
describe('fetchEpicsSwimlanes', () => { describe('fetchEpicsSwimlanes', () => {
...@@ -595,7 +574,7 @@ describe('toggleEpicSwimlanes', () => { ...@@ -595,7 +574,7 @@ describe('toggleEpicSwimlanes', () => {
); );
}); });
it('should dispatch fetchEpicsSwimlanes and fetchIssueLists actions when isShowingEpicsSwimlanes is true', () => { it('should dispatch fetchEpicsSwimlanes and fetchLists actions when isShowingEpicsSwimlanes is true', () => {
global.jsdom.reconfigure({ global.jsdom.reconfigure({
url: `${TEST_HOST}/groups/gitlab-org/-/boards/1`, url: `${TEST_HOST}/groups/gitlab-org/-/boards/1`,
}); });
...@@ -613,7 +592,7 @@ describe('toggleEpicSwimlanes', () => { ...@@ -613,7 +592,7 @@ describe('toggleEpicSwimlanes', () => {
null, null,
state, state,
[{ type: types.TOGGLE_EPICS_SWIMLANES }], [{ type: types.TOGGLE_EPICS_SWIMLANES }],
[{ type: 'fetchEpicsSwimlanes' }, { type: 'fetchIssueLists' }], [{ type: 'fetchEpicsSwimlanes' }, { type: 'fetchLists' }],
() => { () => {
expect(commonUtils.historyPushState).toHaveBeenCalledWith( expect(commonUtils.historyPushState).toHaveBeenCalledWith(
mergeUrlParams({ group_by: GroupByParamType.epic }, window.location.href), mergeUrlParams({ group_by: GroupByParamType.epic }, window.location.href),
......
import * as Sentry from '@sentry/browser'; import * as Sentry from '@sentry/browser';
import {
inactiveId,
ISSUABLE,
ListType,
issuableTypes,
BoardType,
listsQuery,
} from 'ee_else_ce/boards/constants';
import issueMoveListMutation from 'ee_else_ce/boards/graphql/issue_move_list.mutation.graphql'; import issueMoveListMutation from 'ee_else_ce/boards/graphql/issue_move_list.mutation.graphql';
import testAction from 'helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import { import {
fullBoardId,
formatListIssues, formatListIssues,
formatBoardLists, formatBoardLists,
formatIssueInput, formatIssueInput,
formatIssue, formatIssue,
getMoveData, getMoveData,
} from '~/boards/boards_util'; } from '~/boards/boards_util';
import { inactiveId, ISSUABLE, ListType, issuableTypes } from '~/boards/constants';
import destroyBoardListMutation from '~/boards/graphql/board_list_destroy.mutation.graphql'; import destroyBoardListMutation from '~/boards/graphql/board_list_destroy.mutation.graphql';
import issueCreateMutation from '~/boards/graphql/issue_create.mutation.graphql'; import issueCreateMutation from '~/boards/graphql/issue_create.mutation.graphql';
import actions, { gqlClient } from '~/boards/stores/actions'; import actions, { gqlClient } from '~/boards/stores/actions';
...@@ -132,20 +138,12 @@ describe('setActiveId', () => { ...@@ -132,20 +138,12 @@ describe('setActiveId', () => {
}); });
describe('fetchLists', () => { describe('fetchLists', () => {
it('should dispatch fetchIssueLists action', () => { let state = {
testAction({
action: actions.fetchLists,
expectedActions: [{ type: 'fetchIssueLists' }],
});
});
});
describe('fetchIssueLists', () => {
const state = {
fullPath: 'gitlab-org', fullPath: 'gitlab-org',
boardId: '1', fullBoardId: 'gid://gitlab/Board/1',
filterParams: {}, filterParams: {},
boardType: 'group', boardType: 'group',
issuableType: 'issue',
}; };
let queryResponse = { let queryResponse = {
...@@ -167,7 +165,7 @@ describe('fetchIssueLists', () => { ...@@ -167,7 +165,7 @@ describe('fetchIssueLists', () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse); jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction( testAction(
actions.fetchIssueLists, actions.fetchLists,
{}, {},
state, state,
[ [
...@@ -185,7 +183,7 @@ describe('fetchIssueLists', () => { ...@@ -185,7 +183,7 @@ describe('fetchIssueLists', () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(Promise.reject()); jest.spyOn(gqlClient, 'query').mockResolvedValue(Promise.reject());
testAction( testAction(
actions.fetchIssueLists, actions.fetchLists,
{}, {},
state, state,
[ [
...@@ -214,7 +212,7 @@ describe('fetchIssueLists', () => { ...@@ -214,7 +212,7 @@ describe('fetchIssueLists', () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse); jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction( testAction(
actions.fetchIssueLists, actions.fetchLists,
{}, {},
state, state,
[ [
...@@ -227,6 +225,43 @@ describe('fetchIssueLists', () => { ...@@ -227,6 +225,43 @@ describe('fetchIssueLists', () => {
done, done,
); );
}); });
it.each`
issuableType | boardType | fullBoardId | isGroup | isProject
${issuableTypes.issue} | ${BoardType.group} | ${'gid://gitlab/Board/1'} | ${true} | ${false}
${issuableTypes.issue} | ${BoardType.project} | ${'gid://gitlab/Board/1'} | ${false} | ${true}
`(
'calls $issuableType query with correct variables',
async ({ issuableType, boardType, fullBoardId, isGroup, isProject }) => {
const commit = jest.fn();
const dispatch = jest.fn();
state = {
fullPath: 'gitlab-org',
fullBoardId,
filterParams: {},
boardType,
issuableType,
};
const variables = {
query: listsQuery[issuableType].query,
variables: {
fullPath: 'gitlab-org',
boardId: fullBoardId,
filters: {},
isGroup,
isProject,
},
};
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
await actions.fetchLists({ commit, state, dispatch });
expect(gqlClient.query).toHaveBeenCalledWith(variables);
},
);
}); });
describe('createList', () => { describe('createList', () => {
...@@ -248,7 +283,7 @@ describe('createIssueList', () => { ...@@ -248,7 +283,7 @@ describe('createIssueList', () => {
beforeEach(() => { beforeEach(() => {
state = { state = {
fullPath: 'gitlab-org', fullPath: 'gitlab-org',
boardId: '1', fullBoardId: 'gid://gitlab/Board/1',
boardType: 'group', boardType: 'group',
disabled: false, disabled: false,
boardLists: [{ type: 'closed' }], boardLists: [{ type: 'closed' }],
...@@ -378,7 +413,7 @@ describe('moveList', () => { ...@@ -378,7 +413,7 @@ describe('moveList', () => {
const state = { const state = {
fullPath: 'gitlab-org', fullPath: 'gitlab-org',
boardId: '1', fullBoardId: 'gid://gitlab/Board/1',
boardType: 'group', boardType: 'group',
disabled: false, disabled: false,
boardLists: initialBoardListsState, boardLists: initialBoardListsState,
...@@ -421,7 +456,7 @@ describe('moveList', () => { ...@@ -421,7 +456,7 @@ describe('moveList', () => {
const state = { const state = {
fullPath: 'gitlab-org', fullPath: 'gitlab-org',
boardId: '1', fullBoardId: 'gid://gitlab/Board/1',
boardType: 'group', boardType: 'group',
disabled: false, disabled: false,
boardLists: initialBoardListsState, boardLists: initialBoardListsState,
...@@ -455,7 +490,7 @@ describe('updateList', () => { ...@@ -455,7 +490,7 @@ describe('updateList', () => {
const state = { const state = {
fullPath: 'gitlab-org', fullPath: 'gitlab-org',
boardId: '1', fullBoardId: 'gid://gitlab/Board/1',
boardType: 'group', boardType: 'group',
disabled: false, disabled: false,
boardLists: [{ type: 'closed' }], boardLists: [{ type: 'closed' }],
...@@ -573,7 +608,7 @@ describe('fetchItemsForList', () => { ...@@ -573,7 +608,7 @@ describe('fetchItemsForList', () => {
const state = { const state = {
fullPath: 'gitlab-org', fullPath: 'gitlab-org',
boardId: '1', fullBoardId: 'gid://gitlab/Board/1',
filterParams: {}, filterParams: {},
boardType: 'group', boardType: 'group',
}; };
...@@ -960,7 +995,7 @@ describe('updateIssueOrder', () => { ...@@ -960,7 +995,7 @@ describe('updateIssueOrder', () => {
const state = { const state = {
boardItems: issues, boardItems: issues,
boardId: 'gid://gitlab/Board/1', fullBoardId: 'gid://gitlab/Board/1',
}; };
const moveData = { const moveData = {
...@@ -974,7 +1009,7 @@ describe('updateIssueOrder', () => { ...@@ -974,7 +1009,7 @@ describe('updateIssueOrder', () => {
mutation: issueMoveListMutation, mutation: issueMoveListMutation,
variables: { variables: {
projectPath: getProjectPath(mockIssue.referencePath), projectPath: getProjectPath(mockIssue.referencePath),
boardId: fullBoardId(state.boardId), boardId: state.fullBoardId,
iid: mockIssue.iid, iid: mockIssue.iid,
fromListId: 1, fromListId: 1,
toListId: 2, toListId: 2,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment