2020-11-24 15:15:51 +05:30
|
|
|
import { inactiveId } from '~/boards/constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import getters from '~/boards/stores/getters';
|
2021-01-03 14:25:43 +05:30
|
|
|
import {
|
|
|
|
mockIssue,
|
|
|
|
mockIssue2,
|
|
|
|
mockIssues,
|
|
|
|
mockIssuesByListId,
|
|
|
|
issues,
|
2021-02-22 17:27:13 +05:30
|
|
|
mockLists,
|
2021-04-17 20:07:23 +05:30
|
|
|
mockGroupProject1,
|
|
|
|
mockArchivedGroupProject,
|
2021-01-03 14:25:43 +05:30
|
|
|
} from '../mock_data';
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
describe('Boards - Getters', () => {
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('isGroupBoard', () => {
|
|
|
|
it('returns true when boardType on state is group', () => {
|
|
|
|
const state = {
|
|
|
|
boardType: 'group',
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(getters.isGroupBoard(state)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false when boardType on state is not group', () => {
|
|
|
|
const state = {
|
|
|
|
boardType: 'project',
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(getters.isGroupBoard(state)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isProjectBoard', () => {
|
|
|
|
it('returns true when boardType on state is project', () => {
|
|
|
|
const state = {
|
|
|
|
boardType: 'project',
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(getters.isProjectBoard(state)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false when boardType on state is not project', () => {
|
|
|
|
const state = {
|
|
|
|
boardType: 'group',
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(getters.isProjectBoard(state)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
describe('isSidebarOpen', () => {
|
|
|
|
it('returns true when activeId is not equal to 0', () => {
|
|
|
|
const state = {
|
|
|
|
activeId: 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(getters.isSidebarOpen(state)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false when activeId is equal to 0', () => {
|
|
|
|
const state = {
|
|
|
|
activeId: inactiveId,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(getters.isSidebarOpen(state)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isSwimlanesOn', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
window.gon = { features: {} };
|
|
|
|
});
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('returns false', () => {
|
|
|
|
expect(getters.isSwimlanesOn()).toBe(false);
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('getBoardItemById', () => {
|
|
|
|
const state = { boardItems: { 1: 'issue' } };
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
it.each`
|
|
|
|
id | expected
|
|
|
|
${'1'} | ${'issue'}
|
|
|
|
${''} | ${{}}
|
|
|
|
`('returns $expected when $id is passed to state', ({ id, expected }) => {
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(getters.getBoardItemById(state)(id)).toEqual(expected);
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('activeIssue', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
it.each`
|
|
|
|
id | expected
|
|
|
|
${'1'} | ${'issue'}
|
|
|
|
${''} | ${{}}
|
|
|
|
`('returns $expected when $id is passed to state', ({ id, expected }) => {
|
2021-04-17 20:07:23 +05:30
|
|
|
const state = { boardItems: { 1: 'issue' }, activeId: id };
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(getters.activeIssue(state)).toEqual(expected);
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
describe('groupPathByIssueId', () => {
|
|
|
|
it('returns group path for the active issue', () => {
|
|
|
|
const mockActiveIssue = {
|
|
|
|
referencePath: 'gitlab-org/gitlab-test#1',
|
|
|
|
};
|
|
|
|
expect(getters.groupPathForActiveIssue({}, { activeIssue: mockActiveIssue })).toEqual(
|
|
|
|
'gitlab-org',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns empty string as group path when active issue is an empty object', () => {
|
|
|
|
const mockActiveIssue = {};
|
|
|
|
expect(getters.groupPathForActiveIssue({}, { activeIssue: mockActiveIssue })).toEqual('');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('projectPathByIssueId', () => {
|
|
|
|
it('returns project path for the active issue', () => {
|
|
|
|
const mockActiveIssue = {
|
|
|
|
referencePath: 'gitlab-org/gitlab-test#1',
|
|
|
|
};
|
|
|
|
expect(getters.projectPathForActiveIssue({}, { activeIssue: mockActiveIssue })).toEqual(
|
|
|
|
'gitlab-org/gitlab-test',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it('returns empty string as project path when active issue is an empty object', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
const mockActiveIssue = {};
|
|
|
|
expect(getters.projectPathForActiveIssue({}, { activeIssue: mockActiveIssue })).toEqual('');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('getBoardItemsByList', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
const boardsState = {
|
2021-04-17 20:07:23 +05:30
|
|
|
boardItemsByListId: mockIssuesByListId,
|
|
|
|
boardItems: issues,
|
2020-11-24 15:15:51 +05:30
|
|
|
};
|
|
|
|
it('returns issues for a given listId', () => {
|
2021-04-17 20:07:23 +05:30
|
|
|
const getBoardItemById = (issueId) =>
|
|
|
|
[mockIssue, mockIssue2].find(({ id }) => id === issueId);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(
|
|
|
|
getters.getBoardItemsByList(boardsState, { getBoardItemById })('gid://gitlab/List/2'),
|
|
|
|
).toEqual(mockIssues);
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
const boardsState = {
|
|
|
|
boardLists: {
|
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
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('getListByLabelId', () => {
|
|
|
|
it('returns list for a given label id', () => {
|
|
|
|
expect(getters.getListByLabelId(boardsState)('gid://gitlab/GroupLabel/121')).toEqual(
|
2021-02-22 17:27:13 +05:30
|
|
|
mockLists[1],
|
2021-01-03 14:25:43 +05:30
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getListByTitle', () => {
|
|
|
|
it('returns list for a given list title', () => {
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(getters.getListByTitle(boardsState)('To Do')).toEqual(mockLists[1]);
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
});
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
describe('activeGroupProjects', () => {
|
|
|
|
const state = {
|
|
|
|
groupProjects: [mockGroupProject1, mockArchivedGroupProject],
|
|
|
|
};
|
|
|
|
|
|
|
|
it('returns only returns non-archived group projects', () => {
|
|
|
|
expect(getters.activeGroupProjects(state)).toEqual([mockGroupProject1]);
|
|
|
|
});
|
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|