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

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

    $.cookie('issue_board_welcome_hidden', 'false');
  });

  describe('Store', () => {
    it('starts with a blank state', () => {
25
      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(0);
26 27 28 29
    });

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

32
        expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);
33 34 35
      });

      it('finds list by ID', () => {
36 37
        gl.issueBoards.BoardsStore.addList(listObj);
        const list = gl.issueBoards.BoardsStore.findList('id', 1);
38 39 40 41 42

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

      it('finds list by type', () => {
43 44
        gl.issueBoards.BoardsStore.addList(listObj);
        const list = gl.issueBoards.BoardsStore.findList('type', 'label');
45 46 47 48

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

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

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

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

65
        expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);
66 67 68

        setTimeout(() => {
          expect(list.issues.length).toBe(1);
Phil Hughes's avatar
Phil Hughes committed
69
          expect(list.issues[0].id).toBe(1);
70 71 72 73 74
          done();
        }, 0);
      });

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

        setTimeout(() => {
88
          const list = gl.issueBoards.BoardsStore.findList('id', 1);
89 90 91 92 93 94 95 96
          expect(list).toBeDefined();
          expect(list.id).toBe(1);
          expect(list.position).toBe(0);
          done();
        }, 0);
      });

      it('check for blank state adding', () => {
97
        expect(gl.issueBoards.BoardsStore.shouldAddBlankState()).toBe(true);
98 99 100
      });

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Phil Hughes's avatar
Phil Hughes committed
150
        setTimeout(() => {
151
          expect(listOne.issues.length).toBe(1);
152 153
          expect(listTwo.issues.length).toBe(1);

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

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

          done();
Phil Hughes's avatar
Phil Hughes committed
160
        }, 0);
161 162 163 164
      });
    });
  });
})();