gitlab-org--gitlab-foss/spec/frontend/boards/issue_spec.js

184 lines
3.8 KiB
JavaScript
Raw Normal View History

/* global ListIssue */
import '~/boards/models/label';
import '~/boards/models/assignee';
import '~/boards/models/issue';
import '~/boards/models/list';
import boardsStore from '~/boards/stores/boards_store';
import { setMockEndpoints } from './mock_data';
2016-08-10 08:54:04 -04:00
describe('Issue model', () => {
let issue;
beforeEach(() => {
setMockEndpoints();
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',
2017-09-06 02:49:19 -04:00
id: 1,
2016-08-10 08:54:04 -04:00
iid: 1,
confidential: false,
2018-10-17 03:13:26 -04:00
labels: [
{
id: 1,
title: 'test',
color: 'red',
description: 'testing',
},
],
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',
2018-10-17 03:13:26 -04:00
description: 'bugs!',
2016-08-10 08:54:04 -04:00
});
2018-10-09 14:03:09 -04:00
2016-08-10 08:54:04 -04:00
expect(issue.labels.length).toBe(2);
});
2018-11-21 11:04:28 -05:00
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', () => {
2016-08-10 08:54:04 -04:00
issue.addLabel({
id: 2,
title: 'test',
color: 'blue',
2018-11-21 11:04:28 -05:00
description: 'other test',
2016-08-10 08:54:04 -04:00
});
2018-11-21 11:04:28 -05:00
expect(issue.labels.length).toBe(2);
2016-08-10 08:54:04 -04:00
});
it('finds label', () => {
const label = issue.findLabel(issue.labels[0]);
2018-10-09 14:03:09 -04:00
2016-08-10 08:54:04 -04:00
expect(label).toBeDefined();
});
it('removes label', () => {
const label = issue.findLabel(issue.labels[0]);
issue.removeLabel(label);
2018-10-09 14:03:09 -04:00
2016-08-10 08:54:04 -04:00
expect(issue.labels.length).toBe(0);
});
it('removes multiple labels', () => {
issue.addLabel({
id: 2,
title: 'bug',
color: 'blue',
2018-10-17 03:13:26 -04:00
description: 'bugs!',
2016-08-10 08:54:04 -04:00
});
2018-10-09 14:03:09 -04:00
2016-08-10 08:54:04 -04:00
expect(issue.labels.length).toBe(2);
issue.removeLabels([issue.labels[0], issue.labels[1]]);
2018-10-09 14:03:09 -04:00
2016-08-10 08:54:04 -04:00
expect(issue.labels.length).toBe(0);
});
2017-02-14 07:25:45 -05: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]);
2018-10-09 14:03:09 -04:00
expect(assignee).toBeDefined();
});
it('removes assignee', () => {
const assignee = issue.findAssignee(issue.assignees[0]);
issue.removeAssignee(assignee);
2018-10-09 14:03:09 -04:00
expect(issue.assignees.length).toBe(0);
});
it('removes all assignees', () => {
issue.removeAllAssignees();
2018-10-09 14:03:09 -04:00
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,
labels: [],
assignees: [],
2017-02-14 07:25:45 -05:00
});
expect(relativePositionIssue.position).toBe(1);
});
it('updates data', () => {
issue.updateData({ subscribed: true });
2018-10-09 14:03:09 -04:00
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);
});
describe('update', () => {
it('passes update to boardsStore', () => {
jest.spyOn(boardsStore, 'updateIssue').mockImplementation();
issue.update();
expect(boardsStore.updateIssue).toHaveBeenCalledWith(issue);
});
});
2016-08-10 08:54:04 -04:00
});