2018-12-13 13:39:08 +05:30
|
|
|
/* eslint-disable no-unused-vars */
|
2017-08-17 22:00:37 +05:30
|
|
|
/* global ListIssue */
|
|
|
|
|
|
|
|
import Vue from 'vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-08-17 22:00:37 +05:30
|
|
|
import Cookies from 'js-cookie';
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
import '~/vue_shared/models/label';
|
2018-11-08 19:23:39 +05:30
|
|
|
import '~/vue_shared/models/assignee';
|
2017-08-17 22:00:37 +05:30
|
|
|
import '~/boards/models/issue';
|
|
|
|
import '~/boards/models/list';
|
|
|
|
import '~/boards/services/board_service';
|
2018-12-13 13:39:08 +05:30
|
|
|
import boardsStore from '~/boards/stores/boards_store';
|
2018-03-17 18:26:18 +05:30
|
|
|
import { listObj, listObjDuplicate, boardsMockInterceptor, mockBoardService } from './mock_data';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe('Store', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
let mock;
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
beforeEach(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onAny().reply(boardsMockInterceptor);
|
|
|
|
gl.boardService = mockBoardService();
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.create();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
spyOn(gl.boardService, 'moveIssue').and.callFake(
|
|
|
|
() =>
|
|
|
|
new Promise(resolve => {
|
|
|
|
resolve();
|
|
|
|
}),
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
Cookies.set('issue_board_welcome_hidden', 'false', {
|
|
|
|
expires: 365 * 10,
|
2018-12-13 13:39:08 +05:30
|
|
|
path: '',
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
mock.restore();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('starts with a blank state', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(boardsStore.state.lists.length).toBe(0);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('lists', () => {
|
|
|
|
it('creates new list without persisting to DB', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.addList(listObj);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(boardsStore.state.lists.length).toBe(1);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('finds list by ID', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.addList(listObj);
|
|
|
|
const list = boardsStore.findList('id', listObj.id);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(list.id).toBe(listObj.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('finds list by type', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.addList(listObj);
|
|
|
|
const list = boardsStore.findList('type', 'label');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(list).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
it('finds list by label ID', () => {
|
|
|
|
boardsStore.addList(listObj);
|
|
|
|
const list = boardsStore.findListByLabelId(listObj.label.id);
|
|
|
|
|
|
|
|
expect(list.id).toBe(listObj.id);
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('gets issue when new list added', done => {
|
|
|
|
boardsStore.addList(listObj);
|
|
|
|
const list = boardsStore.findList('id', listObj.id);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(boardsStore.state.lists.length).toBe(1);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(list.issues.length).toBe(1);
|
|
|
|
expect(list.issues[0].id).toBe(1);
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('persists new list', done => {
|
|
|
|
boardsStore.new({
|
2017-08-17 22:00:37 +05:30
|
|
|
title: 'Test',
|
2018-03-17 18:26:18 +05:30
|
|
|
list_type: 'label',
|
2017-08-17 22:00:37 +05:30
|
|
|
label: {
|
|
|
|
id: 1,
|
|
|
|
title: 'Testing',
|
|
|
|
color: 'red',
|
2018-12-13 13:39:08 +05:30
|
|
|
description: 'testing;',
|
|
|
|
},
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
expect(boardsStore.state.lists.length).toBe(1);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
const list = boardsStore.findList('id', listObj.id);
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(list).toBeDefined();
|
|
|
|
expect(list.id).toBe(listObj.id);
|
|
|
|
expect(list.position).toBe(0);
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('check for blank state adding', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(boardsStore.shouldAddBlankState()).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('check for blank state not adding', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.addList(listObj);
|
|
|
|
|
|
|
|
expect(boardsStore.shouldAddBlankState()).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('check for blank state adding when closed list exist', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.addList({
|
|
|
|
list_type: 'closed',
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(boardsStore.shouldAddBlankState()).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('adds the blank state', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.addBlankState();
|
|
|
|
|
|
|
|
const list = boardsStore.findList('type', 'blank', 'blank');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(list).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes list from state', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.addList(listObj);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(boardsStore.state.lists.length).toBe(1);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.removeList(listObj.id, 'label');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(boardsStore.state.lists.length).toBe(0);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('moves the position of lists', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
const listOne = boardsStore.addList(listObj);
|
|
|
|
const listTwo = boardsStore.addList(listObjDuplicate);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(boardsStore.state.lists.length).toBe(2);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.moveList(listOne, [listObjDuplicate.id, listObj.id]);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(listOne.position).toBe(1);
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('moves an issue from one list to another', done => {
|
|
|
|
const listOne = boardsStore.addList(listObj);
|
|
|
|
const listTwo = boardsStore.addList(listObjDuplicate);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(boardsStore.state.lists.length).toBe(2);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(listOne.issues.length).toBe(1);
|
|
|
|
expect(listTwo.issues.length).toBe(1);
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.moveIssueToList(listOne, listTwo, listOne.findIssue(1));
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(listOne.issues.length).toBe(0);
|
|
|
|
expect(listTwo.issues.length).toBe(1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('moves an issue from backlog to a list', done => {
|
|
|
|
const backlog = boardsStore.addList({
|
2018-11-18 11:00:15 +05:30
|
|
|
...listObj,
|
|
|
|
list_type: 'backlog',
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
const listTwo = boardsStore.addList(listObjDuplicate);
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(boardsStore.state.lists.length).toBe(2);
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(backlog.issues.length).toBe(1);
|
|
|
|
expect(listTwo.issues.length).toBe(1);
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.moveIssueToList(backlog, listTwo, backlog.findIssue(1));
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
expect(backlog.issues.length).toBe(0);
|
|
|
|
expect(listTwo.issues.length).toBe(1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('moves issue to top of another list', done => {
|
|
|
|
const listOne = boardsStore.addList(listObj);
|
|
|
|
const listTwo = boardsStore.addList(listObjDuplicate);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(boardsStore.state.lists.length).toBe(2);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
listOne.issues[0].id = 2;
|
|
|
|
|
|
|
|
expect(listOne.issues.length).toBe(1);
|
|
|
|
expect(listTwo.issues.length).toBe(1);
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.moveIssueToList(listOne, listTwo, listOne.findIssue(2), 0);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(listOne.issues.length).toBe(0);
|
|
|
|
expect(listTwo.issues.length).toBe(2);
|
|
|
|
expect(listTwo.issues[0].id).toBe(2);
|
|
|
|
expect(gl.boardService.moveIssue).toHaveBeenCalledWith(2, listOne.id, listTwo.id, null, 1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('moves issue to bottom of another list', done => {
|
|
|
|
const listOne = boardsStore.addList(listObj);
|
|
|
|
const listTwo = boardsStore.addList(listObjDuplicate);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(boardsStore.state.lists.length).toBe(2);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
listOne.issues[0].id = 2;
|
|
|
|
|
|
|
|
expect(listOne.issues.length).toBe(1);
|
|
|
|
expect(listTwo.issues.length).toBe(1);
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.moveIssueToList(listOne, listTwo, listOne.findIssue(2), 1);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(listOne.issues.length).toBe(0);
|
|
|
|
expect(listTwo.issues.length).toBe(2);
|
|
|
|
expect(listTwo.issues[1].id).toBe(2);
|
|
|
|
expect(gl.boardService.moveIssue).toHaveBeenCalledWith(2, listOne.id, listTwo.id, 1, null);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('moves issue in list', done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
const issue = new ListIssue({
|
|
|
|
title: 'Testing',
|
2018-03-17 18:26:18 +05:30
|
|
|
id: 2,
|
2017-08-17 22:00:37 +05:30
|
|
|
iid: 2,
|
|
|
|
confidential: false,
|
|
|
|
labels: [],
|
|
|
|
assignees: [],
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
const list = boardsStore.addList(listObj);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
list.addIssue(issue);
|
|
|
|
|
|
|
|
expect(list.issues.length).toBe(2);
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.moveIssueInList(list, issue, 0, 1, [1, 2]);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(list.issues[0].id).toBe(2);
|
|
|
|
expect(gl.boardService.moveIssue).toHaveBeenCalledWith(2, null, null, 1, null);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|