summaryrefslogtreecommitdiff
path: root/spec/javascripts/boards/boards_store_spec.js.es6
blob: b3a1afa28a564906fc2e6d06be0bb66a6b5b7231 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
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
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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* eslint-disable comma-dangle, one-var, no-unused-vars, indent */
/* global Vue */
/* global BoardService */
/* global boardsMockInterceptor */
/* global Cookies */
/* global listObj */
/* global listObjDuplicate */

//= require jquery
//= require jquery_ujs
//= require js.cookie
//= require vue
//= require vue-resource
//= 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
//= require ./mock_data

describe('Store', () => {
  beforeEach(() => {
    Vue.http.interceptors.push(boardsMockInterceptor);
    gl.boardService = new BoardService('/test/issue-boards/board', '1');
    gl.issueBoards.BoardsStore.create();

    Cookies.set('issue_board_welcome_hidden', 'false', {
      expires: 365 * 10,
      path: ''
    });
  });

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

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

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

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

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

      expect(list.id).toBe(1);
    });

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

      expect(list).toBeDefined();
    });

    it('finds list limited by type', () => {
      gl.issueBoards.BoardsStore.addList({
        id: 1,
        position: 0,
        title: 'Test',
        list_type: 'backlog'
      });
      const list = gl.issueBoards.BoardsStore.findList('id', 1, 'backlog');

      expect(list).toBeDefined();
    });

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

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

      setTimeout(() => {
        expect(list.issues.length).toBe(1);
        expect(list.issues[0].id).toBe(1);
        done();
      }, 0);
    });

    it('persists new list', (done) => {
      gl.issueBoards.BoardsStore.new({
        title: 'Test',
        type: 'label',
        label: {
          id: 1,
          title: 'Testing',
          color: 'red',
          description: 'testing;'
        }
      });
      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);

      setTimeout(() => {
        const list = gl.issueBoards.BoardsStore.findList('id', 1);
        expect(list).toBeDefined();
        expect(list.id).toBe(1);
        expect(list.position).toBe(0);
        done();
      }, 0);
    });

    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);
    });

    it('check for blank state adding when backlog & done list exist', () => {
      gl.issueBoards.BoardsStore.addList({
        list_type: 'backlog'
      });
      gl.issueBoards.BoardsStore.addList({
        list_type: 'done'
      });

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

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

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

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

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

      gl.issueBoards.BoardsStore.removeList(1, 'label');

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

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

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

      gl.issueBoards.BoardsStore.moveList(listOne, ['2', '1']);

      expect(listOne.position).toBe(1);
    });

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

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

      setTimeout(() => {
        expect(listOne.issues.length).toBe(1);
        expect(listTwo.issues.length).toBe(1);

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

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

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