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

444 lines
12 KiB
JavaScript
Raw Normal View History

2019-09-04 21:01:54 +05:30
import mutations from '~/boards/stores/mutations';
2020-11-24 15:15:51 +05:30
import * as types from '~/boards/stores/mutation_types';
2020-06-23 00:09:42 +05:30
import defaultState from '~/boards/stores/state';
2020-11-24 15:15:51 +05:30
import {
listObj,
listObjDuplicate,
mockListsWithModel,
mockLists,
rawIssue,
mockIssue,
mockIssue2,
mockIssueWithModel,
mockIssue2WithModel,
} from '../mock_data';
2019-09-04 21:01:54 +05:30
const expectNotImplemented = action => {
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
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', () => {
const endpoints = {
boardsEndpoint: '/boards/',
recentBoardsEndpoint: '/boards/',
listsEndpoint: '/boards/lists',
bulkUpdatePath: '/boards/bulkUpdate',
boardId: 1,
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;
const showPromotion = false;
2020-06-23 00:09:42 +05:30
2020-11-24 15:15:51 +05:30
mutations[types.SET_INITIAL_BOARD_DATA](state, {
...endpoints,
boardType,
disabled,
showPromotion,
});
2020-06-23 00:09:42 +05:30
expect(state.endpoints).toEqual(endpoints);
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);
expect(state.showPromotion).toEqual(showPromotion);
});
});
describe('RECEIVE_BOARD_LISTS_SUCCESS', () => {
it('Should set boardLists to state', () => {
const lists = [listObj, listObjDuplicate];
mutations[types.RECEIVE_BOARD_LISTS_SUCCESS](state, lists);
expect(state.boardLists).toEqual(lists);
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);
});
it('updates aciveListId to be the value that is passed', () => {
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
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', () => {
expectNotImplemented(mutations.RECEIVE_ADD_LIST_SUCCESS);
});
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,
boardLists: mockListsWithModel,
};
2019-09-04 21:01:54 +05:30
2020-11-24 15:15:51 +05:30
mutations.MOVE_LIST(state, {
movedList: mockListsWithModel[0],
listAtNewIndex: mockListsWithModel[1],
});
expect(state.boardLists).toEqual([mockListsWithModel[1], mockListsWithModel[0]]);
});
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,
boardLists: [mockListsWithModel[1], mockListsWithModel[0]],
error: undefined,
};
mutations.UPDATE_LIST_FAILURE(state, mockListsWithModel);
expect(state.boardLists).toEqual(mockListsWithModel);
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
2020-06-23 00:09:42 +05:30
describe('REQUEST_REMOVE_LIST', () => {
expectNotImplemented(mutations.REQUEST_REMOVE_LIST);
});
2019-09-04 21:01:54 +05:30
2020-06-23 00:09:42 +05:30
describe('RECEIVE_REMOVE_LIST_SUCCESS', () => {
expectNotImplemented(mutations.RECEIVE_REMOVE_LIST_SUCCESS);
});
2019-09-04 21:01:54 +05:30
2020-06-23 00:09:42 +05:30
describe('RECEIVE_REMOVE_LIST_ERROR', () => {
expectNotImplemented(mutations.RECEIVE_REMOVE_LIST_ERROR);
});
2019-09-04 21:01:54 +05:30
2020-11-24 15:15:51 +05:30
describe('RECEIVE_ISSUES_FOR_LIST_SUCCESS', () => {
it('updates issuesByListId and issues on state', () => {
const listIssues = {
'gid://gitlab/List/1': [mockIssue.id],
};
const issues = {
'1': mockIssue,
};
state = {
...state,
isLoadingIssues: true,
issuesByListId: {},
issues: {},
boardLists: mockListsWithModel,
};
mutations.RECEIVE_ISSUES_FOR_LIST_SUCCESS(state, {
listIssues: { listData: listIssues, issues },
listId: 'gid://gitlab/List/1',
});
expect(state.issuesByListId).toEqual(listIssues);
expect(state.issues).toEqual(issues);
});
});
2020-10-24 23:57:45 +05:30
describe('REQUEST_ISSUES_FOR_ALL_LISTS', () => {
it('sets isLoadingIssues to true', () => {
expect(state.isLoadingIssues).toBe(false);
mutations.REQUEST_ISSUES_FOR_ALL_LISTS(state);
expect(state.isLoadingIssues).toBe(true);
});
});
2020-11-24 15:15:51 +05:30
describe('RECEIVE_ISSUES_FOR_LIST_FAILURE', () => {
it('sets error message', () => {
state = {
...state,
boardLists: mockListsWithModel,
error: undefined,
};
const listId = 'gid://gitlab/List/1';
mutations.RECEIVE_ISSUES_FOR_LIST_FAILURE(state, listId);
expect(state.error).toEqual(
'An error occurred while fetching the board issues. Please reload the page.',
);
});
});
2020-10-24 23:57:45 +05:30
describe('RECEIVE_ISSUES_FOR_ALL_LISTS_SUCCESS', () => {
it('sets isLoadingIssues to false and updates issuesByListId object', () => {
const listIssues = {
2020-11-24 15:15:51 +05:30
'gid://gitlab/List/1': [mockIssue.id],
};
const issues = {
'1': mockIssue,
2020-10-24 23:57:45 +05:30
};
state = {
...state,
isLoadingIssues: true,
issuesByListId: {},
2020-11-24 15:15:51 +05:30
issues: {},
2020-10-24 23:57:45 +05:30
};
2020-11-24 15:15:51 +05:30
mutations.RECEIVE_ISSUES_FOR_ALL_LISTS_SUCCESS(state, { listData: listIssues, issues });
2020-10-24 23:57:45 +05:30
expect(state.isLoadingIssues).toBe(false);
expect(state.issuesByListId).toEqual(listIssues);
2020-11-24 15:15:51 +05:30
expect(state.issues).toEqual(issues);
2020-10-24 23:57:45 +05:30
});
});
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('RECEIVE_ISSUES_FOR_ALL_LISTS_FAILURE', () => {
it('sets isLoadingIssues to false and sets error message', () => {
state = {
...state,
isLoadingIssues: true,
error: undefined,
};
mutations.RECEIVE_ISSUES_FOR_ALL_LISTS_FAILURE(state);
expect(state.isLoadingIssues).toBe(false);
expect(state.error).toEqual(
'An error occurred while fetching the board issues. Please reload the page.',
);
});
});
describe('UPDATE_ISSUE_BY_ID', () => {
const issueId = '1';
const prop = 'id';
const value = '2';
const issue = { [issueId]: { id: 1, title: 'Issue' } };
beforeEach(() => {
state = {
...state,
isLoadingIssues: true,
error: undefined,
issues: {
...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,
});
expect(state.issues[issueId]).toEqual({ ...issue[issueId], id: '2' });
});
});
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', () => {
it('updates issuesByListId, moving issue between lists', () => {
const listIssues = {
'gid://gitlab/List/1': [mockIssue.id, mockIssue2.id],
'gid://gitlab/List/2': [],
};
const issues = {
'1': mockIssueWithModel,
'2': mockIssue2WithModel,
};
state = {
...state,
issuesByListId: listIssues,
boardLists: mockListsWithModel,
issues,
};
mutations.MOVE_ISSUE(state, {
originalIssue: mockIssue2WithModel,
fromListId: 'gid://gitlab/List/1',
toListId: 'gid://gitlab/List/2',
});
const updatedListIssues = {
'gid://gitlab/List/1': [mockIssue.id],
'gid://gitlab/List/2': [mockIssue2.id],
};
expect(state.issuesByListId).toEqual(updatedListIssues);
});
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 = {
'436': { id: rawIssue.id },
};
state = {
...state,
issues,
};
mutations.MOVE_ISSUE_SUCCESS(state, {
issue: rawIssue,
});
expect(state.issues).toEqual({ '436': { ...mockIssueWithModel, id: 436 } });
});
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', () => {
it('updates issuesByListId, reverting moving issue between lists, and sets error message', () => {
const listIssues = {
'gid://gitlab/List/1': [mockIssue.id],
'gid://gitlab/List/2': [mockIssue2.id],
};
state = {
...state,
issuesByListId: listIssues,
};
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': [],
};
expect(state.issuesByListId).toEqual(updatedListIssues);
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);
});
2020-11-24 15:15:51 +05:30
describe('ADD_ISSUE_TO_LIST', () => {
it('adds issue to issues state and issue id in list in issuesByListId', () => {
const listIssues = {
'gid://gitlab/List/1': [mockIssue.id],
};
const issues = {
'1': mockIssue,
};
state = {
...state,
issuesByListId: listIssues,
issues,
};
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);
});
});
describe('ADD_ISSUE_TO_LIST_FAILURE', () => {
it('removes issue id from list in issuesByListId', () => {
const listIssues = {
'gid://gitlab/List/1': [mockIssue.id, mockIssue2.id],
};
const issues = {
'1': mockIssue,
'2': mockIssue2,
};
state = {
...state,
issuesByListId: listIssues,
issues,
};
mutations.ADD_ISSUE_TO_LIST_FAILURE(state, { list: mockLists[0], issue: mockIssue2 });
expect(state.issuesByListId['gid://gitlab/List/1']).not.toContain(mockIssue2.id);
});
});
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);
});
2019-09-04 21:01:54 +05:30
});