2017-01-26 12:55:08 +00:00
|
|
|
/* global ListIssue */
|
|
|
|
|
2018-03-05 12:35:58 +00:00
|
|
|
import '~/vue_shared/models/label';
|
2018-06-07 20:54:24 +00:00
|
|
|
import '~/vue_shared/models/assignee';
|
2017-05-04 12:11:15 +00:00
|
|
|
import '~/boards/models/issue';
|
|
|
|
import '~/boards/models/list';
|
2018-04-06 12:12:21 +00:00
|
|
|
import Store from '~/boards/stores/modal_store';
|
2017-01-26 12:55:08 +00:00
|
|
|
|
|
|
|
describe('Modal store', () => {
|
|
|
|
let issue;
|
|
|
|
let issue2;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-09-17 09:17:33 +00:00
|
|
|
// Set up default state
|
2017-01-26 12:55:08 +00:00
|
|
|
Store.store.issues = [];
|
|
|
|
Store.store.selectedIssues = [];
|
|
|
|
|
|
|
|
issue = new ListIssue({
|
|
|
|
title: 'Testing',
|
2017-09-06 06:49:19 +00:00
|
|
|
id: 1,
|
2017-01-26 12:55:08 +00:00
|
|
|
iid: 1,
|
|
|
|
confidential: false,
|
|
|
|
labels: [],
|
2017-05-04 12:11:15 +00:00
|
|
|
assignees: [],
|
2017-01-26 12:55:08 +00:00
|
|
|
});
|
|
|
|
issue2 = new ListIssue({
|
|
|
|
title: 'Testing',
|
2017-09-06 06:49:19 +00:00
|
|
|
id: 1,
|
2017-01-26 12:55:08 +00:00
|
|
|
iid: 2,
|
|
|
|
confidential: false,
|
|
|
|
labels: [],
|
2017-05-04 12:11:15 +00:00
|
|
|
assignees: [],
|
2017-01-26 12:55:08 +00:00
|
|
|
});
|
|
|
|
Store.store.issues.push(issue);
|
|
|
|
Store.store.issues.push(issue2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns selected count', () => {
|
|
|
|
expect(Store.selectedCount()).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('toggles the issue as selected', () => {
|
|
|
|
Store.toggleIssue(issue);
|
|
|
|
|
|
|
|
expect(issue.selected).toBe(true);
|
|
|
|
expect(Store.selectedCount()).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('toggles the issue as un-selected', () => {
|
|
|
|
Store.toggleIssue(issue);
|
|
|
|
Store.toggleIssue(issue);
|
|
|
|
|
|
|
|
expect(issue.selected).toBe(false);
|
|
|
|
expect(Store.selectedCount()).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('toggles all issues as selected', () => {
|
|
|
|
Store.toggleAll();
|
|
|
|
|
|
|
|
expect(issue.selected).toBe(true);
|
|
|
|
expect(issue2.selected).toBe(true);
|
|
|
|
expect(Store.selectedCount()).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('toggles all issues as un-selected', () => {
|
|
|
|
Store.toggleAll();
|
|
|
|
Store.toggleAll();
|
|
|
|
|
|
|
|
expect(issue.selected).toBe(false);
|
|
|
|
expect(issue2.selected).toBe(false);
|
|
|
|
expect(Store.selectedCount()).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('toggles all if a single issue is selected', () => {
|
|
|
|
Store.toggleIssue(issue);
|
|
|
|
Store.toggleAll();
|
|
|
|
|
|
|
|
expect(issue.selected).toBe(true);
|
|
|
|
expect(issue2.selected).toBe(true);
|
|
|
|
expect(Store.selectedCount()).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds issue to selected array', () => {
|
2017-01-27 16:49:56 +00:00
|
|
|
issue.selected = true;
|
2017-01-26 12:55:08 +00:00
|
|
|
Store.addSelectedIssue(issue);
|
|
|
|
|
|
|
|
expect(Store.selectedCount()).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes issue from selected array', () => {
|
|
|
|
Store.addSelectedIssue(issue);
|
|
|
|
Store.removeSelectedIssue(issue);
|
|
|
|
|
|
|
|
expect(Store.selectedCount()).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns selected issue index if present', () => {
|
|
|
|
Store.toggleIssue(issue);
|
|
|
|
|
|
|
|
expect(Store.selectedIssueIndex(issue)).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns -1 if issue is not selected', () => {
|
|
|
|
expect(Store.selectedIssueIndex(issue)).toBe(-1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('finds the selected issue', () => {
|
|
|
|
Store.toggleIssue(issue);
|
|
|
|
|
|
|
|
expect(Store.findSelectedIssue(issue)).toBe(issue);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not find a selected issue', () => {
|
|
|
|
expect(Store.findSelectedIssue(issue)).toBe(undefined);
|
|
|
|
});
|
2017-01-27 16:49:56 +00:00
|
|
|
|
|
|
|
it('does not remove from selected issue if tab is not all', () => {
|
|
|
|
Store.store.activeTab = 'selected';
|
|
|
|
|
|
|
|
Store.toggleIssue(issue);
|
|
|
|
Store.toggleIssue(issue);
|
|
|
|
|
|
|
|
expect(Store.store.selectedIssues.length).toBe(1);
|
|
|
|
expect(Store.selectedCount()).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('gets selected issue array with only selected issues', () => {
|
|
|
|
Store.toggleIssue(issue);
|
|
|
|
Store.toggleIssue(issue2);
|
|
|
|
Store.toggleIssue(issue2);
|
|
|
|
|
|
|
|
expect(Store.getSelectedIssues().length).toBe(1);
|
|
|
|
});
|
2017-01-26 12:55:08 +00:00
|
|
|
});
|