diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/frontend/boards/stores | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/frontend/boards/stores')
-rw-r--r-- | spec/frontend/boards/stores/actions_spec.js | 235 | ||||
-rw-r--r-- | spec/frontend/boards/stores/getters_spec.js | 76 | ||||
-rw-r--r-- | spec/frontend/boards/stores/mutations_spec.js | 62 |
3 files changed, 207 insertions, 166 deletions
diff --git a/spec/frontend/boards/stores/actions_spec.js b/spec/frontend/boards/stores/actions_spec.js index 4d529580a7a..0cae6456887 100644 --- a/spec/frontend/boards/stores/actions_spec.js +++ b/spec/frontend/boards/stores/actions_spec.js @@ -1,23 +1,25 @@ import testAction from 'helpers/vuex_action_helper'; import { - mockListsWithModel, mockLists, mockListsById, mockIssue, - mockIssueWithModel, - mockIssue2WithModel, + mockIssue2, rawIssue, mockIssues, + mockMilestone, labels, mockActiveIssue, } from '../mock_data'; import actions, { gqlClient } from '~/boards/stores/actions'; import * as types from '~/boards/stores/mutation_types'; import { inactiveId } from '~/boards/constants'; -import issueMoveListMutation from '~/boards/queries/issue_move_list.mutation.graphql'; -import destroyBoardListMutation from '~/boards/queries/board_list_destroy.mutation.graphql'; +import issueMoveListMutation from '~/boards/graphql/issue_move_list.mutation.graphql'; +import destroyBoardListMutation from '~/boards/graphql/board_list_destroy.mutation.graphql'; import updateAssignees from '~/vue_shared/components/sidebar/queries/updateAssignees.mutation.graphql'; import { fullBoardId, formatListIssues, formatBoardLists } from '~/boards/boards_util'; +import createFlash from '~/flash'; + +jest.mock('~/flash'); const expectNotImplemented = action => { it('is not implemented', () => { @@ -29,6 +31,10 @@ const expectNotImplemented = action => { // subgroups when the movIssue action is called. const getProjectPath = path => path.split('#')[0]; +beforeEach(() => { + window.gon = { features: {} }; +}); + describe('setInitialBoardData', () => { it('sets data object', () => { const mockData = { @@ -65,6 +71,24 @@ describe('setFilters', () => { }); }); +describe('performSearch', () => { + it('should dispatch setFilters action', done => { + testAction(actions.performSearch, {}, {}, [], [{ type: 'setFilters', payload: {} }], done); + }); + + it('should dispatch setFilters, fetchLists and resetIssues action when graphqlBoardLists FF is on', done => { + window.gon = { features: { graphqlBoardLists: true } }; + testAction( + actions.performSearch, + {}, + {}, + [], + [{ type: 'setFilters', payload: {} }, { type: 'fetchLists' }, { type: 'resetIssues' }], + done, + ); + }); +}); + describe('setActiveId', () => { it('should commit mutation SET_ACTIVE_ID', done => { const state = { @@ -120,7 +144,7 @@ describe('fetchLists', () => { payload: formattedLists, }, ], - [{ type: 'generateDefaultLists' }], + [], done, ); }); @@ -150,37 +174,12 @@ describe('fetchLists', () => { payload: formattedLists, }, ], - [{ type: 'createList', payload: { backlog: true } }, { type: 'generateDefaultLists' }], + [{ type: 'createList', payload: { backlog: true } }], done, ); }); }); -describe('generateDefaultLists', () => { - let store; - beforeEach(() => { - const state = { - endpoints: { fullPath: 'gitlab-org', boardId: '1' }, - boardType: 'group', - disabled: false, - boardLists: [{ type: 'backlog' }, { type: 'closed' }], - }; - - store = { - commit: jest.fn(), - dispatch: jest.fn(() => Promise.resolve()), - state, - }; - }); - - it('should dispatch fetchLabels', () => { - return actions.generateDefaultLists(store).then(() => { - expect(store.dispatch.mock.calls[0]).toEqual(['fetchLabels', 'to do']); - expect(store.dispatch.mock.calls[1]).toEqual(['fetchLabels', 'doing']); - }); - }); -}); - describe('createList', () => { it('should dispatch addList action when creating backlog list', done => { const backlogList = { @@ -251,8 +250,8 @@ describe('createList', () => { describe('moveList', () => { it('should commit MOVE_LIST mutation and dispatch updateList action', done => { const initialBoardListsState = { - 'gid://gitlab/List/1': mockListsWithModel[0], - 'gid://gitlab/List/2': mockListsWithModel[1], + 'gid://gitlab/List/1': mockLists[0], + 'gid://gitlab/List/2': mockLists[1], }; const state = { @@ -274,7 +273,7 @@ describe('moveList', () => { [ { type: types.MOVE_LIST, - payload: { movedList: mockListsWithModel[0], listAtNewIndex: mockListsWithModel[1] }, + payload: { movedList: mockLists[0], listAtNewIndex: mockLists[1] }, }, ], [ @@ -290,6 +289,33 @@ describe('moveList', () => { done, ); }); + + it('should not commit MOVE_LIST or dispatch updateList if listId and replacedListId are the same', () => { + const initialBoardListsState = { + 'gid://gitlab/List/1': mockLists[0], + 'gid://gitlab/List/2': mockLists[1], + }; + + const state = { + endpoints: { fullPath: 'gitlab-org', boardId: '1' }, + boardType: 'group', + disabled: false, + boardLists: initialBoardListsState, + }; + + testAction( + actions.moveList, + { + listId: 'gid://gitlab/List/1', + replacedListId: 'gid://gitlab/List/1', + newIndex: 1, + adjustmentValue: 1, + }, + state, + [], + [], + ); + }); }); describe('updateList', () => { @@ -499,15 +525,15 @@ describe('moveIssue', () => { }; const issues = { - '436': mockIssueWithModel, - '437': mockIssue2WithModel, + '436': mockIssue, + '437': mockIssue2, }; const state = { endpoints: { fullPath: 'gitlab-org', boardId: '1' }, boardType: 'group', disabled: false, - boardLists: mockListsWithModel, + boardLists: mockLists, issuesByListId: listIssues, issues, }; @@ -536,7 +562,7 @@ describe('moveIssue', () => { { type: types.MOVE_ISSUE, payload: { - originalIssue: mockIssueWithModel, + originalIssue: mockIssue, fromListId: 'gid://gitlab/List/1', toListId: 'gid://gitlab/List/2', }, @@ -611,7 +637,7 @@ describe('moveIssue', () => { { type: types.MOVE_ISSUE, payload: { - originalIssue: mockIssueWithModel, + originalIssue: mockIssue, fromListId: 'gid://gitlab/List/1', toListId: 'gid://gitlab/List/2', }, @@ -619,7 +645,7 @@ describe('moveIssue', () => { { type: types.MOVE_ISSUE_FAILURE, payload: { - originalIssue: mockIssueWithModel, + originalIssue: mockIssue, fromListId: 'gid://gitlab/List/1', toListId: 'gid://gitlab/List/2', originalIndex: 0, @@ -639,38 +665,59 @@ describe('setAssignees', () => { const refPath = `${projectPath}#3`; const iid = '1'; - beforeEach(() => { - jest.spyOn(gqlClient, 'mutate').mockResolvedValue({ - data: { issueSetAssignees: { issue: { assignees: { nodes: [{ ...node }] } } } }, + describe('when succeeds', () => { + beforeEach(() => { + jest.spyOn(gqlClient, 'mutate').mockResolvedValue({ + data: { issueSetAssignees: { issue: { assignees: { nodes: [{ ...node }] } } } }, + }); }); - }); - it('calls mutate with the correct values', async () => { - await actions.setAssignees( - { commit: () => {}, getters: { activeIssue: { iid, referencePath: refPath } } }, - [name], - ); + it('calls mutate with the correct values', async () => { + await actions.setAssignees( + { commit: () => {}, getters: { activeIssue: { iid, referencePath: refPath } } }, + [name], + ); + + expect(gqlClient.mutate).toHaveBeenCalledWith({ + mutation: updateAssignees, + variables: { iid, assigneeUsernames: [name], projectPath }, + }); + }); - expect(gqlClient.mutate).toHaveBeenCalledWith({ - mutation: updateAssignees, - variables: { iid, assigneeUsernames: [name], projectPath }, + it('calls the correct mutation with the correct values', done => { + testAction( + actions.setAssignees, + {}, + { activeIssue: { iid, referencePath: refPath }, commit: () => {} }, + [ + { type: types.SET_ASSIGNEE_LOADING, payload: true }, + { + type: 'UPDATE_ISSUE_BY_ID', + payload: { prop: 'assignees', issueId: undefined, value: [node] }, + }, + { type: types.SET_ASSIGNEE_LOADING, payload: false }, + ], + [], + done, + ); }); }); - it('calls the correct mutation with the correct values', done => { - testAction( - actions.setAssignees, - {}, - { activeIssue: { iid, referencePath: refPath }, commit: () => {} }, - [ - { - type: 'UPDATE_ISSUE_BY_ID', - payload: { prop: 'assignees', issueId: undefined, value: [node] }, - }, - ], - [], - done, - ); + describe('when fails', () => { + beforeEach(() => { + jest.spyOn(gqlClient, 'mutate').mockRejectedValue(); + }); + + it('calls createFlash', async () => { + await actions.setAssignees({ + commit: () => {}, + getters: { activeIssue: { iid, referencePath: refPath } }, + }); + + expect(createFlash).toHaveBeenCalledWith({ + message: 'An error occurred while updating assignees.', + }); + }); }); }); @@ -885,6 +932,60 @@ describe('setActiveIssueSubscribed', () => { }); }); +describe('setActiveIssueMilestone', () => { + const state = { issues: { [mockIssue.id]: mockIssue } }; + const getters = { activeIssue: mockIssue }; + const testMilestone = { + ...mockMilestone, + id: 'gid://gitlab/Milestone/1', + }; + const input = { + milestoneId: testMilestone.id, + projectPath: 'h/b', + }; + + it('should commit milestone after setting the issue', done => { + jest.spyOn(gqlClient, 'mutate').mockResolvedValue({ + data: { + updateIssue: { + issue: { + milestone: testMilestone, + }, + errors: [], + }, + }, + }); + + const payload = { + issueId: getters.activeIssue.id, + prop: 'milestone', + value: testMilestone, + }; + + testAction( + actions.setActiveIssueMilestone, + input, + { ...state, ...getters }, + [ + { + type: types.UPDATE_ISSUE_BY_ID, + payload, + }, + ], + [], + done, + ); + }); + + it('throws error if fails', async () => { + jest + .spyOn(gqlClient, 'mutate') + .mockResolvedValue({ data: { updateIssue: { errors: ['failed mutation'] } } }); + + await expect(actions.setActiveIssueMilestone({ getters }, input)).rejects.toThrow(Error); + }); +}); + describe('fetchBacklog', () => { expectNotImplemented(actions.fetchBacklog); }); diff --git a/spec/frontend/boards/stores/getters_spec.js b/spec/frontend/boards/stores/getters_spec.js index 64025726dd1..6ceb8867d1f 100644 --- a/spec/frontend/boards/stores/getters_spec.js +++ b/spec/frontend/boards/stores/getters_spec.js @@ -6,28 +6,10 @@ import { mockIssues, mockIssuesByListId, issues, - mockListsWithModel, + mockLists, } from '../mock_data'; describe('Boards - Getters', () => { - describe('labelToggleState', () => { - it('should return "on" when isShowingLabels is true', () => { - const state = { - isShowingLabels: true, - }; - - expect(getters.labelToggleState(state)).toBe('on'); - }); - - it('should return "off" when isShowingLabels is false', () => { - const state = { - isShowingLabels: false, - }; - - expect(getters.labelToggleState(state)).toBe('off'); - }); - }); - describe('isSidebarOpen', () => { it('returns true when activeId is not equal to 0', () => { const state = { @@ -51,52 +33,8 @@ describe('Boards - Getters', () => { window.gon = { features: {} }; }); - describe('when boardsWithSwimlanes is true', () => { - beforeEach(() => { - window.gon = { features: { boardsWithSwimlanes: true } }; - }); - - describe('when isShowingEpicsSwimlanes is true', () => { - it('returns true', () => { - const state = { - isShowingEpicsSwimlanes: true, - }; - - expect(getters.isSwimlanesOn(state)).toBe(true); - }); - }); - - describe('when isShowingEpicsSwimlanes is false', () => { - it('returns false', () => { - const state = { - isShowingEpicsSwimlanes: false, - }; - - expect(getters.isSwimlanesOn(state)).toBe(false); - }); - }); - }); - - describe('when boardsWithSwimlanes is false', () => { - describe('when isShowingEpicsSwimlanes is true', () => { - it('returns false', () => { - const state = { - isShowingEpicsSwimlanes: true, - }; - - expect(getters.isSwimlanesOn(state)).toBe(false); - }); - }); - - describe('when isShowingEpicsSwimlanes is false', () => { - it('returns false', () => { - const state = { - isShowingEpicsSwimlanes: false, - }; - - expect(getters.isSwimlanesOn(state)).toBe(false); - }); - }); + it('returns false', () => { + expect(getters.isSwimlanesOn()).toBe(false); }); }); @@ -156,22 +94,22 @@ describe('Boards - Getters', () => { const boardsState = { boardLists: { - 'gid://gitlab/List/1': mockListsWithModel[0], - 'gid://gitlab/List/2': mockListsWithModel[1], + 'gid://gitlab/List/1': mockLists[0], + 'gid://gitlab/List/2': mockLists[1], }, }; describe('getListByLabelId', () => { it('returns list for a given label id', () => { expect(getters.getListByLabelId(boardsState)('gid://gitlab/GroupLabel/121')).toEqual( - mockListsWithModel[1], + mockLists[1], ); }); }); describe('getListByTitle', () => { it('returns list for a given list title', () => { - expect(getters.getListByTitle(boardsState)('To Do')).toEqual(mockListsWithModel[1]); + expect(getters.getListByTitle(boardsState)('To Do')).toEqual(mockLists[1]); }); }); }); diff --git a/spec/frontend/boards/stores/mutations_spec.js b/spec/frontend/boards/stores/mutations_spec.js index e1e57a8fd43..d93119ede3d 100644 --- a/spec/frontend/boards/stores/mutations_spec.js +++ b/spec/frontend/boards/stores/mutations_spec.js @@ -1,15 +1,7 @@ import mutations from '~/boards/stores/mutations'; import * as types from '~/boards/stores/mutation_types'; import defaultState from '~/boards/stores/state'; -import { - mockListsWithModel, - mockLists, - rawIssue, - mockIssue, - mockIssue2, - mockIssueWithModel, - mockIssue2WithModel, -} from '../mock_data'; +import { mockLists, rawIssue, mockIssue, mockIssue2 } from '../mock_data'; const expectNotImplemented = action => { it('is not implemented', () => { @@ -21,8 +13,8 @@ describe('Board Store Mutations', () => { let state; const initialBoardListsState = { - 'gid://gitlab/List/1': mockListsWithModel[0], - 'gid://gitlab/List/2': mockListsWithModel[1], + 'gid://gitlab/List/1': mockLists[0], + 'gid://gitlab/List/2': mockLists[1], }; beforeEach(() => { @@ -41,19 +33,21 @@ describe('Board Store Mutations', () => { }; const boardType = 'group'; const disabled = false; - const showPromotion = false; + const boardConfig = { + milestoneTitle: 'Milestone 1', + }; mutations[types.SET_INITIAL_BOARD_DATA](state, { ...endpoints, boardType, disabled, - showPromotion, + boardConfig, }); expect(state.endpoints).toEqual(endpoints); expect(state.boardType).toEqual(boardType); expect(state.disabled).toEqual(disabled); - expect(state.showPromotion).toEqual(showPromotion); + expect(state.boardConfig).toEqual(boardConfig); }); }); @@ -135,10 +129,10 @@ describe('Board Store Mutations', () => { describe('RECEIVE_ADD_LIST_SUCCESS', () => { it('adds list to boardLists state', () => { - mutations.RECEIVE_ADD_LIST_SUCCESS(state, mockListsWithModel[0]); + mutations.RECEIVE_ADD_LIST_SUCCESS(state, mockLists[0]); expect(state.boardLists).toEqual({ - [mockListsWithModel[0].id]: mockListsWithModel[0], + [mockLists[0].id]: mockLists[0], }); }); }); @@ -155,13 +149,13 @@ describe('Board Store Mutations', () => { }; mutations.MOVE_LIST(state, { - movedList: mockListsWithModel[0], - listAtNewIndex: mockListsWithModel[1], + movedList: mockLists[0], + listAtNewIndex: mockLists[1], }); expect(state.boardLists).toEqual({ - 'gid://gitlab/List/2': mockListsWithModel[1], - 'gid://gitlab/List/1': mockListsWithModel[0], + 'gid://gitlab/List/2': mockLists[1], + 'gid://gitlab/List/1': mockLists[0], }); }); }); @@ -171,8 +165,8 @@ describe('Board Store Mutations', () => { state = { ...state, boardLists: { - 'gid://gitlab/List/2': mockListsWithModel[1], - 'gid://gitlab/List/1': mockListsWithModel[0], + 'gid://gitlab/List/2': mockLists[1], + 'gid://gitlab/List/1': mockLists[0], }, error: undefined, }; @@ -186,7 +180,7 @@ describe('Board Store Mutations', () => { describe('REMOVE_LIST', () => { it('removes list from boardLists', () => { - const [list, secondList] = mockListsWithModel; + const [list, secondList] = mockLists; const expected = { [secondList.id]: secondList, }; @@ -355,8 +349,8 @@ describe('Board Store Mutations', () => { }; const issues = { - '1': mockIssueWithModel, - '2': mockIssue2WithModel, + '1': mockIssue, + '2': mockIssue2, }; state = { @@ -367,7 +361,7 @@ describe('Board Store Mutations', () => { }; mutations.MOVE_ISSUE(state, { - originalIssue: mockIssue2WithModel, + originalIssue: mockIssue2, fromListId: 'gid://gitlab/List/1', toListId: 'gid://gitlab/List/2', }); @@ -396,7 +390,7 @@ describe('Board Store Mutations', () => { issue: rawIssue, }); - expect(state.issues).toEqual({ '436': { ...mockIssueWithModel, id: 436 } }); + expect(state.issues).toEqual({ '436': { ...mockIssue, id: 436 } }); }); }); @@ -466,13 +460,13 @@ describe('Board Store Mutations', () => { boardLists: initialBoardListsState, }; - expect(state.boardLists['gid://gitlab/List/1'].issuesSize).toBe(1); + expect(state.boardLists['gid://gitlab/List/1'].issuesCount).toBe(1); - mutations.ADD_ISSUE_TO_LIST(state, { list: mockListsWithModel[0], issue: mockIssue2 }); + mutations.ADD_ISSUE_TO_LIST(state, { list: mockLists[0], issue: mockIssue2 }); expect(state.issuesByListId['gid://gitlab/List/1']).toContain(mockIssue2.id); expect(state.issues[mockIssue2.id]).toEqual(mockIssue2); - expect(state.boardLists['gid://gitlab/List/1'].issuesSize).toBe(2); + expect(state.boardLists['gid://gitlab/List/1'].issuesCount).toBe(2); }); }); @@ -524,6 +518,14 @@ describe('Board Store Mutations', () => { }); }); + describe('SET_ASSIGNEE_LOADING', () => { + it('sets isSettingAssignees to the value passed', () => { + mutations.SET_ASSIGNEE_LOADING(state, true); + + expect(state.isSettingAssignees).toBe(true); + }); + }); + describe('SET_CURRENT_PAGE', () => { expectNotImplemented(mutations.SET_CURRENT_PAGE); }); |