gitlab-org--gitlab-foss/spec/javascripts/boards/boards_store_spec.js

258 lines
7.6 KiB
JavaScript
Raw Normal View History

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