debian-mirror-gitlab/spec/frontend/boards/stores/mutations_spec.js

670 lines
18 KiB
JavaScript
Raw Normal View History

2021-04-17 20:07:23 +05:30
import { issuableTypes } from '~/boards/constants';
2020-11-24 15:15:51 +05:30
import * as types from '~/boards/stores/mutation_types';
2021-03-11 19:13:27 +05:30
import mutations from '~/boards/stores/mutations';
2020-06-23 00:09:42 +05:30
import defaultState from '~/boards/stores/state';
2021-03-11 19:13:27 +05:30
import {
mockLists,
rawIssue,
mockIssue,
mockIssue2,
mockGroupProjects,
labels,
} from '../mock_data';
2019-09-04 21:01:54 +05:30
2021-03-08 18:12:59 +05:30
const expectNotImplemented = (action) => {
2019-09-04 21:01:54 +05:30
it('is not implemented', () => {
expect(action).toThrow(new Error('Not implemented!'));
});
};
2020-06-23 00:09:42 +05:30
describe('Board Store Mutations', () => {
let state;
2019-09-04 21:01:54 +05:30
2021-01-03 14:25:43 +05:30
const initialBoardListsState = {
2021-02-22 17:27:13 +05:30
'gid://gitlab/List/1': mockLists[0],
'gid://gitlab/List/2': mockLists[1],
2021-01-03 14:25:43 +05:30
};
2020-06-23 00:09:42 +05:30
beforeEach(() => {
state = defaultState();
});
2019-09-04 21:01:54 +05:30
2020-10-24 23:57:45 +05:30
describe('SET_INITIAL_BOARD_DATA', () => {
2020-06-23 00:09:42 +05:30
it('Should set initial Boards data to state', () => {
2021-03-08 18:12:59 +05:30
const boardId = 1;
const fullPath = 'gitlab-org';
2020-10-24 23:57:45 +05:30
const boardType = 'group';
2020-11-24 15:15:51 +05:30
const disabled = false;
2021-02-22 17:27:13 +05:30
const boardConfig = {
milestoneTitle: 'Milestone 1',
};
2021-04-17 20:07:23 +05:30
const issuableType = issuableTypes.issue;
2020-06-23 00:09:42 +05:30
2020-11-24 15:15:51 +05:30
mutations[types.SET_INITIAL_BOARD_DATA](state, {
2021-03-08 18:12:59 +05:30
boardId,
fullPath,
2020-11-24 15:15:51 +05:30
boardType,
disabled,
2021-02-22 17:27:13 +05:30
boardConfig,
2021-04-17 20:07:23 +05:30
issuableType,
2020-11-24 15:15:51 +05:30
});
2020-06-23 00:09:42 +05:30
2021-03-08 18:12:59 +05:30
expect(state.boardId).toEqual(boardId);
expect(state.fullPath).toEqual(fullPath);
2020-10-24 23:57:45 +05:30
expect(state.boardType).toEqual(boardType);
2020-11-24 15:15:51 +05:30
expect(state.disabled).toEqual(disabled);
2021-02-22 17:27:13 +05:30
expect(state.boardConfig).toEqual(boardConfig);
2021-04-17 20:07:23 +05:30
expect(state.issuableType).toEqual(issuableType);
2020-11-24 15:15:51 +05:30
});
});
describe('RECEIVE_BOARD_LISTS_SUCCESS', () => {
it('Should set boardLists to state', () => {
2021-01-03 14:25:43 +05:30
mutations[types.RECEIVE_BOARD_LISTS_SUCCESS](state, initialBoardListsState);
expect(state.boardLists).toEqual(initialBoardListsState);
});
});
2020-11-24 15:15:51 +05:30
2021-01-03 14:25:43 +05:30
describe('RECEIVE_BOARD_LISTS_FAILURE', () => {
it('Should set error in state', () => {
mutations[types.RECEIVE_BOARD_LISTS_FAILURE](state);
2020-11-24 15:15:51 +05:30
2021-01-03 14:25:43 +05:30
expect(state.error).toEqual(
'An error occurred while fetching the board lists. Please reload the page.',
);
2020-10-24 23:57:45 +05:30
});
});
describe('SET_ACTIVE_ID', () => {
2020-11-24 15:15:51 +05:30
const expected = { id: 1, sidebarType: '' };
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
beforeEach(() => {
mutations.SET_ACTIVE_ID(state, expected);
});
2021-01-29 00:20:46 +05:30
it('updates activeListId to be the value that is passed', () => {
2020-11-24 15:15:51 +05:30
expect(state.activeId).toBe(expected.id);
});
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
it('updates sidebarType to be the value that is passed', () => {
expect(state.sidebarType).toBe(expected.sidebarType);
});
});
describe('SET_FILTERS', () => {
it('updates filterParams to be the value that is passed', () => {
const filterParams = { labelName: 'label' };
mutations.SET_FILTERS(state, filterParams);
expect(state.filterParams).toBe(filterParams);
2020-06-23 00:09:42 +05:30
});
});
2019-09-04 21:01:54 +05:30
2021-01-29 00:20:46 +05:30
describe('CREATE_LIST_FAILURE', () => {
it('sets error message', () => {
mutations.CREATE_LIST_FAILURE(state);
expect(state.error).toEqual('An error occurred while creating the list. Please try again.');
});
});
2021-04-17 20:07:23 +05:30
describe('RECEIVE_LABELS_REQUEST', () => {
it('sets labelsLoading on state', () => {
mutations.RECEIVE_LABELS_REQUEST(state);
expect(state.labelsLoading).toEqual(true);
});
});
2021-03-11 19:13:27 +05:30
describe('RECEIVE_LABELS_SUCCESS', () => {
it('sets labels on state', () => {
mutations.RECEIVE_LABELS_SUCCESS(state, labels);
2021-01-29 00:20:46 +05:30
2021-03-11 19:13:27 +05:30
expect(state.labels).toEqual(labels);
2021-04-17 20:07:23 +05:30
expect(state.labelsLoading).toEqual(false);
});
});
describe('RECEIVE_LABELS_FAILURE', () => {
it('sets error message', () => {
mutations.RECEIVE_LABELS_FAILURE(state);
expect(state.error).toEqual(
'An error occurred while fetching labels. Please reload the page.',
);
expect(state.labelsLoading).toEqual(false);
2021-01-29 00:20:46 +05:30
});
});
describe('GENERATE_DEFAULT_LISTS_FAILURE', () => {
it('sets error message', () => {
mutations.GENERATE_DEFAULT_LISTS_FAILURE(state);
expect(state.error).toEqual(
'An error occurred while generating lists. Please reload the page.',
);
});
});
2020-06-23 00:09:42 +05:30
describe('REQUEST_ADD_LIST', () => {
expectNotImplemented(mutations.REQUEST_ADD_LIST);
});
2019-09-04 21:01:54 +05:30
2020-06-23 00:09:42 +05:30
describe('RECEIVE_ADD_LIST_SUCCESS', () => {
2021-01-03 14:25:43 +05:30
it('adds list to boardLists state', () => {
2021-02-22 17:27:13 +05:30
mutations.RECEIVE_ADD_LIST_SUCCESS(state, mockLists[0]);
2021-01-03 14:25:43 +05:30
expect(state.boardLists).toEqual({
2021-02-22 17:27:13 +05:30
[mockLists[0].id]: mockLists[0],
2021-01-03 14:25:43 +05:30
});
});
2020-06-23 00:09:42 +05:30
});
2019-09-04 21:01:54 +05:30
2020-06-23 00:09:42 +05:30
describe('RECEIVE_ADD_LIST_ERROR', () => {
expectNotImplemented(mutations.RECEIVE_ADD_LIST_ERROR);
});
2019-09-04 21:01:54 +05:30
2020-11-24 15:15:51 +05:30
describe('MOVE_LIST', () => {
it('updates boardLists state with reordered lists', () => {
state = {
...state,
2021-01-03 14:25:43 +05:30
boardLists: initialBoardListsState,
2020-11-24 15:15:51 +05:30
};
2019-09-04 21:01:54 +05:30
2020-11-24 15:15:51 +05:30
mutations.MOVE_LIST(state, {
2021-02-22 17:27:13 +05:30
movedList: mockLists[0],
listAtNewIndex: mockLists[1],
2020-11-24 15:15:51 +05:30
});
2021-01-03 14:25:43 +05:30
expect(state.boardLists).toEqual({
2021-02-22 17:27:13 +05:30
'gid://gitlab/List/2': mockLists[1],
'gid://gitlab/List/1': mockLists[0],
2021-01-03 14:25:43 +05:30
});
2020-11-24 15:15:51 +05:30
});
2020-06-23 00:09:42 +05:30
});
2019-09-04 21:01:54 +05:30
2020-11-24 15:15:51 +05:30
describe('UPDATE_LIST_FAILURE', () => {
it('updates boardLists state with previous order and sets error message', () => {
state = {
...state,
2021-01-03 14:25:43 +05:30
boardLists: {
2021-02-22 17:27:13 +05:30
'gid://gitlab/List/2': mockLists[1],
'gid://gitlab/List/1': mockLists[0],
2021-01-03 14:25:43 +05:30
},
2020-11-24 15:15:51 +05:30
error: undefined,
};
2021-01-03 14:25:43 +05:30
mutations.UPDATE_LIST_FAILURE(state, initialBoardListsState);
2020-11-24 15:15:51 +05:30
2021-01-03 14:25:43 +05:30
expect(state.boardLists).toEqual(initialBoardListsState);
2020-11-24 15:15:51 +05:30
expect(state.error).toEqual('An error occurred while updating the list. Please try again.');
});
2020-06-23 00:09:42 +05:30
});
2019-09-04 21:01:54 +05:30
2021-04-17 20:07:23 +05:30
describe('TOGGLE_LIST_COLLAPSED', () => {
it('updates collapsed attribute of list in boardLists state', () => {
const listId = 'gid://gitlab/List/1';
state = {
...state,
boardLists: {
[listId]: mockLists[0],
},
};
expect(state.boardLists[listId].collapsed).toEqual(false);
mutations.TOGGLE_LIST_COLLAPSED(state, { listId, collapsed: true });
expect(state.boardLists[listId].collapsed).toEqual(true);
});
});
2021-01-29 00:20:46 +05:30
describe('REMOVE_LIST', () => {
it('removes list from boardLists', () => {
2021-02-22 17:27:13 +05:30
const [list, secondList] = mockLists;
2021-01-29 00:20:46 +05:30
const expected = {
[secondList.id]: secondList,
};
state = {
...state,
boardLists: { ...initialBoardListsState },
};
2019-09-04 21:01:54 +05:30
2021-01-29 00:20:46 +05:30
mutations[types.REMOVE_LIST](state, list.id);
expect(state.boardLists).toEqual(expected);
});
2020-06-23 00:09:42 +05:30
});
2019-09-04 21:01:54 +05:30
2021-01-29 00:20:46 +05:30
describe('REMOVE_LIST_FAILURE', () => {
it('restores lists from backup', () => {
const backupLists = { ...initialBoardListsState };
mutations[types.REMOVE_LIST_FAILURE](state, backupLists);
expect(state.boardLists).toEqual(backupLists);
});
it('sets error state', () => {
const backupLists = { ...initialBoardListsState };
state = {
...state,
error: undefined,
};
mutations[types.REMOVE_LIST_FAILURE](state, backupLists);
expect(state.error).toEqual('An error occurred while removing the list. Please try again.');
});
2020-06-23 00:09:42 +05:30
});
2019-09-04 21:01:54 +05:30
2021-01-03 14:25:43 +05:30
describe('RESET_ISSUES', () => {
2021-04-17 20:07:23 +05:30
it('should remove issues from boardItemsByListId state', () => {
const boardItemsByListId = {
2021-01-03 14:25:43 +05:30
'gid://gitlab/List/1': [mockIssue.id],
};
state = {
...state,
2021-04-17 20:07:23 +05:30
boardItemsByListId,
2021-01-03 14:25:43 +05:30
};
mutations[types.RESET_ISSUES](state);
2021-04-17 20:07:23 +05:30
expect(state.boardItemsByListId).toEqual({ 'gid://gitlab/List/1': [] });
2021-01-03 14:25:43 +05:30
});
});
2021-04-17 20:07:23 +05:30
describe('RECEIVE_ITEMS_FOR_LIST_SUCCESS', () => {
it('updates boardItemsByListId and issues on state', () => {
2020-11-24 15:15:51 +05:30
const listIssues = {
'gid://gitlab/List/1': [mockIssue.id],
};
const issues = {
2021-03-08 18:12:59 +05:30
1: mockIssue,
2020-11-24 15:15:51 +05:30
};
state = {
...state,
2021-04-17 20:07:23 +05:30
boardItemsByListId: {
2021-01-03 14:25:43 +05:30
'gid://gitlab/List/1': [],
},
2021-04-17 20:07:23 +05:30
boardItems: {},
2021-01-03 14:25:43 +05:30
boardLists: initialBoardListsState,
};
const listPageInfo = {
'gid://gitlab/List/1': {
endCursor: '',
hasNextPage: false,
},
2020-11-24 15:15:51 +05:30
};
2021-04-17 20:07:23 +05:30
mutations.RECEIVE_ITEMS_FOR_LIST_SUCCESS(state, {
listItems: { listData: listIssues, boardItems: issues },
2021-01-03 14:25:43 +05:30
listPageInfo,
2020-11-24 15:15:51 +05:30
listId: 'gid://gitlab/List/1',
});
2021-04-17 20:07:23 +05:30
expect(state.boardItemsByListId).toEqual(listIssues);
expect(state.boardItems).toEqual(issues);
2020-11-24 15:15:51 +05:30
});
});
2021-04-17 20:07:23 +05:30
describe('RECEIVE_ITEMS_FOR_LIST_FAILURE', () => {
2020-11-24 15:15:51 +05:30
it('sets error message', () => {
state = {
...state,
2021-01-03 14:25:43 +05:30
boardLists: initialBoardListsState,
2020-11-24 15:15:51 +05:30
error: undefined,
};
const listId = 'gid://gitlab/List/1';
2021-04-17 20:07:23 +05:30
mutations.RECEIVE_ITEMS_FOR_LIST_FAILURE(state, listId);
2020-11-24 15:15:51 +05:30
expect(state.error).toEqual(
'An error occurred while fetching the board issues. Please reload the page.',
);
});
});
2020-06-23 00:09:42 +05:30
describe('REQUEST_ADD_ISSUE', () => {
expectNotImplemented(mutations.REQUEST_ADD_ISSUE);
});
2019-09-04 21:01:54 +05:30
2020-11-24 15:15:51 +05:30
describe('UPDATE_ISSUE_BY_ID', () => {
const issueId = '1';
const prop = 'id';
const value = '2';
const issue = { [issueId]: { id: 1, title: 'Issue' } };
beforeEach(() => {
state = {
...state,
error: undefined,
2021-04-17 20:07:23 +05:30
boardItems: {
2020-11-24 15:15:51 +05:30
...issue,
},
};
});
describe('when the issue is in state', () => {
it('updates the property of the correct issue', () => {
mutations.UPDATE_ISSUE_BY_ID(state, {
issueId,
prop,
value,
});
2021-04-17 20:07:23 +05:30
expect(state.boardItems[issueId]).toEqual({ ...issue[issueId], id: '2' });
2020-11-24 15:15:51 +05:30
});
});
describe('when the issue is not in state', () => {
it('throws an error', () => {
expect(() => {
mutations.UPDATE_ISSUE_BY_ID(state, {
issueId: '3',
prop,
value,
});
}).toThrow(new Error('No issue found.'));
});
});
});
2020-06-23 00:09:42 +05:30
describe('RECEIVE_ADD_ISSUE_SUCCESS', () => {
expectNotImplemented(mutations.RECEIVE_ADD_ISSUE_SUCCESS);
});
2019-09-04 21:01:54 +05:30
2020-06-23 00:09:42 +05:30
describe('RECEIVE_ADD_ISSUE_ERROR', () => {
expectNotImplemented(mutations.RECEIVE_ADD_ISSUE_ERROR);
});
2019-09-04 21:01:54 +05:30
2020-11-24 15:15:51 +05:30
describe('MOVE_ISSUE', () => {
2021-04-17 20:07:23 +05:30
it('updates boardItemsByListId, moving issue between lists', () => {
2020-11-24 15:15:51 +05:30
const listIssues = {
'gid://gitlab/List/1': [mockIssue.id, mockIssue2.id],
'gid://gitlab/List/2': [],
};
const issues = {
2021-03-08 18:12:59 +05:30
1: mockIssue,
2: mockIssue2,
2020-11-24 15:15:51 +05:30
};
state = {
...state,
2021-04-17 20:07:23 +05:30
boardItemsByListId: listIssues,
2021-01-03 14:25:43 +05:30
boardLists: initialBoardListsState,
2021-04-17 20:07:23 +05:30
boardItems: issues,
2020-11-24 15:15:51 +05:30
};
mutations.MOVE_ISSUE(state, {
2021-02-22 17:27:13 +05:30
originalIssue: mockIssue2,
2020-11-24 15:15:51 +05:30
fromListId: 'gid://gitlab/List/1',
toListId: 'gid://gitlab/List/2',
});
const updatedListIssues = {
'gid://gitlab/List/1': [mockIssue.id],
'gid://gitlab/List/2': [mockIssue2.id],
};
2021-04-17 20:07:23 +05:30
expect(state.boardItemsByListId).toEqual(updatedListIssues);
2020-11-24 15:15:51 +05:30
});
2020-06-23 00:09:42 +05:30
});
2019-09-04 21:01:54 +05:30
2020-11-24 15:15:51 +05:30
describe('MOVE_ISSUE_SUCCESS', () => {
it('updates issue in issues state', () => {
const issues = {
2021-03-08 18:12:59 +05:30
436: { id: rawIssue.id },
2020-11-24 15:15:51 +05:30
};
state = {
...state,
2021-04-17 20:07:23 +05:30
boardItems: issues,
2020-11-24 15:15:51 +05:30
};
mutations.MOVE_ISSUE_SUCCESS(state, {
issue: rawIssue,
});
2021-04-17 20:07:23 +05:30
expect(state.boardItems).toEqual({ 436: { ...mockIssue, id: 436 } });
2020-11-24 15:15:51 +05:30
});
2020-06-23 00:09:42 +05:30
});
2019-09-04 21:01:54 +05:30
2020-11-24 15:15:51 +05:30
describe('MOVE_ISSUE_FAILURE', () => {
2021-04-17 20:07:23 +05:30
it('updates boardItemsByListId, reverting moving issue between lists, and sets error message', () => {
2020-11-24 15:15:51 +05:30
const listIssues = {
'gid://gitlab/List/1': [mockIssue.id],
'gid://gitlab/List/2': [mockIssue2.id],
};
state = {
...state,
2021-04-17 20:07:23 +05:30
boardItemsByListId: listIssues,
2021-01-03 14:25:43 +05:30
boardLists: initialBoardListsState,
2020-11-24 15:15:51 +05:30
};
mutations.MOVE_ISSUE_FAILURE(state, {
originalIssue: mockIssue2,
fromListId: 'gid://gitlab/List/1',
toListId: 'gid://gitlab/List/2',
originalIndex: 1,
});
const updatedListIssues = {
'gid://gitlab/List/1': [mockIssue.id, mockIssue2.id],
'gid://gitlab/List/2': [],
};
2021-04-17 20:07:23 +05:30
expect(state.boardItemsByListId).toEqual(updatedListIssues);
2020-11-24 15:15:51 +05:30
expect(state.error).toEqual('An error occurred while moving the issue. Please try again.');
});
2020-06-23 00:09:42 +05:30
});
2019-09-04 21:01:54 +05:30
2020-06-23 00:09:42 +05:30
describe('REQUEST_UPDATE_ISSUE', () => {
expectNotImplemented(mutations.REQUEST_UPDATE_ISSUE);
});
2019-09-04 21:01:54 +05:30
2020-06-23 00:09:42 +05:30
describe('RECEIVE_UPDATE_ISSUE_SUCCESS', () => {
expectNotImplemented(mutations.RECEIVE_UPDATE_ISSUE_SUCCESS);
});
2019-09-04 21:01:54 +05:30
2020-06-23 00:09:42 +05:30
describe('RECEIVE_UPDATE_ISSUE_ERROR', () => {
expectNotImplemented(mutations.RECEIVE_UPDATE_ISSUE_ERROR);
});
2021-01-29 00:20:46 +05:30
describe('CREATE_ISSUE_FAILURE', () => {
it('sets error message on state', () => {
mutations.CREATE_ISSUE_FAILURE(state);
expect(state.error).toBe('An error occurred while creating the issue. Please try again.');
});
});
2020-11-24 15:15:51 +05:30
describe('ADD_ISSUE_TO_LIST', () => {
2021-04-17 20:07:23 +05:30
it('adds issue to issues state and issue id in list in boardItemsByListId', () => {
2020-11-24 15:15:51 +05:30
const listIssues = {
'gid://gitlab/List/1': [mockIssue.id],
};
const issues = {
2021-03-08 18:12:59 +05:30
1: mockIssue,
2020-11-24 15:15:51 +05:30
};
state = {
...state,
2021-04-17 20:07:23 +05:30
boardItemsByListId: listIssues,
boardItems: issues,
2021-01-29 00:20:46 +05:30
boardLists: initialBoardListsState,
2020-11-24 15:15:51 +05:30
};
2021-02-22 17:27:13 +05:30
expect(state.boardLists['gid://gitlab/List/1'].issuesCount).toBe(1);
2021-01-29 00:20:46 +05:30
2021-02-22 17:27:13 +05:30
mutations.ADD_ISSUE_TO_LIST(state, { list: mockLists[0], issue: mockIssue2 });
2020-11-24 15:15:51 +05:30
2021-04-17 20:07:23 +05:30
expect(state.boardItemsByListId['gid://gitlab/List/1']).toContain(mockIssue2.id);
expect(state.boardItems[mockIssue2.id]).toEqual(mockIssue2);
2021-02-22 17:27:13 +05:30
expect(state.boardLists['gid://gitlab/List/1'].issuesCount).toBe(2);
2020-11-24 15:15:51 +05:30
});
});
describe('ADD_ISSUE_TO_LIST_FAILURE', () => {
2021-04-17 20:07:23 +05:30
it('removes issue id from list in boardItemsByListId and sets error message', () => {
2021-01-29 00:20:46 +05:30
const listIssues = {
'gid://gitlab/List/1': [mockIssue.id, mockIssue2.id],
};
const issues = {
2021-03-08 18:12:59 +05:30
1: mockIssue,
2: mockIssue2,
2021-01-29 00:20:46 +05:30
};
state = {
...state,
2021-04-17 20:07:23 +05:30
boardItemsByListId: listIssues,
boardItems: issues,
2021-01-29 00:20:46 +05:30
boardLists: initialBoardListsState,
};
mutations.ADD_ISSUE_TO_LIST_FAILURE(state, { list: mockLists[0], issueId: mockIssue2.id });
2021-04-17 20:07:23 +05:30
expect(state.boardItemsByListId['gid://gitlab/List/1']).not.toContain(mockIssue2.id);
2021-01-29 00:20:46 +05:30
expect(state.error).toBe('An error occurred while creating the issue. Please try again.');
});
});
describe('REMOVE_ISSUE_FROM_LIST', () => {
2021-04-17 20:07:23 +05:30
it('removes issue id from list in boardItemsByListId and deletes issue from state', () => {
2020-11-24 15:15:51 +05:30
const listIssues = {
'gid://gitlab/List/1': [mockIssue.id, mockIssue2.id],
};
const issues = {
2021-03-08 18:12:59 +05:30
1: mockIssue,
2: mockIssue2,
2020-11-24 15:15:51 +05:30
};
state = {
...state,
2021-04-17 20:07:23 +05:30
boardItemsByListId: listIssues,
boardItems: issues,
2021-01-03 14:25:43 +05:30
boardLists: initialBoardListsState,
2020-11-24 15:15:51 +05:30
};
2021-01-29 00:20:46 +05:30
mutations.ADD_ISSUE_TO_LIST_FAILURE(state, { list: mockLists[0], issueId: mockIssue2.id });
2020-11-24 15:15:51 +05:30
2021-04-17 20:07:23 +05:30
expect(state.boardItemsByListId['gid://gitlab/List/1']).not.toContain(mockIssue2.id);
expect(state.boardItems).not.toContain(mockIssue2);
2020-11-24 15:15:51 +05:30
});
});
2021-02-22 17:27:13 +05:30
describe('SET_ASSIGNEE_LOADING', () => {
it('sets isSettingAssignees to the value passed', () => {
mutations.SET_ASSIGNEE_LOADING(state, true);
expect(state.isSettingAssignees).toBe(true);
});
});
2020-06-23 00:09:42 +05:30
describe('SET_CURRENT_PAGE', () => {
expectNotImplemented(mutations.SET_CURRENT_PAGE);
});
describe('TOGGLE_EMPTY_STATE', () => {
expectNotImplemented(mutations.TOGGLE_EMPTY_STATE);
});
2021-03-08 18:12:59 +05:30
describe('REQUEST_GROUP_PROJECTS', () => {
it('Should set isLoading in groupProjectsFlags to true in state when fetchNext is false', () => {
mutations[types.REQUEST_GROUP_PROJECTS](state, false);
expect(state.groupProjectsFlags.isLoading).toBe(true);
});
it('Should set isLoading in groupProjectsFlags to true in state when fetchNext is true', () => {
mutations[types.REQUEST_GROUP_PROJECTS](state, true);
expect(state.groupProjectsFlags.isLoadingMore).toBe(true);
});
});
describe('RECEIVE_GROUP_PROJECTS_SUCCESS', () => {
it('Should set groupProjects and pageInfo to state and isLoading in groupProjectsFlags to false', () => {
mutations[types.RECEIVE_GROUP_PROJECTS_SUCCESS](state, {
projects: mockGroupProjects,
pageInfo: { hasNextPage: false },
});
expect(state.groupProjects).toEqual(mockGroupProjects);
expect(state.groupProjectsFlags.isLoading).toBe(false);
expect(state.groupProjectsFlags.pageInfo).toEqual({ hasNextPage: false });
});
it('Should merge projects in groupProjects in state when fetchNext is true', () => {
state = {
...state,
groupProjects: [mockGroupProjects[0]],
};
mutations[types.RECEIVE_GROUP_PROJECTS_SUCCESS](state, {
projects: [mockGroupProjects[1]],
fetchNext: true,
});
expect(state.groupProjects).toEqual(mockGroupProjects);
});
});
describe('RECEIVE_GROUP_PROJECTS_FAILURE', () => {
it('Should set error in state and isLoading in groupProjectsFlags to false', () => {
mutations[types.RECEIVE_GROUP_PROJECTS_FAILURE](state);
expect(state.error).toEqual(
'An error occurred while fetching group projects. Please try again.',
);
expect(state.groupProjectsFlags.isLoading).toBe(false);
});
});
describe('SET_SELECTED_PROJECT', () => {
it('Should set selectedProject to state', () => {
mutations[types.SET_SELECTED_PROJECT](state, mockGroupProjects[0]);
expect(state.selectedProject).toEqual(mockGroupProjects[0]);
});
});
2021-03-11 19:13:27 +05:30
describe('ADD_BOARD_ITEM_TO_SELECTION', () => {
it('Should add boardItem to selectedBoardItems state', () => {
expect(state.selectedBoardItems).toEqual([]);
mutations[types.ADD_BOARD_ITEM_TO_SELECTION](state, mockIssue);
expect(state.selectedBoardItems).toEqual([mockIssue]);
});
});
describe('REMOVE_BOARD_ITEM_FROM_SELECTION', () => {
it('Should remove boardItem to selectedBoardItems state', () => {
2021-04-17 20:07:23 +05:30
state.selectedBoardItems = [mockIssue];
2021-03-11 19:13:27 +05:30
mutations[types.REMOVE_BOARD_ITEM_FROM_SELECTION](state, mockIssue);
expect(state.selectedBoardItems).toEqual([]);
});
});
2021-04-17 20:07:23 +05:30
describe('RESET_BOARD_ITEM_SELECTION', () => {
it('Should reset selectedBoardItems state', () => {
state.selectedBoardItems = [mockIssue];
mutations[types.RESET_BOARD_ITEM_SELECTION](state, mockIssue);
expect(state.selectedBoardItems).toEqual([]);
});
});
2019-09-04 21:01:54 +05:30
});