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

211 lines
4.8 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* global List */
/* global ListIssue */
2018-03-17 18:26:18 +05:30
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import _ from 'underscore';
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';
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('List model', () => {
let list;
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({
bulkUpdatePath: '/test/issue-boards/board/1/lists',
});
2018-12-13 13:39:08 +05:30
boardsStore.create();
2017-08-17 22:00:37 +05:30
list = new List(listObj);
});
afterEach(() => {
2018-03-17 18:26:18 +05:30
mock.restore();
2017-08-17 22:00:37 +05:30
});
2018-12-13 13:39:08 +05:30
it('gets issues when created', done => {
2017-08-17 22:00:37 +05:30
setTimeout(() => {
expect(list.issues.length).toBe(1);
done();
}, 0);
});
2018-12-13 13:39:08 +05:30
it('saves list and returns ID', done => {
2017-08-17 22:00:37 +05:30
list = new List({
title: 'test',
label: {
id: _.random(10000),
title: 'test',
2018-12-13 13:39:08 +05:30
color: 'red',
2019-07-31 22:56:46 +05:30
text_color: 'white',
2018-12-13 13:39:08 +05:30
},
2017-08-17 22:00:37 +05:30
});
list.save();
setTimeout(() => {
expect(list.id).toBe(listObj.id);
expect(list.type).toBe('label');
expect(list.position).toBe(0);
2019-07-31 22:56:46 +05:30
expect(list.label.color).toBe('red');
expect(list.label.textColor).toBe('white');
2017-08-17 22:00:37 +05:30
done();
}, 0);
});
2018-12-13 13:39:08 +05:30
it('destroys the list', done => {
boardsStore.addList(listObj);
list = boardsStore.findList('id', listObj.id);
expect(boardsStore.state.lists.length).toBe(1);
2017-08-17 22:00:37 +05:30
list.destroy();
setTimeout(() => {
2018-12-13 13:39:08 +05:30
expect(boardsStore.state.lists.length).toBe(0);
2017-08-17 22:00:37 +05:30
done();
}, 0);
});
2018-12-13 13:39:08 +05:30
it('gets issue from list', done => {
2017-08-17 22:00:37 +05:30
setTimeout(() => {
const issue = list.findIssue(1);
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(issue).toBeDefined();
done();
}, 0);
});
2018-12-13 13:39:08 +05:30
it('removes issue', done => {
2017-08-17 22:00:37 +05:30
setTimeout(() => {
const issue = list.findIssue(1);
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(list.issues.length).toBe(1);
list.removeIssue(issue);
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(list.issues.length).toBe(0);
done();
}, 0);
});
it('sends service request to update issue label', () => {
const listDup = new List(listObjDuplicate);
const issue = new ListIssue({
title: 'Testing',
2018-03-17 18:26:18 +05:30
id: _.random(10000),
2017-08-17 22:00:37 +05:30
iid: _.random(10000),
confidential: false,
labels: [list.label, listDup.label],
assignees: [],
});
list.issues.push(issue);
listDup.issues.push(issue);
spyOn(gl.boardService, 'moveIssue').and.callThrough();
listDup.updateIssueLabel(issue, list);
2018-12-13 13:39:08 +05:30
expect(gl.boardService.moveIssue).toHaveBeenCalledWith(
issue.id,
list.id,
listDup.id,
undefined,
undefined,
);
2017-08-17 22:00:37 +05:30
});
describe('page number', () => {
beforeEach(() => {
spyOn(list, 'getIssues');
});
it('increase page number if current issue count is more than the page size', () => {
for (let i = 0; i < 30; i += 1) {
2018-12-13 13:39:08 +05:30
list.issues.push(
new ListIssue({
title: 'Testing',
id: _.random(10000) + i,
iid: _.random(10000) + i,
confidential: false,
labels: [list.label],
assignees: [],
}),
);
2017-08-17 22:00:37 +05:30
}
list.issuesSize = 50;
expect(list.issues.length).toBe(30);
list.nextPage();
expect(list.page).toBe(2);
expect(list.getIssues).toHaveBeenCalled();
});
it('does not increase page number if issue count is less than the page size', () => {
2018-12-13 13:39:08 +05:30
list.issues.push(
new ListIssue({
title: 'Testing',
id: _.random(10000),
confidential: false,
labels: [list.label],
assignees: [],
}),
);
2017-08-17 22:00:37 +05:30
list.issuesSize = 2;
list.nextPage();
expect(list.page).toBe(1);
expect(list.getIssues).toHaveBeenCalled();
});
});
2017-09-10 17:25:29 +05:30
describe('newIssue', () => {
beforeEach(() => {
2018-12-13 13:39:08 +05:30
spyOn(gl.boardService, 'newIssue').and.returnValue(
Promise.resolve({
data: {
id: 42,
},
}),
);
2017-09-10 17:25:29 +05:30
});
2018-12-13 13:39:08 +05:30
it('adds new issue to top of list', done => {
list.issues.push(
new ListIssue({
title: 'Testing',
id: _.random(10000),
confidential: false,
labels: [list.label],
assignees: [],
}),
);
2017-09-10 17:25:29 +05:30
const dummyIssue = new ListIssue({
title: 'new issue',
2018-03-17 18:26:18 +05:30
id: _.random(10000),
2017-09-10 17:25:29 +05:30
confidential: false,
labels: [list.label],
assignees: [],
});
2018-12-13 13:39:08 +05:30
list
.newIssue(dummyIssue)
2017-09-10 17:25:29 +05:30
.then(() => {
expect(list.issues.length).toBe(2);
expect(list.issues[0]).toBe(dummyIssue);
})
.then(done)
.catch(done.fail);
});
});
2017-08-17 22:00:37 +05:30
});