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

211 lines
4.8 KiB
JavaScript
Raw Normal View History

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