Commit 7a075fa2 authored by Florie Guibert's avatar Florie Guibert

Refactor shared board action

Review feedback
parent b6b99e4d
...@@ -11,6 +11,7 @@ import { ...@@ -11,6 +11,7 @@ import {
deleteListQueries, deleteListQueries,
listsQuery, 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 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';
...@@ -92,8 +93,10 @@ export default { ...@@ -92,8 +93,10 @@ export default {
fullPath, fullPath,
boardId: fullBoardId, 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
......
/* 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';
...@@ -9,6 +10,8 @@ import destroyEpicBoardListMutation from './graphql/epic_board_list_destroy.muta ...@@ -9,6 +10,8 @@ import destroyEpicBoardListMutation from './graphql/epic_board_list_destroy.muta
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'; import epicBoardListsQuery from './graphql/epic_board_lists.query.graphql';
export * from '~/boards/constants';
export const DRAGGABLE_TAG = 'div'; export const DRAGGABLE_TAG = 'div';
export const EPIC_LANE_BASE_HEIGHT = 40; export const EPIC_LANE_BASE_HEIGHT = 40;
...@@ -63,9 +66,6 @@ export const ErrorMessages = { ...@@ -63,9 +66,6 @@ export const ErrorMessages = {
), ),
}; };
/* eslint-disable import/export */
export * from '~/boards/constants';
export const listsQuery = { export const listsQuery = {
[issuableTypes.issue]: { [issuableTypes.issue]: {
query: boardListsQuery, query: boardListsQuery,
......
...@@ -9,10 +9,9 @@ import { ...@@ -9,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,
...@@ -58,13 +57,6 @@ const notImplemented = () => { ...@@ -58,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;
...@@ -115,6 +107,8 @@ const fetchAndFormatListEpics = (state, extraVariables) => { ...@@ -115,6 +107,8 @@ const fetchAndFormatListEpics = (state, extraVariables) => {
}); });
}; };
export { gqlClient };
export default { export default {
...actionsCE, ...actionsCE,
......
...@@ -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';
...@@ -152,6 +152,57 @@ describe('performSearch', () => { ...@@ -152,6 +152,57 @@ describe('performSearch', () => {
}); });
}); });
describe('fetchLists', () => {
const queryResponse = {
data: {
group: {
board: {
hideBacklogList: true,
lists: {
nodes: [mockLists[1]],
},
},
},
},
};
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();
const 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('fetchEpicsSwimlanes', () => { describe('fetchEpicsSwimlanes', () => {
const state = { const state = {
fullPath: 'gitlab-org', fullPath: 'gitlab-org',
......
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 {
...@@ -8,7 +16,6 @@ import { ...@@ -8,7 +16,6 @@ import {
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';
...@@ -131,7 +138,7 @@ describe('setActiveId', () => { ...@@ -131,7 +138,7 @@ describe('setActiveId', () => {
}); });
describe('fetchLists', () => { describe('fetchLists', () => {
const state = { let state = {
fullPath: 'gitlab-org', fullPath: 'gitlab-org',
fullBoardId: 'gid://gitlab/Board/1', fullBoardId: 'gid://gitlab/Board/1',
filterParams: {}, filterParams: {},
...@@ -218,6 +225,43 @@ describe('fetchLists', () => { ...@@ -218,6 +225,43 @@ describe('fetchLists', () => {
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', () => {
......
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