2017-08-17 22:00:37 +05:30
|
|
|
/* global ListIssue */
|
|
|
|
|
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';
|
2018-12-13 13:39:08 +05:30
|
|
|
import boardsStore from '~/boards/stores/boards_store';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { setMockEndpoints, mockIssue } from './mock_data';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe('Issue model', () => {
|
|
|
|
let issue;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-01-01 13:55:28 +05:30
|
|
|
setMockEndpoints();
|
2018-12-13 13:39:08 +05:30
|
|
|
boardsStore.create();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
issue = new ListIssue(mockIssue);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('has label', () => {
|
|
|
|
expect(issue.labels.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('add new label', () => {
|
|
|
|
issue.addLabel({
|
|
|
|
id: 2,
|
|
|
|
title: 'bug',
|
|
|
|
color: 'blue',
|
2018-12-13 13:39:08 +05:30
|
|
|
description: 'bugs!',
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(issue.labels.length).toBe(2);
|
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
it('does not add label if label id exists', () => {
|
|
|
|
issue.addLabel({
|
|
|
|
id: 1,
|
|
|
|
title: 'test 2',
|
|
|
|
color: 'blue',
|
|
|
|
description: 'testing',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(issue.labels.length).toBe(1);
|
|
|
|
expect(issue.labels[0].color).toBe('red');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds other label with same title', () => {
|
2017-08-17 22:00:37 +05:30
|
|
|
issue.addLabel({
|
|
|
|
id: 2,
|
|
|
|
title: 'test',
|
|
|
|
color: 'blue',
|
2019-02-15 15:39:39 +05:30
|
|
|
description: 'other test',
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(issue.labels.length).toBe(2);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('finds label', () => {
|
|
|
|
const label = issue.findLabel(issue.labels[0]);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(label).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes label', () => {
|
|
|
|
const label = issue.findLabel(issue.labels[0]);
|
|
|
|
issue.removeLabel(label);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(issue.labels.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes multiple labels', () => {
|
|
|
|
issue.addLabel({
|
|
|
|
id: 2,
|
|
|
|
title: 'bug',
|
|
|
|
color: 'blue',
|
2018-12-13 13:39:08 +05:30
|
|
|
description: 'bugs!',
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(issue.labels.length).toBe(2);
|
|
|
|
|
|
|
|
issue.removeLabels([issue.labels[0], issue.labels[1]]);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(issue.labels.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
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]);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(assignee).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes assignee', () => {
|
|
|
|
const assignee = issue.findAssignee(issue.assignees[0]);
|
|
|
|
issue.removeAssignee(assignee);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(issue.assignees.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes all assignees', () => {
|
|
|
|
issue.removeAllAssignees();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(issue.assignees.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
|
|
|
labels: [],
|
|
|
|
assignees: [],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(relativePositionIssue.position).toBe(1);
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('updates data', () => {
|
|
|
|
issue.updateData({ subscribed: true });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(issue.subscribed).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets fetching state', () => {
|
|
|
|
expect(issue.isFetching.subscriptions).toBe(true);
|
|
|
|
|
|
|
|
issue.setFetchingState('subscriptions', false);
|
|
|
|
|
|
|
|
expect(issue.isFetching.subscriptions).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets loading state', () => {
|
|
|
|
issue.setLoadingState('foo', true);
|
|
|
|
|
|
|
|
expect(issue.isLoading.foo).toBe(true);
|
|
|
|
});
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe('update', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
it('passes update to boardsStore', () => {
|
|
|
|
jest.spyOn(boardsStore, 'updateIssue').mockImplementation();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
issue.update();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(boardsStore.updateIssue).toHaveBeenCalledWith(issue);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|