BigW Consortium Gitlab

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

9 10
import Vue from 'vue';

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

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

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

    list = new List(listObj);
  });

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

35 36 37 38 39 40 41 42 43 44 45
  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: {
46
        id: _.random(10000),
47 48 49 50 51 52 53
        title: 'test',
        color: 'red'
      }
    });
    list.save();

    setTimeout(() => {
54
      expect(list.id).toBe(listObj.id);
55 56 57 58 59 60 61
      expect(list.type).toBe('label');
      expect(list.position).toBe(0);
      done();
    }, 0);
  });

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

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

  it('sends service request to update issue label', () => {
    const listDup = new List(listObjDuplicate);
    const issue = new ListIssue({
      title: 'Testing',
95
      iid: _.random(10000),
96 97 98 99 100 101 102 103 104
      confidential: false,
      labels: [list.label, listDup.label]
    });

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

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

105
    listDup.updateIssueLabel(issue, list);
106

Phil Hughes committed
107 108
    expect(gl.boardService.moveIssue)
      .toHaveBeenCalledWith(issue.id, list.id, listDup.id, undefined, undefined);
109
  });
110 111 112 113 114 115 116

  describe('page number', () => {
    beforeEach(() => {
      spyOn(list, 'getIssues');
    });

    it('increase page number if current issue count is more than the page size', () => {
Phil Hughes committed
117
      for (let i = 0; i < 30; i += 1) {
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
        list.issues.push(new ListIssue({
          title: 'Testing',
          iid: _.random(10000) + i,
          confidential: false,
          labels: [list.label]
        }));
      }
      list.issuesSize = 50;

      expect(list.issues.length).toBe(30);

      list.nextPage();

      expect(list.page).toBe(2);
      expect(list.getIssues).toHaveBeenCalled();
    });

    it('does not increase page number if issue count is less than the page size', () => {
      list.issues.push(new ListIssue({
        title: 'Testing',
        iid: _.random(10000),
        confidential: false,
        labels: [list.label]
      }));
      list.issuesSize = 2;

      list.nextPage();

      expect(list.page).toBe(1);
      expect(list.getIssues).toHaveBeenCalled();
    });
  });
150
});