BigW Consortium Gitlab

issue_spec.js 3.84 KB
Newer Older
1 2 3
/* eslint-disable comma-dangle */
/* global BoardService */
/* global ListIssue */
Simon Knox committed
4
/* global mockBoardService */
5

6 7 8 9 10 11 12 13 14
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';
15 16 17 18 19

describe('Issue model', () => {
  let issue;

  beforeEach(() => {
Simon Knox committed
20
    gl.boardService = mockBoardService();
21
    gl.issueBoards.BoardsStore.create();
22

23
    issue = new ListIssue({
24
      title: 'Testing',
Simon Knox committed
25
      id: 1,
26 27 28 29 30 31 32
      iid: 1,
      confidential: false,
      labels: [{
        id: 1,
        title: 'test',
        color: 'red',
        description: 'testing'
33 34 35 36 37 38 39
      }],
      assignees: [{
        id: 1,
        name: 'name',
        username: 'username',
        avatar_url: 'http://avatar_url',
      }],
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    });
  });

  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);
  });
Phil Hughes committed
91

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
  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);
  });

Phil Hughes committed
119 120 121 122 123 124 125 126 127 128
  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,
129 130
      labels: [],
      assignees: [],
Phil Hughes committed
131 132 133 134
    });

    expect(relativePositionIssue.position).toBe(1);
  });
135

136 137 138 139 140 141 142 143 144 145 146 147 148
  it('updates data', () => {
    issue.updateData({ subscribed: true });
    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);
  });

149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
  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');
    });
  });
169
});