boards_store_spec.js 4.6 KB
Newer Older
1
/* eslint-disable comma-dangle, one-var, no-unused-vars */
2 3 4 5 6 7 8
/* global Vue */
/* global BoardService */
/* global boardsMockInterceptor */
/* global Cookies */
/* global listObj */
/* global listObjDuplicate */

9 10 11 12 13 14 15
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');
16
require('./mock_data');
17

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

P
Phil Hughes 已提交
24 25 26 27
    Cookies.set('issue_board_welcome_hidden', 'false', {
      expires: 365 * 10,
      path: ''
    });
28 29
  });

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

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

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

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

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

49 50
      expect(list.id).toBe(1);
    });
51

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

56 57
      expect(list).toBeDefined();
    });
58

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

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

65 66 67 68 69 70
      setTimeout(() => {
        expect(list.issues.length).toBe(1);
        expect(list.issues[0].id).toBe(1);
        done();
      }, 0);
    });
71

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

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

94 95 96 97 98 99 100 101
    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);
    });
102

P
Phil Hughes 已提交
103
    it('check for blank state adding when done list exist', () => {
104 105 106 107 108 109
      gl.issueBoards.BoardsStore.addList({
        list_type: 'done'
      });

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

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

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

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

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

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

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

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

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

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

136 137
      expect(listOne.position).toBe(1);
    });
138

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

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

145 146 147
      setTimeout(() => {
        expect(listOne.issues.length).toBe(1);
        expect(listTwo.issues.length).toBe(1);
148

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

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

154 155
        done();
      }, 0);
156 157
    });
  });
158
});