BigW Consortium Gitlab

board_card_spec.js 4.47 KB
Newer Older
Phil Hughes committed
1 2
/* global Vue */
/* global List */
Phil Hughes committed
3
/* global ListLabel */
Phil Hughes committed
4
/* global listObj */
Phil Hughes committed
5 6
/* global boardsMockInterceptor */
/* global BoardService */
Phil Hughes committed
7 8 9 10

require('~/boards/models/list');
require('~/boards/models/label');
require('~/boards/stores/boards_store');
11
const boardCard = require('~/boards/components/board_card').default;
Phil Hughes committed
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
require('./mock_data');

describe('Issue card', () => {
  let vm;

  beforeEach((done) => {
    Vue.http.interceptors.push(boardsMockInterceptor);

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

    const BoardCardComp = Vue.extend(boardCard);
    const list = new List(listObj);
    const label1 = new ListLabel({
      id: 3,
      title: 'testing 123',
      color: 'blue',
      text_color: 'white',
      description: 'test',
    });

    setTimeout(() => {
      list.issues[0].labels.push(label1);

      vm = new BoardCardComp({
        propsData: {
          list,
          issue: list.issues[0],
          issueLinkBase: '/',
          disabled: false,
          index: 0,
          rootPath: '/',
        },
Phil Hughes committed
46
      }).$mount();
Phil Hughes committed
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
      done();
    }, 0);
  });

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

  it('returns false when detailIssue is empty', () => {
    expect(vm.issueDetailVisible).toBe(false);
  });

  it('returns true when detailIssue is equal to card issue', () => {
    gl.issueBoards.BoardsStore.detail.issue = vm.issue;

    expect(vm.issueDetailVisible).toBe(true);
  });

  it('adds user-can-drag class if not disabled', () => {
    expect(vm.$el.classList.contains('user-can-drag')).toBe(true);
  });

  it('does not add user-can-drag class disabled', (done) => {
    vm.disabled = true;

    setTimeout(() => {
      expect(vm.$el.classList.contains('user-can-drag')).toBe(false);
      done();
    }, 0);
  });

  it('does not add disabled class', () => {
    expect(vm.$el.classList.contains('is-disabled')).toBe(false);
  });

  it('adds disabled class is disabled is true', (done) => {
    vm.disabled = true;

    setTimeout(() => {
      expect(vm.$el.classList.contains('is-disabled')).toBe(true);
      done();
    }, 0);
  });

  describe('mouse events', () => {
    const triggerEvent = (eventName, el = vm.$el) => {
      const event = document.createEvent('MouseEvents');
Phil Hughes committed
94 95
      event.initMouseEvent(eventName, true, true, window, 1, 0, 0, 0, 0, false, false,
                           false, false, 0, null);
Phil Hughes committed
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

      el.dispatchEvent(event);
    };

    it('sets showDetail to true on mousedown', () => {
      triggerEvent('mousedown');

      expect(vm.showDetail).toBe(true);
    });

    it('sets showDetail to false on mousemove', () => {
      triggerEvent('mousedown');

      expect(vm.showDetail).toBe(true);

      triggerEvent('mousemove');

      expect(vm.showDetail).toBe(false);
    });

    it('does not set detail issue if showDetail is false', () => {
      expect(gl.issueBoards.BoardsStore.detail.issue).toEqual({});
    });

    it('does not set detail issue if link is clicked', () => {
      triggerEvent('mouseup', vm.$el.querySelector('a'));

      expect(gl.issueBoards.BoardsStore.detail.issue).toEqual({});
    });

    it('does not set detail issue if button is clicked', () => {
      triggerEvent('mouseup', vm.$el.querySelector('button'));

      expect(gl.issueBoards.BoardsStore.detail.issue).toEqual({});
    });

Phil Hughes committed
132
    it('does not set detail issue if showDetail is false after mouseup', () => {
Phil Hughes committed
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
      triggerEvent('mouseup');

      expect(gl.issueBoards.BoardsStore.detail.issue).toEqual({});
    });

    it('sets detail issue to card issue on mouse up', () => {
      triggerEvent('mousedown');
      triggerEvent('mouseup');

      expect(gl.issueBoards.BoardsStore.detail.issue).toEqual(vm.issue);
      expect(gl.issueBoards.BoardsStore.detail.list).toEqual(vm.list);
    });

    it('adds active class if detail issue is set', (done) => {
      triggerEvent('mousedown');
      triggerEvent('mouseup');

      setTimeout(() => {
        expect(vm.$el.classList.contains('is-active')).toBe(true);
        done();
      }, 0);
    });

    it('resets detail issue to empty if already set', () => {
      triggerEvent('mousedown');
      triggerEvent('mouseup');

      expect(gl.issueBoards.BoardsStore.detail.issue).toEqual(vm.issue);

      triggerEvent('mousedown');
      triggerEvent('mouseup');

      expect(gl.issueBoards.BoardsStore.detail.issue).toEqual({});
    });
  });
});