2017-01-11 22:49:57 -05:00
|
|
|
/* eslint-disable comma-dangle, one-var, no-unused-vars */
|
2016-12-13 22:01:05 -05:00
|
|
|
/* global Vue */
|
|
|
|
/* global BoardService */
|
|
|
|
/* global boardsMockInterceptor */
|
|
|
|
/* global Cookies */
|
|
|
|
/* global listObj */
|
|
|
|
/* global listObjDuplicate */
|
|
|
|
|
2017-01-09 18:23:54 -05:00
|
|
|
require('~/lib/utils/url_utility');
|
|
|
|
require('~/boards/models/issue');
|
|
|
|
require('~/boards/models/label');
|
|
|
|
require('~/boards/models/list');
|
|
|
|
require('~/boards/models/user');
|
|
|
|
require('~/boards/services/board_service');
|
|
|
|
require('~/boards/stores/boards_store');
|
2016-12-29 16:42:48 -05:00
|
|
|
require('./mock_data');
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
describe('Store', () => {
|
2016-08-10 08:54:04 -04:00
|
|
|
beforeEach(() => {
|
2016-11-05 06:53:23 -04:00
|
|
|
Vue.http.interceptors.push(boardsMockInterceptor);
|
2017-01-31 11:35:04 -05:00
|
|
|
gl.boardService = new BoardService('/test/issue-boards/board', '', '1');
|
2016-08-15 04:57:01 -04:00
|
|
|
gl.issueBoards.BoardsStore.create();
|
2016-08-10 08:54:04 -04: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
|
|
|
});
|
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(Vue.http.interceptors, boardsMockInterceptor);
|
|
|
|
});
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -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
|
|
|
|
2016-11-05 06:53:23 -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
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);
|
|
|
|
});
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
it('finds list by ID', () => {
|
|
|
|
gl.issueBoards.BoardsStore.addList(listObj);
|
|
|
|
const list = gl.issueBoards.BoardsStore.findList('id', 1);
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
expect(list.id).toBe(1);
|
|
|
|
});
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -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
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
expect(list).toBeDefined();
|
|
|
|
});
|
2016-08-12 11:58:34 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
it('gets issue when new list added', (done) => {
|
|
|
|
gl.issueBoards.BoardsStore.addList(listObj);
|
|
|
|
const list = gl.issueBoards.BoardsStore.findList('id', 1);
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -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
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
it('persists new list', (done) => {
|
|
|
|
gl.issueBoards.BoardsStore.new({
|
|
|
|
title: 'Test',
|
|
|
|
type: 'label',
|
|
|
|
label: {
|
|
|
|
id: 1,
|
|
|
|
title: 'Testing',
|
|
|
|
color: 'red',
|
|
|
|
description: 'testing;'
|
|
|
|
}
|
2016-08-10 08:54:04 -04:00
|
|
|
});
|
2016-11-05 06:53:23 -04:00
|
|
|
expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
const list = gl.issueBoards.BoardsStore.findList('id', 1);
|
|
|
|
expect(list).toBeDefined();
|
|
|
|
expect(list.id).toBe(1);
|
|
|
|
expect(list.position).toBe(0);
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -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
|
|
|
|
2017-01-30 09:11:09 -05:00
|
|
|
it('check for blank state adding when done list exist', () => {
|
2016-11-05 06:53:23 -04:00
|
|
|
gl.issueBoards.BoardsStore.addList({
|
|
|
|
list_type: 'done'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(gl.issueBoards.BoardsStore.shouldAddBlankState()).toBe(true);
|
|
|
|
});
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
it('adds the blank state', () => {
|
|
|
|
gl.issueBoards.BoardsStore.addBlankState();
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
const list = gl.issueBoards.BoardsStore.findList('type', 'blank', 'blank');
|
|
|
|
expect(list).toBeDefined();
|
|
|
|
});
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
it('removes list from state', () => {
|
|
|
|
gl.issueBoards.BoardsStore.addList(listObj);
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
gl.issueBoards.BoardsStore.removeList(1, 'label');
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(0);
|
|
|
|
});
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -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
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(2);
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
gl.issueBoards.BoardsStore.moveList(listOne, ['2', '1']);
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
expect(listOne.position).toBe(1);
|
|
|
|
});
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -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
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(2);
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(listOne.issues.length).toBe(1);
|
|
|
|
expect(listTwo.issues.length).toBe(1);
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
gl.issueBoards.BoardsStore.moveIssueToList(listOne, listTwo, listOne.findIssue(1));
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
expect(listOne.issues.length).toBe(0);
|
|
|
|
expect(listTwo.issues.length).toBe(1);
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
done();
|
|
|
|
}, 0);
|
2016-08-10 08:54:04 -04:00
|
|
|
});
|
|
|
|
});
|
2016-11-05 06:53:23 -04:00
|
|
|
});
|