2016-12-13 22:01:05 -05:00
|
|
|
/* global List */
|
2017-02-21 11:00:33 -05:00
|
|
|
/* global ListIssue */
|
2016-12-13 22:01:05 -05:00
|
|
|
|
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';
|
2018-06-07 16:54:24 -04:00
|
|
|
import '~/vue_shared/models/assignee';
|
2017-05-04 08:11:15 -04:00
|
|
|
import '~/boards/models/issue';
|
|
|
|
import '~/boards/models/list';
|
|
|
|
import '~/boards/services/board_service';
|
2018-10-10 13:08:43 -04:00
|
|
|
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',
|
|
|
|
});
|
2018-10-10 13:08:43 -04:00
|
|
|
boardsStore.create();
|
2016-08-10 08:54:04 -04:00
|
|
|
|
|
|
|
list = new List(listObj);
|
|
|
|
});
|
|
|
|
|
2016-11-05 06:53:23 -04:00
|
|
|
afterEach(() => {
|
2018-01-23 06:42:02 -05:00
|
|
|
mock.restore();
|
2016-11-05 06:53:23 -04:00
|
|
|
});
|
|
|
|
|
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: {
|
2017-03-24 09:13:44 -04:00
|
|
|
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(() => {
|
2017-03-24 09:13:44 -04:00
|
|
|
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 => {
|
2018-10-10 13:08:43 -04:00
|
|
|
boardsStore.addList(listObj);
|
|
|
|
list = boardsStore.findList('id', listObj.id);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-10-10 13:08:43 -04:00
|
|
|
expect(boardsStore.state.lists.length).toBe(1);
|
2016-08-10 08:54:04 -04:00
|
|
|
list.destroy();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-10-10 13:08:43 -04:00
|
|
|
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);
|
|
|
|
});
|
2017-02-21 11:00:33 -05:00
|
|
|
|
|
|
|
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),
|
2017-03-24 09:13:44 -04:00
|
|
|
iid: _.random(10000),
|
2017-02-21 11:00:33 -05:00
|
|
|
confidential: false,
|
2017-05-04 08:11:15 -04:00
|
|
|
labels: [list.label, listDup.label],
|
|
|
|
assignees: [],
|
2017-02-21 11:00:33 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
list.issues.push(issue);
|
|
|
|
listDup.issues.push(issue);
|
|
|
|
|
|
|
|
spyOn(gl.boardService, 'moveIssue').and.callThrough();
|
|
|
|
|
2017-03-24 09:13:44 -04:00
|
|
|
listDup.updateIssueLabel(issue, list);
|
2017-02-21 11:00:33 -05:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(gl.boardService.moveIssue).toHaveBeenCalledWith(
|
|
|
|
issue.id,
|
|
|
|
list.id,
|
|
|
|
listDup.id,
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
);
|
2017-02-21 11:00:33 -05:00
|
|
|
});
|
2017-04-13 11:33:19 -04:00
|
|
|
|
|
|
|
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: [],
|
|
|
|
}),
|
|
|
|
);
|
2017-04-13 11:33:19 -04:00
|
|
|
}
|
|
|
|
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: [],
|
|
|
|
}),
|
|
|
|
);
|
2017-04-13 11:33:19 -04:00
|
|
|
list.issuesSize = 2;
|
|
|
|
|
|
|
|
list.nextPage();
|
|
|
|
|
|
|
|
expect(list.page).toBe(1);
|
|
|
|
expect(list.getIssues).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2017-06-23 05:28:19 -04:00
|
|
|
|
|
|
|
describe('newIssue', () => {
|
|
|
|
beforeEach(() => {
|
2018-10-17 03:13:26 -04:00
|
|
|
spyOn(gl.boardService, 'newIssue').and.returnValue(
|
|
|
|
Promise.resolve({
|
|
|
|
data: {
|
|
|
|
id: 42,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2017-06-23 05:28:19 -04:00
|
|
|
});
|
|
|
|
|
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: [],
|
|
|
|
}),
|
|
|
|
);
|
2017-06-23 05:28:19 -04:00
|
|
|
const dummyIssue = new ListIssue({
|
|
|
|
title: 'new issue',
|
2017-09-06 02:49:19 -04:00
|
|
|
id: _.random(10000),
|
2017-06-23 05:28:19 -04:00
|
|
|
confidential: false,
|
|
|
|
labels: [list.label],
|
|
|
|
assignees: [],
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
list
|
|
|
|
.newIssue(dummyIssue)
|
2017-06-23 05:28:19 -04:00
|
|
|
.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
|
|
|
});
|