Welcome to mirror list, hosted at ThFree Co, Russian Federation.

board_card_spec.js « components « boards « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d68e0f9fc2353bd930b3c6d6425858409289e34b (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
import { createLocalVue, shallowMount } from '@vue/test-utils';
import Vuex from 'vuex';

import BoardCard from '~/boards/components/board_card.vue';
import IssueCardInner from '~/boards/components/issue_card_inner.vue';
import { inactiveId } from '~/boards/constants';
import { mockLabelList, mockIssue } from '../mock_data';

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

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

  const createStore = ({ initialState = {}, isSwimlanesOn = false } = {}) => {
    mockActions = {
      toggleBoardItem: jest.fn(),
      toggleBoardItemMultiSelection: jest.fn(),
    };

    store = new Vuex.Store({
      state: {
        activeId: inactiveId,
        selectedBoardItems: [],
        ...initialState,
      },
      actions: mockActions,
      getters: {
        isSwimlanesOn: () => isSwimlanesOn,
      },
    });
  };

  // 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(BoardCard, {
      localVue,
      stubs: {
        IssueCardInner,
      },
      store,
      propsData: {
        list: mockLabelList,
        issue: mockIssue,
        disabled: false,
        index: 0,
        ...propsData,
      },
      provide: {
        groupId: null,
        rootPath: '/',
        scopedLabelsAvailable: false,
        ...provide,
      },
    });
  };

  const selectCard = async () => {
    wrapper.trigger('mouseup');
    await wrapper.vm.$nextTick();
  };

  const multiSelectCard = async () => {
    wrapper.trigger('mouseup', { ctrlKey: true });
    await wrapper.vm.$nextTick();
  };

  afterEach(() => {
    wrapper.destroy();
    wrapper = null;
    store = null;
  });

  describe.each`
    isSwimlanesOn
    ${true}       | ${false}
  `('when isSwimlanesOn is $isSwimlanesOn', ({ isSwimlanesOn }) => {
    it('should not highlight the card by default', async () => {
      createStore({ isSwimlanesOn });
      mountComponent();

      expect(wrapper.classes()).not.toContain('is-active');
      expect(wrapper.classes()).not.toContain('multi-select');
    });

    it('should highlight the card with a correct style when selected', async () => {
      createStore({
        initialState: {
          activeId: mockIssue.id,
        },
        isSwimlanesOn,
      });
      mountComponent();

      expect(wrapper.classes()).toContain('is-active');
      expect(wrapper.classes()).not.toContain('multi-select');
    });

    it('should highlight the card with a correct style when multi-selected', async () => {
      createStore({
        initialState: {
          activeId: inactiveId,
          selectedBoardItems: [mockIssue],
        },
        isSwimlanesOn,
      });
      mountComponent();

      expect(wrapper.classes()).toContain('multi-select');
      expect(wrapper.classes()).not.toContain('is-active');
    });

    describe('when mouseup event is called on the issue card', () => {
      beforeEach(() => {
        createStore({ isSwimlanesOn });
        mountComponent();
      });

      describe('when not using multi-select', () => {
        it('should call vuex action "toggleBoardItem" with correct parameters', async () => {
          await selectCard();

          expect(mockActions.toggleBoardItem).toHaveBeenCalledTimes(1);
          expect(mockActions.toggleBoardItem).toHaveBeenCalledWith(expect.any(Object), {
            boardItem: mockIssue,
          });
        });
      });

      describe('when using multi-select', () => {
        it('should call vuex action "multiSelectBoardItem" with correct parameters', async () => {
          await multiSelectCard();

          expect(mockActions.toggleBoardItemMultiSelection).toHaveBeenCalledTimes(1);
          expect(mockActions.toggleBoardItemMultiSelection).toHaveBeenCalledWith(
            expect.any(Object),
            mockIssue,
          );
        });
      });
    });
  });
});