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

226 lines
5.4 KiB
JavaScript
Raw Normal View History

/* global List */
/* global ListAssignee */
/* global ListIssue */
/* global ListLabel */
2017-12-15 03:31:14 -05:00
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import '~/boards/models/label';
import '~/boards/models/assignee';
import '~/boards/models/issue';
import '~/boards/models/list';
import boardsStore from '~/boards/stores/boards_store';
import { listObj, listObjDuplicate, boardsMockInterceptor } 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);
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: 1,
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',
id: 1,
iid: 1,
confidential: false,
labels: [list.label, listDup.label],
assignees: [],
});
list.issues.push(issue);
listDup.issues.push(issue);
spyOn(boardsStore, 'moveIssue').and.callThrough();
listDup.updateIssueLabel(issue, list);
expect(boardsStore.moveIssue).toHaveBeenCalledWith(
2018-10-17 03:13:26 -04:00
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: i,
iid: i,
2018-10-17 03:13:26 -04:00
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: 1,
2018-10-17 03:13:26 -04:00
confidential: false,
labels: [list.label],
assignees: [],
}),
);
list.issuesSize = 2;
list.nextPage();
expect(list.page).toBe(1);
expect(list.getIssues).toHaveBeenCalled();
});
});
describe('newIssue', () => {
beforeEach(() => {
spyOn(boardsStore, 'newIssue').and.returnValue(
2018-10-17 03:13:26 -04:00
Promise.resolve({
data: {
id: 42,
subscribed: false,
assignable_labels_endpoint: '/issue/42/labels',
toggle_subscription_endpoint: '/issue/42/subscriptions',
issue_sidebar_endpoint: '/issue/42/sidebar_info',
2018-10-17 03:13:26 -04:00
},
}),
);
});
2018-10-17 03:13:26 -04:00
it('adds new issue to top of list', done => {
const user = new ListAssignee({
id: 1,
name: 'testing 123',
username: 'test',
avatar: 'test_image',
});
2018-10-17 03:13:26 -04:00
list.issues.push(
new ListIssue({
title: 'Testing',
id: 1,
2018-10-17 03:13:26 -04:00
confidential: false,
labels: [new ListLabel(list.label)],
2018-10-17 03:13:26 -04:00
assignees: [],
}),
);
const dummyIssue = new ListIssue({
title: 'new issue',
id: 2,
confidential: false,
labels: [new ListLabel(list.label)],
assignees: [user],
subscribed: false,
});
2018-10-17 03:13:26 -04:00
list
.newIssue(dummyIssue)
.then(() => {
expect(list.issues.length).toBe(2);
expect(list.issues[0]).toBe(dummyIssue);
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);
})
.then(done)
.catch(done.fail);
});
});
2016-08-10 08:54:04 -04:00
});