debian-mirror-gitlab/spec/javascripts/boards/boards_store_spec.js

380 lines
10 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* global ListIssue */
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';
2019-09-04 21:01:54 +05:30
import '~/boards/models/label';
import '~/boards/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';
2019-09-04 21:01:54 +05:30
import eventHub from '~/boards/eventhub';
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
});
2019-09-04 21:01:54 +05:30
describe('addList', () => {
it('sorts by position', () => {
boardsStore.addList({ position: 2 });
boardsStore.addList({ position: 1 });
expect(boardsStore.state.lists[0].position).toBe(1);
});
});
describe('toggleFilter', () => {
const dummyFilter = 'x=42';
let updateTokensSpy;
beforeEach(() => {
updateTokensSpy = jasmine.createSpy('updateTokens');
eventHub.$once('updateTokens', updateTokensSpy);
// prevent using window.history
spyOn(boardsStore, 'updateFiltersUrl').and.callFake(() => {});
});
it('adds the filter if it is not present', () => {
boardsStore.filter.path = 'something';
boardsStore.toggleFilter(dummyFilter);
expect(boardsStore.filter.path).toEqual(`something&${dummyFilter}`);
expect(updateTokensSpy).toHaveBeenCalled();
expect(boardsStore.updateFiltersUrl).toHaveBeenCalled();
});
it('removes the filter if it is present', () => {
boardsStore.filter.path = `something&${dummyFilter}`;
boardsStore.toggleFilter(dummyFilter);
expect(boardsStore.filter.path).toEqual('something');
expect(updateTokensSpy).toHaveBeenCalled();
expect(boardsStore.updateFiltersUrl).toHaveBeenCalled();
});
});
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);
2019-12-04 20:38:33 +05:30
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();
});
});
});
2019-09-04 21:01:54 +05:30
describe('setListDetail', () => {
it('sets the list detail', () => {
boardsStore.detail.list = 'not a list';
const dummyValue = 'new list';
boardsStore.setListDetail(dummyValue);
expect(boardsStore.detail.list).toEqual(dummyValue);
});
});
describe('clearDetailIssue', () => {
it('resets issue details', () => {
boardsStore.detail.issue = 'something';
boardsStore.clearDetailIssue();
expect(boardsStore.detail.issue).toEqual({});
});
});
describe('setIssueDetail', () => {
it('sets issue details', () => {
boardsStore.detail.issue = 'some details';
const dummyValue = 'new details';
boardsStore.setIssueDetail(dummyValue);
expect(boardsStore.detail.issue).toEqual(dummyValue);
});
});
describe('startMoving', () => {
it('stores list and issue', () => {
const dummyIssue = 'some issue';
const dummyList = 'some list';
boardsStore.startMoving(dummyList, dummyIssue);
expect(boardsStore.moving.issue).toEqual(dummyIssue);
expect(boardsStore.moving.list).toEqual(dummyList);
});
});
2019-09-30 21:07:59 +05:30
describe('setTimeTrackingLimitToHours', () => {
it('sets the timeTracking.LimitToHours option', () => {
boardsStore.timeTracking.limitToHours = false;
boardsStore.setTimeTrackingLimitToHours('true');
expect(boardsStore.timeTracking.limitToHours).toEqual(true);
});
});
describe('setCurrentBoard', () => {
const dummyBoard = 'hoverboard';
it('sets the current board', () => {
const { state } = boardsStore;
state.currentBoard = null;
boardsStore.setCurrentBoard(dummyBoard);
expect(state.currentBoard).toEqual(dummyBoard);
});
});
2017-08-17 22:00:37 +05:30
});