BigW Consortium Gitlab

list_spec.js.es6 2.04 KB
Newer Older
1 2 3 4 5 6 7
/* eslint-disable comma-dangle */
/* global Vue */
/* global boardsMockInterceptor */
/* global BoardService */
/* global List */
/* global listObj */

8 9 10 11 12 13 14
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');
15
require('./mock_data');
16 17 18 19 20

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

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

    list = new List(listObj);
  });

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

32 33 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
  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) => {
59 60 61
    gl.issueBoards.BoardsStore.addList(listObj);
    list = gl.issueBoards.BoardsStore.findList('id', 1);
    expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);
62 63 64
    list.destroy();

    setTimeout(() => {
65
      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(0);
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
      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);
  });
});