2019-10-28 11:05:58 -04:00
|
|
|
import getters from '~/boards/stores/getters';
|
2020-08-25 02:10:18 -04:00
|
|
|
import { inactiveId } from '~/boards/constants';
|
2020-10-14 05:08:46 -04:00
|
|
|
import {
|
|
|
|
mockIssue,
|
|
|
|
mockIssue2,
|
|
|
|
mockIssues,
|
|
|
|
mockIssuesByListId,
|
|
|
|
issues,
|
2020-12-14 16:09:47 -05:00
|
|
|
mockLists,
|
2020-10-14 05:08:46 -04:00
|
|
|
} from '../mock_data';
|
2019-10-28 11:05:58 -04:00
|
|
|
|
|
|
|
describe('Boards - Getters', () => {
|
2020-08-25 02:10:18 -04:00
|
|
|
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: {} };
|
|
|
|
});
|
|
|
|
|
2020-11-26 13:09:18 -05:00
|
|
|
it('returns false', () => {
|
|
|
|
expect(getters.isSwimlanesOn()).toBe(false);
|
2020-08-25 02:10:18 -04:00
|
|
|
});
|
|
|
|
});
|
2020-09-02 14:10:40 -04:00
|
|
|
|
|
|
|
describe('getIssueById', () => {
|
|
|
|
const state = { issues: { '1': 'issue' } };
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
id | expected
|
|
|
|
${'1'} | ${'issue'}
|
|
|
|
${''} | ${{}}
|
|
|
|
`('returns $expected when $id is passed to state', ({ id, expected }) => {
|
|
|
|
expect(getters.getIssueById(state)(id)).toEqual(expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-09 07:09:24 -05:00
|
|
|
describe('activeIssue', () => {
|
2020-09-02 14:10:40 -04:00
|
|
|
it.each`
|
|
|
|
id | expected
|
|
|
|
${'1'} | ${'issue'}
|
|
|
|
${''} | ${{}}
|
|
|
|
`('returns $expected when $id is passed to state', ({ id, expected }) => {
|
|
|
|
const state = { issues: { '1': 'issue' }, activeId: id };
|
|
|
|
|
2020-11-09 07:09:24 -05:00
|
|
|
expect(getters.activeIssue(state)).toEqual(expected);
|
2020-09-02 14:10:40 -04:00
|
|
|
});
|
|
|
|
});
|
2020-11-16 04:09:18 -05:00
|
|
|
|
|
|
|
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',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns empty string as project when active issue is an empty object', () => {
|
|
|
|
const mockActiveIssue = {};
|
|
|
|
expect(getters.projectPathForActiveIssue({}, { activeIssue: mockActiveIssue })).toEqual('');
|
|
|
|
});
|
|
|
|
});
|
2020-09-15 05:09:30 -04:00
|
|
|
|
2020-11-09 07:09:24 -05:00
|
|
|
describe('getIssuesByList', () => {
|
2020-09-15 05:09:30 -04:00
|
|
|
const boardsState = {
|
|
|
|
issuesByListId: mockIssuesByListId,
|
|
|
|
issues,
|
|
|
|
};
|
|
|
|
it('returns issues for a given listId', () => {
|
|
|
|
const getIssueById = issueId => [mockIssue, mockIssue2].find(({ id }) => id === issueId);
|
|
|
|
|
2020-11-09 07:09:24 -05:00
|
|
|
expect(getters.getIssuesByList(boardsState, { getIssueById })('gid://gitlab/List/2')).toEqual(
|
2020-09-15 05:09:30 -04:00
|
|
|
mockIssues,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2020-10-14 05:08:46 -04:00
|
|
|
|
|
|
|
const boardsState = {
|
|
|
|
boardLists: {
|
2020-12-14 16:09:47 -05:00
|
|
|
'gid://gitlab/List/1': mockLists[0],
|
|
|
|
'gid://gitlab/List/2': mockLists[1],
|
2020-10-14 05:08:46 -04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('getListByLabelId', () => {
|
|
|
|
it('returns list for a given label id', () => {
|
|
|
|
expect(getters.getListByLabelId(boardsState)('gid://gitlab/GroupLabel/121')).toEqual(
|
2020-12-14 16:09:47 -05:00
|
|
|
mockLists[1],
|
2020-10-14 05:08:46 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getListByTitle', () => {
|
|
|
|
it('returns list for a given list title', () => {
|
2020-12-14 16:09:47 -05:00
|
|
|
expect(getters.getListByTitle(boardsState)('To Do')).toEqual(mockLists[1]);
|
2020-10-14 05:08:46 -04:00
|
|
|
});
|
|
|
|
});
|
2019-10-28 11:05:58 -04:00
|
|
|
});
|