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