2016-12-13 22:01:05 -05:00
|
|
|
/* eslint-disable comma-dangle */
|
|
|
|
/* global BoardService */
|
|
|
|
/* global ListIssue */
|
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import '~/lib/utils/url_utility';
|
|
|
|
import '~/boards/models/issue';
|
|
|
|
import '~/boards/models/label';
|
|
|
|
import '~/boards/models/list';
|
|
|
|
import '~/boards/models/assignee';
|
|
|
|
import '~/boards/services/board_service';
|
|
|
|
import '~/boards/stores/boards_store';
|
|
|
|
import './mock_data';
|
2016-08-10 08:54:04 -04:00
|
|
|
|
|
|
|
describe('Issue model', () => {
|
|
|
|
let issue;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-02-01 10:23:01 -05:00
|
|
|
gl.boardService = new BoardService('/test/issue-boards/board', '', '1');
|
2016-08-15 04:57:01 -04:00
|
|
|
gl.issueBoards.BoardsStore.create();
|
2016-08-10 08:54:04 -04:00
|
|
|
|
2016-08-10 13:29:55 -04:00
|
|
|
issue = new ListIssue({
|
2016-08-10 08:54:04 -04:00
|
|
|
title: 'Testing',
|
|
|
|
iid: 1,
|
|
|
|
confidential: false,
|
|
|
|
labels: [{
|
|
|
|
id: 1,
|
|
|
|
title: 'test',
|
|
|
|
color: 'red',
|
|
|
|
description: 'testing'
|
2017-05-04 08:11:15 -04:00
|
|
|
}],
|
|
|
|
assignees: [{
|
|
|
|
id: 1,
|
|
|
|
name: 'name',
|
|
|
|
username: 'username',
|
|
|
|
avatar_url: 'http://avatar_url',
|
|
|
|
}],
|
2016-08-10 08:54:04 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has label', () => {
|
|
|
|
expect(issue.labels.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('add new label', () => {
|
|
|
|
issue.addLabel({
|
|
|
|
id: 2,
|
|
|
|
title: 'bug',
|
|
|
|
color: 'blue',
|
|
|
|
description: 'bugs!'
|
|
|
|
});
|
|
|
|
expect(issue.labels.length).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not add existing label', () => {
|
|
|
|
issue.addLabel({
|
|
|
|
id: 2,
|
|
|
|
title: 'test',
|
|
|
|
color: 'blue',
|
|
|
|
description: 'bugs!'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(issue.labels.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('finds label', () => {
|
|
|
|
const label = issue.findLabel(issue.labels[0]);
|
|
|
|
expect(label).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes label', () => {
|
|
|
|
const label = issue.findLabel(issue.labels[0]);
|
|
|
|
issue.removeLabel(label);
|
|
|
|
expect(issue.labels.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes multiple labels', () => {
|
|
|
|
issue.addLabel({
|
|
|
|
id: 2,
|
|
|
|
title: 'bug',
|
|
|
|
color: 'blue',
|
|
|
|
description: 'bugs!'
|
|
|
|
});
|
|
|
|
expect(issue.labels.length).toBe(2);
|
|
|
|
|
|
|
|
issue.removeLabels([issue.labels[0], issue.labels[1]]);
|
|
|
|
expect(issue.labels.length).toBe(0);
|
|
|
|
});
|
2017-02-14 07:25:45 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
it('adds assignee', () => {
|
|
|
|
issue.addAssignee({
|
|
|
|
id: 2,
|
|
|
|
name: 'Bruce Wayne',
|
|
|
|
username: 'batman',
|
|
|
|
avatar_url: 'http://batman',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(issue.assignees.length).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('finds assignee', () => {
|
|
|
|
const assignee = issue.findAssignee(issue.assignees[0]);
|
|
|
|
expect(assignee).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes assignee', () => {
|
|
|
|
const assignee = issue.findAssignee(issue.assignees[0]);
|
|
|
|
issue.removeAssignee(assignee);
|
|
|
|
expect(issue.assignees.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes all assignees', () => {
|
|
|
|
issue.removeAllAssignees();
|
|
|
|
expect(issue.assignees.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
2017-02-14 07:25:45 -05:00
|
|
|
it('sets position to infinity if no position is stored', () => {
|
|
|
|
expect(issue.position).toBe(Infinity);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets position', () => {
|
|
|
|
const relativePositionIssue = new ListIssue({
|
|
|
|
title: 'Testing',
|
|
|
|
iid: 1,
|
|
|
|
confidential: false,
|
|
|
|
relative_position: 1,
|
2017-05-04 08:11:15 -04:00
|
|
|
labels: [],
|
|
|
|
assignees: [],
|
2017-02-14 07:25:45 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(relativePositionIssue.position).toBe(1);
|
|
|
|
});
|
2017-05-04 08:11:15 -04:00
|
|
|
|
|
|
|
describe('update', () => {
|
|
|
|
it('passes assignee ids when there are assignees', (done) => {
|
|
|
|
spyOn(Vue.http, 'patch').and.callFake((url, data) => {
|
|
|
|
expect(data.issue.assignee_ids).toEqual([1]);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
issue.update('url');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes assignee ids of [0] when there are no assignees', (done) => {
|
|
|
|
spyOn(Vue.http, 'patch').and.callFake((url, data) => {
|
|
|
|
expect(data.issue.assignee_ids).toEqual([0]);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
issue.removeAllAssignees();
|
|
|
|
issue.update('url');
|
|
|
|
});
|
|
|
|
});
|
2016-08-10 08:54:04 -04:00
|
|
|
});
|