2021-04-29 21:17:54 +05:30
|
|
|
import { cloneDeep } from 'lodash';
|
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 {
|
2022-05-07 20:08:51 +05:30
|
|
|
mockBoard,
|
2021-03-11 19:13:27 +05:30
|
|
|
mockLists,
|
|
|
|
rawIssue,
|
|
|
|
mockIssue,
|
|
|
|
mockIssue2,
|
|
|
|
mockGroupProjects,
|
|
|
|
labels,
|
2021-04-29 21:17:54 +05:30
|
|
|
mockList,
|
2021-03-11 19:13:27 +05:30
|
|
|
} from '../mock_data';
|
2019-09-04 21:01:54 +05:30
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
const setBoardsListsState = () => {
|
|
|
|
state = cloneDeep({
|
|
|
|
...state,
|
|
|
|
boardItemsByListId: { 'gid://gitlab/List/1': [mockIssue.id] },
|
|
|
|
boardLists: { 'gid://gitlab/List/1': mockList },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
state = defaultState();
|
|
|
|
});
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
describe('RECEIVE_BOARD_SUCCESS', () => {
|
|
|
|
it('Should set board to state', () => {
|
|
|
|
mutations[types.RECEIVE_BOARD_SUCCESS](state, mockBoard);
|
|
|
|
|
|
|
|
expect(state.board).toEqual({
|
|
|
|
...mockBoard,
|
|
|
|
labels: mockBoard.labels.nodes,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('RECEIVE_BOARD_FAILURE', () => {
|
|
|
|
it('Should set error in state', () => {
|
|
|
|
mutations[types.RECEIVE_BOARD_FAILURE](state);
|
|
|
|
|
|
|
|
expect(state.error).toEqual(
|
|
|
|
'An error occurred while fetching the board. Please reload the page.',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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-09-30 23:02:18 +05:30
|
|
|
const allowSubEpics = true;
|
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-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-09-30 23:02:18 +05:30
|
|
|
allowSubEpics,
|
2021-03-08 18:12:59 +05:30
|
|
|
boardId,
|
|
|
|
fullPath,
|
2020-11-24 15:15:51 +05:30
|
|
|
boardType,
|
|
|
|
disabled,
|
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-09-30 23:02:18 +05:30
|
|
|
expect(state.allowSubEpics).toBe(allowSubEpics);
|
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-04-17 20:07:23 +05:30
|
|
|
expect(state.issuableType).toEqual(issuableType);
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
describe('SET_BOARD_CONFIG', () => {
|
|
|
|
it('Should set board config data o state', () => {
|
|
|
|
const boardConfig = {
|
|
|
|
milestoneId: 1,
|
|
|
|
milestoneTitle: 'Milestone 1',
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations[types.SET_BOARD_CONFIG](state, boardConfig);
|
|
|
|
|
|
|
|
expect(state.boardConfig).toEqual(boardConfig);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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('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
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
describe('MOVE_LISTS', () => {
|
|
|
|
it('updates the positions of board lists', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
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
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
mutations.MOVE_LISTS(state, [
|
|
|
|
{
|
|
|
|
listId: mockLists[0].id,
|
|
|
|
position: 1,
|
2021-01-03 14:25:43 +05:30
|
|
|
},
|
2021-10-27 15:23:28 +05:30
|
|
|
{
|
|
|
|
listId: mockLists[1].id,
|
|
|
|
position: 0,
|
|
|
|
},
|
|
|
|
]);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
expect(state.boardLists[mockLists[0].id].position).toBe(1);
|
|
|
|
expect(state.boardLists[mockLists[1].id].position).toBe(0);
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
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-09-04 01:27:46 +05:30
|
|
|
describe('RESET_ITEMS_FOR_LIST', () => {
|
|
|
|
it('should remove issues from boardItemsByListId state', () => {
|
|
|
|
const listId = 'gid://gitlab/List/1';
|
|
|
|
const boardItemsByListId = {
|
|
|
|
[listId]: [mockIssue.id],
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
...state,
|
|
|
|
boardItemsByListId,
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations[types.RESET_ITEMS_FOR_LIST](state, listId);
|
|
|
|
|
|
|
|
expect(state.boardItemsByListId[listId]).toEqual([]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('REQUEST_ITEMS_FOR_LIST', () => {
|
|
|
|
const listId = 'gid://gitlab/List/1';
|
|
|
|
const boardItemsByListId = {
|
|
|
|
[listId]: [mockIssue.id],
|
|
|
|
};
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
fetchNext | isLoading | isLoadingMore
|
|
|
|
${true} | ${undefined} | ${true}
|
|
|
|
${false} | ${true} | ${undefined}
|
|
|
|
`(
|
|
|
|
'sets isLoading to $isLoading and isLoadingMore to $isLoadingMore when fetchNext is $fetchNext',
|
|
|
|
({ fetchNext, isLoading, isLoadingMore }) => {
|
|
|
|
state = {
|
|
|
|
...state,
|
|
|
|
boardItemsByListId,
|
|
|
|
listsFlags: {
|
|
|
|
[listId]: {},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations[types.REQUEST_ITEMS_FOR_LIST](state, { listId, fetchNext });
|
|
|
|
|
|
|
|
expect(state.listsFlags[listId].isLoading).toBe(isLoading);
|
|
|
|
expect(state.listsFlags[listId].isLoadingMore).toBe(isLoadingMore);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
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.',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe('UPDATE_BOARD_ITEM_BY_ID', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
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', () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
mutations.UPDATE_BOARD_ITEM_BY_ID(state, {
|
|
|
|
itemId: issueId,
|
2020-11-24 15:15:51 +05:30
|
|
|
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(() => {
|
2021-04-29 21:17:54 +05:30
|
|
|
mutations.UPDATE_BOARD_ITEM_BY_ID(state, {
|
|
|
|
itemId: '3',
|
2020-11-24 15:15:51 +05:30
|
|
|
prop,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
}).toThrow(new Error('No issue found.'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe('MUTATE_ISSUE_SUCCESS', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
it('updates issue in issues state', () => {
|
|
|
|
const issues = {
|
2021-11-11 11:23:49 +05:30
|
|
|
[rawIssue.id]: { 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
|
|
|
};
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
mutations.MUTATE_ISSUE_SUCCESS(state, {
|
2020-11-24 15:15:51 +05:30
|
|
|
issue: rawIssue,
|
|
|
|
});
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(state.boardItems).toEqual({ [mockIssue.id]: mockIssue });
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe('UPDATE_BOARD_ITEM', () => {
|
|
|
|
it('updates the given issue in state.boardItems', () => {
|
|
|
|
const updatedIssue = { id: 'some_gid', foo: 'bar' };
|
|
|
|
state = { boardItems: { some_gid: { id: 'some_gid' } } };
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
mutations.UPDATE_BOARD_ITEM(state, updatedIssue);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(state.boardItems.some_gid).toEqual(updatedIssue);
|
|
|
|
});
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe('REMOVE_BOARD_ITEM', () => {
|
|
|
|
it('removes the given issue from state.boardItems', () => {
|
|
|
|
state = { boardItems: { some_gid: {}, some_gid2: {} } };
|
|
|
|
|
|
|
|
mutations.REMOVE_BOARD_ITEM(state, 'some_gid');
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(state.boardItems).toEqual({ some_gid2: {} });
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe('ADD_BOARD_ITEM_TO_LIST', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setBoardsListsState();
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
[
|
|
|
|
'at position 0 by default',
|
|
|
|
{
|
|
|
|
payload: {
|
|
|
|
itemId: mockIssue2.id,
|
|
|
|
listId: mockList.id,
|
|
|
|
},
|
|
|
|
listState: [mockIssue2.id, mockIssue.id],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'at a given position',
|
|
|
|
{
|
|
|
|
payload: {
|
|
|
|
itemId: mockIssue2.id,
|
|
|
|
listId: mockList.id,
|
|
|
|
atIndex: 1,
|
|
|
|
},
|
|
|
|
listState: [mockIssue.id, mockIssue2.id],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"below the issue with id of 'moveBeforeId'",
|
|
|
|
{
|
|
|
|
payload: {
|
|
|
|
itemId: mockIssue2.id,
|
|
|
|
listId: mockList.id,
|
|
|
|
moveBeforeId: mockIssue.id,
|
|
|
|
},
|
|
|
|
listState: [mockIssue.id, mockIssue2.id],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"above the issue with id of 'moveAfterId'",
|
|
|
|
{
|
|
|
|
payload: {
|
|
|
|
itemId: mockIssue2.id,
|
|
|
|
listId: mockList.id,
|
|
|
|
moveAfterId: mockIssue.id,
|
|
|
|
},
|
|
|
|
listState: [mockIssue2.id, mockIssue.id],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
])(`inserts an item into a list %s`, (_, { payload, listState }) => {
|
|
|
|
mutations.ADD_BOARD_ITEM_TO_LIST(state, payload);
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(state.boardItemsByListId[payload.listId]).toEqual(listState);
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it("updates the list's items count", () => {
|
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-04-29 21:17:54 +05:30
|
|
|
mutations.ADD_BOARD_ITEM_TO_LIST(state, {
|
|
|
|
itemId: mockIssue2.id,
|
|
|
|
listId: mockList.id,
|
|
|
|
});
|
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(2);
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe('REMOVE_BOARD_ITEM_FROM_LIST', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setBoardsListsState();
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it("removes an item from a list and updates the list's items count", () => {
|
|
|
|
expect(state.boardLists['gid://gitlab/List/1'].issuesCount).toBe(1);
|
|
|
|
expect(state.boardItemsByListId['gid://gitlab/List/1']).toContain(mockIssue.id);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
mutations.REMOVE_BOARD_ITEM_FROM_LIST(state, {
|
|
|
|
itemId: mockIssue.id,
|
|
|
|
listId: mockList.id,
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(state.boardItemsByListId['gid://gitlab/List/1']).not.toContain(mockIssue.id);
|
|
|
|
expect(state.boardLists['gid://gitlab/List/1'].issuesCount).toBe(0);
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
it('Should set isLoadingMore in groupProjectsFlags to true in state when fetchNext is true', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
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([]);
|
|
|
|
});
|
|
|
|
});
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
describe('SET_ERROR', () => {
|
|
|
|
it('Should set error state', () => {
|
|
|
|
state.error = undefined;
|
|
|
|
|
|
|
|
mutations[types.SET_ERROR](state, 'mayday');
|
|
|
|
|
|
|
|
expect(state.error).toBe('mayday');
|
|
|
|
});
|
|
|
|
});
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|