BigW Consortium Gitlab

boards_store_spec.js 6.98 KB
Newer Older
1
/* eslint-disable comma-dangle, one-var, no-unused-vars */
2 3 4 5
/* global BoardService */
/* global boardsMockInterceptor */
/* global listObj */
/* global listObjDuplicate */
Phil Hughes committed
6
/* global ListIssue */
7

8
import Vue from 'vue';
9
import Cookies from 'js-cookie';
10

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

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

Phil Hughes committed
26 27 28
    spyOn(gl.boardService, 'moveIssue').and.callFake(() => new Promise((resolve) => {
      resolve();
    }));
Phil Hughes committed
29

Phil Hughes committed
30 31 32 33
    Cookies.set('issue_board_welcome_hidden', 'false', {
      expires: 365 * 10,
      path: ''
    });
34 35
  });

36 37 38
  afterEach(() => {
    Vue.http.interceptors = _.without(Vue.http.interceptors, boardsMockInterceptor);
  });
39

40 41 42
  it('starts with a blank state', () => {
    expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(0);
  });
43

44 45 46
  describe('lists', () => {
    it('creates new list without persisting to DB', () => {
      gl.issueBoards.BoardsStore.addList(listObj);
47

48 49
      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);
    });
50

51 52
    it('finds list by ID', () => {
      gl.issueBoards.BoardsStore.addList(listObj);
53
      const list = gl.issueBoards.BoardsStore.findList('id', listObj.id);
54

55
      expect(list.id).toBe(listObj.id);
56
    });
57

58 59 60
    it('finds list by type', () => {
      gl.issueBoards.BoardsStore.addList(listObj);
      const list = gl.issueBoards.BoardsStore.findList('type', 'label');
61

62 63
      expect(list).toBeDefined();
    });
64

65 66
    it('gets issue when new list added', (done) => {
      gl.issueBoards.BoardsStore.addList(listObj);
67
      const list = gl.issueBoards.BoardsStore.findList('id', listObj.id);
68

69
      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);
70

71 72 73 74 75 76
      setTimeout(() => {
        expect(list.issues.length).toBe(1);
        expect(list.issues[0].id).toBe(1);
        done();
      }, 0);
    });
77

78 79 80 81 82 83 84 85 86 87
    it('persists new list', (done) => {
      gl.issueBoards.BoardsStore.new({
        title: 'Test',
        type: 'label',
        label: {
          id: 1,
          title: 'Testing',
          color: 'red',
          description: 'testing;'
        }
88
      });
89
      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);
90

91
      setTimeout(() => {
92
        const list = gl.issueBoards.BoardsStore.findList('id', listObj.id);
93
        expect(list).toBeDefined();
94
        expect(list.id).toBe(listObj.id);
95 96 97 98
        expect(list.position).toBe(0);
        done();
      }, 0);
    });
99

100 101 102 103 104 105 106 107
    it('check for blank state adding', () => {
      expect(gl.issueBoards.BoardsStore.shouldAddBlankState()).toBe(true);
    });

    it('check for blank state not adding', () => {
      gl.issueBoards.BoardsStore.addList(listObj);
      expect(gl.issueBoards.BoardsStore.shouldAddBlankState()).toBe(false);
    });
108

109
    it('check for blank state adding when closed list exist', () => {
110
      gl.issueBoards.BoardsStore.addList({
111
        list_type: 'closed'
112 113 114 115
      });

      expect(gl.issueBoards.BoardsStore.shouldAddBlankState()).toBe(true);
    });
116

117 118
    it('adds the blank state', () => {
      gl.issueBoards.BoardsStore.addBlankState();
119

120 121 122
      const list = gl.issueBoards.BoardsStore.findList('type', 'blank', 'blank');
      expect(list).toBeDefined();
    });
123

124 125
    it('removes list from state', () => {
      gl.issueBoards.BoardsStore.addList(listObj);
126

127
      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);
128

129
      gl.issueBoards.BoardsStore.removeList(listObj.id, 'label');
130

131 132
      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(0);
    });
133

134
    it('moves the position of lists', () => {
135 136
      const listOne = gl.issueBoards.BoardsStore.addList(listObj);
      const listTwo = gl.issueBoards.BoardsStore.addList(listObjDuplicate);
137

138
      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(2);
139

140
      gl.issueBoards.BoardsStore.moveList(listOne, [listObjDuplicate.id, listObj.id]);
141

142 143
      expect(listOne.position).toBe(1);
    });
144

145
    it('moves an issue from one list to another', (done) => {
146 147
      const listOne = gl.issueBoards.BoardsStore.addList(listObj);
      const listTwo = gl.issueBoards.BoardsStore.addList(listObjDuplicate);
148

149
      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(2);
150

151 152 153
      setTimeout(() => {
        expect(listOne.issues.length).toBe(1);
        expect(listTwo.issues.length).toBe(1);
154

155
        gl.issueBoards.BoardsStore.moveIssueToList(listOne, listTwo, listOne.findIssue(1));
156

157 158
        expect(listOne.issues.length).toBe(0);
        expect(listTwo.issues.length).toBe(1);
159

160 161
        done();
      }, 0);
162
    });
Phil Hughes committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214

    it('moves issue to top of another list', (done) => {
      const listOne = gl.issueBoards.BoardsStore.addList(listObj);
      const listTwo = gl.issueBoards.BoardsStore.addList(listObjDuplicate);

      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(2);

      setTimeout(() => {
        listOne.issues[0].id = 2;

        expect(listOne.issues.length).toBe(1);
        expect(listTwo.issues.length).toBe(1);

        gl.issueBoards.BoardsStore.moveIssueToList(listOne, listTwo, listOne.findIssue(2), 0);

        expect(listOne.issues.length).toBe(0);
        expect(listTwo.issues.length).toBe(2);
        expect(listTwo.issues[0].id).toBe(2);
        expect(gl.boardService.moveIssue).toHaveBeenCalledWith(2, listOne.id, listTwo.id, null, 1);

        done();
      }, 0);
    });

    it('moves issue to bottom of another list', (done) => {
      const listOne = gl.issueBoards.BoardsStore.addList(listObj);
      const listTwo = gl.issueBoards.BoardsStore.addList(listObjDuplicate);

      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(2);

      setTimeout(() => {
        listOne.issues[0].id = 2;

        expect(listOne.issues.length).toBe(1);
        expect(listTwo.issues.length).toBe(1);

        gl.issueBoards.BoardsStore.moveIssueToList(listOne, listTwo, listOne.findIssue(2), 1);

        expect(listOne.issues.length).toBe(0);
        expect(listTwo.issues.length).toBe(2);
        expect(listTwo.issues[1].id).toBe(2);
        expect(gl.boardService.moveIssue).toHaveBeenCalledWith(2, listOne.id, listTwo.id, 1, null);

        done();
      }, 0);
    });

    it('moves issue in list', (done) => {
      const issue = new ListIssue({
        title: 'Testing',
        iid: 2,
        confidential: false,
215 216
        labels: [],
        assignees: [],
Phil Hughes committed
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
      });
      const list = gl.issueBoards.BoardsStore.addList(listObj);

      setTimeout(() => {
        list.addIssue(issue);

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

        gl.issueBoards.BoardsStore.moveIssueInList(list, issue, 0, 1, [1, 2]);

        expect(list.issues[0].id).toBe(2);
        expect(gl.boardService.moveIssue).toHaveBeenCalledWith(2, null, null, 1, null);

        done();
      });
    });
233
  });
234
});