list_spec.js 2.61 KB
Newer Older
1 2 3 4 5
/* eslint-disable comma-dangle */
/* global Vue */
/* global boardsMockInterceptor */
/* global BoardService */
/* global List */
6
/* global ListIssue */
7
/* global listObj */
8
/* global listObjDuplicate */
9

10 11 12 13 14 15 16
require('~/lib/utils/url_utility');
require('~/boards/models/issue');
require('~/boards/models/label');
require('~/boards/models/list');
require('~/boards/models/user');
require('~/boards/services/board_service');
require('~/boards/stores/boards_store');
17
require('./mock_data');
18 19 20 21 22

describe('List model', () => {
  let list;

  beforeEach(() => {
23
    Vue.http.interceptors.push(boardsMockInterceptor);
24
    gl.boardService = new BoardService('/test/issue-boards/board', '', '1');
25
    gl.issueBoards.BoardsStore.create();
26 27 28 29

    list = new List(listObj);
  });

30 31 32 33
  afterEach(() => {
    Vue.http.interceptors = _.without(Vue.http.interceptors, boardsMockInterceptor);
  });

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
  it('gets issues when created', (done) => {
    setTimeout(() => {
      expect(list.issues.length).toBe(1);
      done();
    }, 0);
  });

  it('saves list and returns ID', (done) => {
    list = new List({
      title: 'test',
      label: {
        id: 1,
        title: 'test',
        color: 'red'
      }
    });
    list.save();

    setTimeout(() => {
      expect(list.id).toBe(1);
      expect(list.type).toBe('label');
      expect(list.position).toBe(0);
      done();
    }, 0);
  });

  it('destroys the list', (done) => {
61 62 63
    gl.issueBoards.BoardsStore.addList(listObj);
    list = gl.issueBoards.BoardsStore.findList('id', 1);
    expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);
64 65 66
    list.destroy();

    setTimeout(() => {
67
      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(0);
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
      done();
    }, 0);
  });

  it('gets issue from list', (done) => {
    setTimeout(() => {
      const issue = list.findIssue(1);
      expect(issue).toBeDefined();
      done();
    }, 0);
  });

  it('removes issue', (done) => {
    setTimeout(() => {
      const issue = list.findIssue(1);
      expect(list.issues.length).toBe(1);
      list.removeIssue(issue);
      expect(list.issues.length).toBe(0);
      done();
    }, 0);
  });
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

  it('sends service request to update issue label', () => {
    const listDup = new List(listObjDuplicate);
    const issue = new ListIssue({
      title: 'Testing',
      iid: 1,
      confidential: false,
      labels: [list.label, listDup.label]
    });

    list.issues.push(issue);
    listDup.issues.push(issue);

    spyOn(gl.boardService, 'moveIssue').and.callThrough();

    listDup.updateIssueLabel(list, issue);

    expect(gl.boardService.moveIssue).toHaveBeenCalledWith(issue.id, list.id, listDup.id);
  });
108
});