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

132 lines
3.6 KiB
JavaScript
Raw Normal View History

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-01-03 14:25:43 +05:30
} from '../mock_data';
2019-12-26 22:10:19 +05:30
describe('Boards - Getters', () => {
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
});
});
describe('getIssueById', () => {
2021-03-08 18:12:59 +05:30
const state = { issues: { 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 }) => {
expect(getters.getIssueById(state)(id)).toEqual(expected);
});
});
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-03-08 18:12:59 +05:30
const state = { issues: { 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('');
});
});
describe('getIssuesByList', () => {
2020-11-24 15:15:51 +05:30
const boardsState = {
issuesByListId: mockIssuesByListId,
issues,
};
it('returns issues for a given listId', () => {
2021-03-08 18:12:59 +05:30
const getIssueById = (issueId) => [mockIssue, mockIssue2].find(({ id }) => id === issueId);
2020-11-24 15:15:51 +05:30
2021-01-29 00:20:46 +05:30
expect(getters.getIssuesByList(boardsState, { getIssueById })('gid://gitlab/List/2')).toEqual(
2020-11-24 15:15:51 +05:30
mockIssues,
);
});
});
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
});
});
2019-12-26 22:10:19 +05:30
});