Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascripts/boards/boards_store_spec.js')
-rw-r--r--spec/javascripts/boards/boards_store_spec.js132
1 files changed, 132 insertions, 0 deletions
diff --git a/spec/javascripts/boards/boards_store_spec.js b/spec/javascripts/boards/boards_store_spec.js
index 11352140ba4..678fe5befa8 100644
--- a/spec/javascripts/boards/boards_store_spec.js
+++ b/spec/javascripts/boards/boards_store_spec.js
@@ -12,6 +12,7 @@ import '~/boards/services/board_service';
import boardsStore from '~/boards/stores/boards_store';
import eventHub from '~/boards/eventhub';
import { listObj, listObjDuplicate, boardsMockInterceptor, mockBoardService } from './mock_data';
+import waitForPromises from '../../frontend/helpers/wait_for_promises';
describe('Store', () => {
let mock;
@@ -29,6 +30,13 @@ describe('Store', () => {
}),
);
+ spyOn(gl.boardService, 'moveMultipleIssues').and.callFake(
+ () =>
+ new Promise(resolve => {
+ resolve();
+ }),
+ );
+
Cookies.set('issue_board_welcome_hidden', 'false', {
expires: 365 * 10,
path: '',
@@ -376,4 +384,128 @@ describe('Store', () => {
expect(state.currentBoard).toEqual(dummyBoard);
});
});
+
+ describe('toggleMultiSelect', () => {
+ let basicIssueObj;
+
+ beforeAll(() => {
+ basicIssueObj = { id: 987654 };
+ });
+
+ afterEach(() => {
+ boardsStore.clearMultiSelect();
+ });
+
+ it('adds issue when not present', () => {
+ boardsStore.toggleMultiSelect(basicIssueObj);
+
+ const selectedIds = boardsStore.multiSelect.list.map(x => x.id);
+
+ expect(selectedIds.includes(basicIssueObj.id)).toEqual(true);
+ });
+
+ it('removes issue when issue is present', () => {
+ boardsStore.toggleMultiSelect(basicIssueObj);
+ let selectedIds = boardsStore.multiSelect.list.map(x => x.id);
+
+ expect(selectedIds.includes(basicIssueObj.id)).toEqual(true);
+
+ boardsStore.toggleMultiSelect(basicIssueObj);
+ selectedIds = boardsStore.multiSelect.list.map(x => x.id);
+
+ expect(selectedIds.includes(basicIssueObj.id)).toEqual(false);
+ });
+ });
+
+ describe('clearMultiSelect', () => {
+ it('clears all the multi selected issues', () => {
+ const issue1 = { id: 12345 };
+ const issue2 = { id: 12346 };
+
+ boardsStore.toggleMultiSelect(issue1);
+ boardsStore.toggleMultiSelect(issue2);
+
+ expect(boardsStore.multiSelect.list.length).toEqual(2);
+
+ boardsStore.clearMultiSelect();
+
+ expect(boardsStore.multiSelect.list.length).toEqual(0);
+ });
+ });
+
+ describe('moveMultipleIssuesToList', () => {
+ it('move issues on the new index', done => {
+ const listOne = boardsStore.addList(listObj);
+ const listTwo = boardsStore.addList(listObjDuplicate);
+
+ expect(boardsStore.state.lists.length).toBe(2);
+
+ setTimeout(() => {
+ expect(listOne.issues.length).toBe(1);
+ expect(listTwo.issues.length).toBe(1);
+
+ boardsStore.moveMultipleIssuesToList({
+ listFrom: listOne,
+ listTo: listTwo,
+ issues: listOne.issues,
+ newIndex: 0,
+ });
+
+ expect(listTwo.issues.length).toBe(1);
+
+ done();
+ }, 0);
+ });
+ });
+
+ describe('moveMultipleIssuesInList', () => {
+ it('moves multiple issues in list', done => {
+ const issueObj = {
+ title: 'Issue #1',
+ id: 12345,
+ iid: 2,
+ confidential: false,
+ labels: [],
+ assignees: [],
+ };
+ const issue1 = new ListIssue(issueObj);
+ const issue2 = new ListIssue({
+ ...issueObj,
+ title: 'Issue #2',
+ id: 12346,
+ });
+
+ const list = boardsStore.addList(listObj);
+
+ waitForPromises()
+ .then(() => {
+ list.addIssue(issue1);
+ list.addIssue(issue2);
+
+ expect(list.issues.length).toBe(3);
+ expect(list.issues[0].id).not.toBe(issue2.id);
+
+ boardsStore.moveMultipleIssuesInList({
+ list,
+ issues: [issue1, issue2],
+ oldIndicies: [0],
+ newIndex: 1,
+ idArray: [1, 12345, 12346],
+ });
+
+ expect(list.issues[0].id).toBe(issue1.id);
+
+ expect(gl.boardService.moveMultipleIssues).toHaveBeenCalledWith({
+ ids: [issue1.id, issue2.id],
+ fromListId: null,
+ toListId: null,
+ moveBeforeId: 1,
+ moveAfterId: null,
+ });
+
+ done();
+ })
+ .catch(done.fail);
+ });
+ });
});