boards_store_spec.js.es6 4.94 KB
Newer Older
1
/* eslint-disable */
2 3
//= require jquery
//= require jquery_ujs
4
//= require js.cookie
5 6 7 8 9 10 11 12 13 14 15 16 17
//= 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

(() => {
  beforeEach(() => {
Phil Hughes's avatar
Phil Hughes committed
18
    gl.boardService = new BoardService('/test/issue-boards/board', '1');
19
    gl.issueBoards.BoardsStore.create();
20

Phil Hughes's avatar
Phil Hughes committed
21 22 23 24
    Cookies.set('issue_board_welcome_hidden', 'false', {
      expires: 365 * 10,
      path: ''
    });
25 26 27 28
  });

  describe('Store', () => {
    it('starts with a blank state', () => {
29
      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(0);
30 31 32 33
    });

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

36
        expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);
37 38 39
      });

      it('finds list by ID', () => {
40 41
        gl.issueBoards.BoardsStore.addList(listObj);
        const list = gl.issueBoards.BoardsStore.findList('id', 1);
42 43 44 45 46

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

      it('finds list by type', () => {
47 48
        gl.issueBoards.BoardsStore.addList(listObj);
        const list = gl.issueBoards.BoardsStore.findList('type', 'label');
49 50 51 52

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

53
      it('finds list limited by type', () => {
54
        gl.issueBoards.BoardsStore.addList({
55 56 57 58 59
          id: 1,
          position: 0,
          title: 'Test',
          list_type: 'backlog'
        });
60
        const list = gl.issueBoards.BoardsStore.findList('id', 1, 'backlog');
61 62 63 64

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

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

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

        setTimeout(() => {
          expect(list.issues.length).toBe(1);
Phil Hughes's avatar
Phil Hughes committed
73
          expect(list.issues[0].id).toBe(1);
74 75 76 77 78
          done();
        }, 0);
      });

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

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

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

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

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

117
        expect(gl.issueBoards.BoardsStore.shouldAddBlankState()).toBe(true);
118 119 120
      });

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

123
        const list = gl.issueBoards.BoardsStore.findList('type', 'blank', 'blank');
124 125 126 127
        expect(list).toBeDefined();
      });

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

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

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

134
        expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(0);
135 136 137
      });

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

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

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

145
        expect(listOne.position).toBe(1);
146 147 148
      });

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

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

Phil Hughes's avatar
Phil Hughes committed
154
        setTimeout(() => {
155
          expect(listOne.issues.length).toBe(1);
156 157
          expect(listTwo.issues.length).toBe(1);

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

160
          expect(listOne.issues.length).toBe(0);
161 162 163
          expect(listTwo.issues.length).toBe(1);

          done();
Phil Hughes's avatar
Phil Hughes committed
164
        }, 0);
165 166 167 168
      });
    });
  });
})();