summaryrefslogtreecommitdiff
path: root/spec/frontend/boards/components/board_card_layout_spec.js
blob: d8633871e8d40015321275615e885ad4f35028ee (plain)
1
2
3
4
5
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
94
95
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
132
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
/* global List */
/* global ListLabel */

import Vuex from 'vuex';
import { createLocalVue, shallowMount } from '@vue/test-utils';

import MockAdapter from 'axios-mock-adapter';
import waitForPromises from 'helpers/wait_for_promises';
import axios from '~/lib/utils/axios_utils';

import '~/boards/models/label';
import '~/boards/models/assignee';
import '~/boards/models/list';
import boardsVuexStore from '~/boards/stores';
import boardsStore from '~/boards/stores/boards_store';
import BoardCardLayout from '~/boards/components/board_card_layout.vue';
import issueCardInner from '~/boards/components/issue_card_inner.vue';
import { listObj, boardsMockInterceptor, setMockEndpoints } from '../mock_data';

import { ISSUABLE } from '~/boards/constants';

describe('Board card layout', () => {
  let wrapper;
  let mock;
  let list;
  let store;

  const localVue = createLocalVue();
  localVue.use(Vuex);

  const createStore = ({ getters = {}, actions = {} } = {}) => {
    store = new Vuex.Store({
      ...boardsVuexStore,
      actions,
      getters,
    });
  };

  // this particular mount component needs to be used after the root beforeEach because it depends on list being initialized
  const mountComponent = ({ propsData = {}, provide = {} } = {}) => {
    wrapper = shallowMount(BoardCardLayout, {
      localVue,
      stubs: {
        issueCardInner,
      },
      store,
      propsData: {
        list,
        issue: list.issues[0],
        disabled: false,
        index: 0,
        ...propsData,
      },
      provide: {
        groupId: null,
        rootPath: '/',
        scopedLabelsAvailable: false,
        ...provide,
      },
    });
  };

  const setupData = () => {
    list = new List(listObj);
    boardsStore.create();
    boardsStore.detail.issue = {};
    const label1 = new ListLabel({
      id: 3,
      title: 'testing 123',
      color: '#000cff',
      text_color: 'white',
      description: 'test',
    });
    return waitForPromises().then(() => {
      list.issues[0].labels.push(label1);
    });
  };

  beforeEach(() => {
    mock = new MockAdapter(axios);
    mock.onAny().reply(boardsMockInterceptor);
    setMockEndpoints();
    return setupData();
  });

  afterEach(() => {
    wrapper.destroy();
    wrapper = null;
    list = null;
    mock.restore();
  });

  describe('mouse events', () => {
    it('sets showDetail to true on mousedown', async () => {
      createStore();
      mountComponent();

      wrapper.trigger('mousedown');
      await wrapper.vm.$nextTick();

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

    it('sets showDetail to false on mousemove', async () => {
      createStore();
      mountComponent();
      wrapper.trigger('mousedown');
      await wrapper.vm.$nextTick();
      expect(wrapper.vm.showDetail).toBe(true);
      wrapper.trigger('mousemove');
      await wrapper.vm.$nextTick();
      expect(wrapper.vm.showDetail).toBe(false);
    });

    it("calls 'setActiveId' when 'graphqlBoardLists' feature flag is turned on", async () => {
      const setActiveId = jest.fn();
      createStore({
        actions: {
          setActiveId,
        },
      });
      mountComponent({
        provide: {
          glFeatures: { graphqlBoardLists: true },
        },
      });

      wrapper.trigger('mouseup');
      await wrapper.vm.$nextTick();

      expect(setActiveId).toHaveBeenCalledTimes(1);
      expect(setActiveId).toHaveBeenCalledWith(expect.any(Object), {
        id: list.issues[0].id,
        sidebarType: ISSUABLE,
      });
    });

    it("calls 'setActiveId' when epic swimlanes is active", async () => {
      const setActiveId = jest.fn();
      const isSwimlanesOn = () => true;
      createStore({
        getters: { isSwimlanesOn },
        actions: {
          setActiveId,
        },
      });
      mountComponent();

      wrapper.trigger('mouseup');
      await wrapper.vm.$nextTick();

      expect(setActiveId).toHaveBeenCalledTimes(1);
      expect(setActiveId).toHaveBeenCalledWith(expect.any(Object), {
        id: list.issues[0].id,
        sidebarType: ISSUABLE,
      });
    });
  });
});