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

232 lines
5.9 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* global List */
2019-12-04 20:38:33 +05:30
/* global ListAssignee */
2017-08-17 22:00:37 +05:30
/* global ListIssue */
2019-12-04 20:38:33 +05:30
/* global ListLabel */
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
import MockAdapter from 'axios-mock-adapter';
2020-01-01 13:55:28 +05:30
import axios from '~/lib/utils/axios_utils';
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';
2020-04-22 19:07:51 +05:30
import { ListType } from '~/boards/constants';
2018-12-13 13:39:08 +05:30
import boardsStore from '~/boards/stores/boards_store';
2020-04-22 19:07:51 +05:30
import waitForPromises from 'helpers/wait_for_promises';
2020-01-01 13:55:28 +05:30
import { listObj, listObjDuplicate, boardsMockInterceptor } 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);
2018-12-13 13:39:08 +05:30
boardsStore.create();
2020-04-22 19:07:51 +05:30
boardsStore.setEndpoints({
listsEndpoint: '/test/-/boards/1/lists',
});
2017-08-17 22:00:37 +05:30
list = new List(listObj);
2020-04-22 19:07:51 +05:30
return waitForPromises();
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
});
2020-04-22 19:07:51 +05:30
describe('list type', () => {
const notExpandableList = ['blank'];
const table = Object.keys(ListType).map(k => {
const value = ListType[k];
return [value, !notExpandableList.includes(value)];
});
it.each(table)(`when list_type is %s boards isExpandable is %p`, (type, result) => {
expect(new List({ id: 1, list_type: type }).isExpandable).toBe(result);
});
2017-08-17 22:00:37 +05:30
});
2020-04-22 19:07:51 +05:30
it('gets issues when created', () => {
expect(list.issues.length).toBe(1);
});
it('saves list and returns ID', () => {
2017-08-17 22:00:37 +05:30
list = new List({
title: 'test',
label: {
2020-04-08 14:13:33 +05:30
id: 1,
2017-08-17 22:00:37 +05:30
title: 'test',
2020-04-22 19:07:51 +05:30
color: '#ff0000',
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
});
2020-04-22 19:07:51 +05:30
return list.save().then(() => {
2017-08-17 22:00:37 +05:30
expect(list.id).toBe(listObj.id);
expect(list.type).toBe('label');
expect(list.position).toBe(0);
2020-04-22 19:07:51 +05:30
expect(list.label).toEqual(listObj.label);
});
2017-08-17 22:00:37 +05:30
});
2020-04-22 19:07:51 +05:30
it('destroys the list', () => {
2018-12-13 13:39:08 +05:30
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();
2020-04-22 19:07:51 +05:30
return waitForPromises().then(() => {
2018-12-13 13:39:08 +05:30
expect(boardsStore.state.lists.length).toBe(0);
2020-04-22 19:07:51 +05:30
});
2017-08-17 22:00:37 +05:30
});
2020-04-22 19:07:51 +05:30
it('gets issue from list', () => {
const issue = list.findIssue(1);
2018-12-13 13:39:08 +05:30
2020-04-22 19:07:51 +05:30
expect(issue).toBeDefined();
2017-08-17 22:00:37 +05:30
});
2020-04-22 19:07:51 +05:30
it('removes issue', () => {
const issue = list.findIssue(1);
2018-12-13 13:39:08 +05:30
2020-04-22 19:07:51 +05:30
expect(list.issues.length).toBe(1);
list.removeIssue(issue);
2018-12-13 13:39:08 +05:30
2020-04-22 19:07:51 +05:30
expect(list.issues.length).toBe(0);
2017-08-17 22:00:37 +05:30
});
it('sends service request to update issue label', () => {
const listDup = new List(listObjDuplicate);
const issue = new ListIssue({
title: 'Testing',
2020-04-08 14:13:33 +05:30
id: 1,
iid: 1,
2017-08-17 22:00:37 +05:30
confidential: false,
labels: [list.label, listDup.label],
assignees: [],
});
list.issues.push(issue);
listDup.issues.push(issue);
2020-04-22 19:07:51 +05:30
jest.spyOn(boardsStore, 'moveIssue');
2017-08-17 22:00:37 +05:30
listDup.updateIssueLabel(issue, list);
2020-01-01 13:55:28 +05:30
expect(boardsStore.moveIssue).toHaveBeenCalledWith(
2018-12-13 13:39:08 +05:30
issue.id,
list.id,
listDup.id,
undefined,
undefined,
);
2017-08-17 22:00:37 +05:30
});
describe('page number', () => {
beforeEach(() => {
2020-04-22 19:07:51 +05:30
jest.spyOn(list, 'getIssues').mockImplementation(() => {});
list.issues = [];
2017-08-17 22:00:37 +05:30
});
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',
2020-04-08 14:13:33 +05:30
id: i,
iid: i,
2018-12-13 13:39:08 +05:30
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',
2020-04-08 14:13:33 +05:30
id: 1,
2018-12-13 13:39:08 +05:30
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(() => {
2020-04-22 19:07:51 +05:30
jest.spyOn(boardsStore, 'newIssue').mockReturnValue(
2018-12-13 13:39:08 +05:30
Promise.resolve({
data: {
id: 42,
2019-12-04 20:38:33 +05:30
subscribed: false,
assignable_labels_endpoint: '/issue/42/labels',
toggle_subscription_endpoint: '/issue/42/subscriptions',
issue_sidebar_endpoint: '/issue/42/sidebar_info',
2018-12-13 13:39:08 +05:30
},
}),
);
2020-04-22 19:07:51 +05:30
list.issues = [];
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 => {
2019-12-04 20:38:33 +05:30
const user = new ListAssignee({
id: 1,
name: 'testing 123',
username: 'test',
avatar: 'test_image',
});
2018-12-13 13:39:08 +05:30
list.issues.push(
new ListIssue({
title: 'Testing',
2020-04-08 14:13:33 +05:30
id: 1,
2018-12-13 13:39:08 +05:30
confidential: false,
2019-12-04 20:38:33 +05:30
labels: [new ListLabel(list.label)],
2018-12-13 13:39:08 +05:30
assignees: [],
}),
);
2017-09-10 17:25:29 +05:30
const dummyIssue = new ListIssue({
title: 'new issue',
2020-04-08 14:13:33 +05:30
id: 2,
2017-09-10 17:25:29 +05:30
confidential: false,
2019-12-04 20:38:33 +05:30
labels: [new ListLabel(list.label)],
assignees: [user],
subscribed: false,
2017-09-10 17:25:29 +05:30
});
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);
2019-12-04 20:38:33 +05:30
expect(list.issues[0].subscribed).toBe(false);
expect(list.issues[0].assignableLabelsEndpoint).toBe('/issue/42/labels');
expect(list.issues[0].toggleSubscriptionEndpoint).toBe('/issue/42/subscriptions');
expect(list.issues[0].sidebarInfoEndpoint).toBe('/issue/42/sidebar_info');
expect(list.issues[0].labels).toBe(dummyIssue.labels);
expect(list.issues[0].assignees).toBe(dummyIssue.assignees);
2017-09-10 17:25:29 +05:30
})
.then(done)
.catch(done.fail);
});
});
2017-08-17 22:00:37 +05:30
});