BigW Consortium Gitlab

board_blank_state_spec.js 2.24 KB
Newer Older
Phil Hughes committed
1
/* global BoardService */
2
import Vue from 'vue';
Phil Hughes committed
3
import '~/boards/stores/boards_store';
4
import boardBlankState from '~/boards/components/board_blank_state';
Phil Hughes committed
5
import './mock_data';
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

describe('Boards blank state', () => {
  let vm;
  let fail = false;

  beforeEach((done) => {
    const Comp = Vue.extend(boardBlankState);

    gl.issueBoards.BoardsStore.create();
    gl.boardService = new BoardService('/test/issue-boards/board', '', '1');

    spyOn(gl.boardService, 'generateDefaultLists').and.callFake(() => new Promise((resolve, reject) => {
      if (fail) {
        reject();
      } else {
        resolve({
          json() {
            return [{
              id: 1,
              title: 'To Do',
              label: { id: 1 },
            }, {
              id: 2,
              title: 'Doing',
              label: { id: 2 },
Phil Hughes committed
31
            }];
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
          },
        });
      }
    }));

    vm = new Comp();

    setTimeout(() => {
      vm.$mount();
      done();
    });
  });

  it('renders pre-defined labels', () => {
    expect(
Phil Hughes committed
47
      vm.$el.querySelectorAll('.board-blank-state-list li').length,
48 49 50
    ).toBe(2);

    expect(
Phil Hughes committed
51
      vm.$el.querySelectorAll('.board-blank-state-list li')[0].textContent.trim(),
52 53 54
    ).toEqual('To Do');

    expect(
Phil Hughes committed
55
      vm.$el.querySelectorAll('.board-blank-state-list li')[1].textContent.trim(),
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
    ).toEqual('Doing');
  });

  it('clears blank state', (done) => {
    vm.$el.querySelector('.btn-default').click();

    setTimeout(() => {
      expect(gl.issueBoards.BoardsStore.welcomeIsHidden()).toBeTruthy();

      done();
    });
  });

  it('creates pre-defined labels', (done) => {
    vm.$el.querySelector('.btn-create').click();

    setTimeout(() => {
      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(2);
      expect(gl.issueBoards.BoardsStore.state.lists[0].title).toEqual('To Do');
      expect(gl.issueBoards.BoardsStore.state.lists[1].title).toEqual('Doing');

      done();
    });
  });

  it('resets the store if request fails', (done) => {
    fail = true;

    vm.$el.querySelector('.btn-create').click();

    setTimeout(() => {
      expect(gl.issueBoards.BoardsStore.welcomeIsHidden()).toBeFalsy();
      expect(gl.issueBoards.BoardsStore.state.lists.length).toBe(1);

      done();
    });
  });
});