summaryrefslogtreecommitdiff
path: root/spec/frontend/boards/components/board_column_spec.js
blob: d34e228a2d7abb17c230676374863106b4e55d39 (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
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';

import { listObj } from 'jest/boards/mock_data';
import BoardColumn from '~/boards/components/board_column.vue';
import { ListType } from '~/boards/constants';
import { createStore } from '~/boards/stores';

describe('Board Column Component', () => {
  let wrapper;
  let store;

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

  const initStore = () => {
    store = createStore();
  };

  const createComponent = ({ listType = ListType.backlog, collapsed = false } = {}) => {
    const listMock = {
      ...listObj,
      listType,
      collapsed,
    };

    if (listType === ListType.assignee) {
      delete listMock.label;
      listMock.assignee = {};
    }

    wrapper = shallowMount(BoardColumn, {
      store,
      propsData: {
        list: listMock,
      },
    });
  };

  const isExpandable = () => wrapper.classes('is-expandable');
  const isCollapsed = () => wrapper.classes('is-collapsed');

  describe('Given different list types', () => {
    beforeEach(() => {
      initStore();
    });

    it('is expandable when List Type is `backlog`', () => {
      createComponent({ listType: ListType.backlog });

      expect(isExpandable()).toBe(true);
    });
  });

  describe('expanded / collapsed column', () => {
    it('has class is-collapsed when list is collapsed', () => {
      createComponent({ collapsed: false });

      expect(isCollapsed()).toBe(false);
    });

    it('does not have class is-collapsed when list is expanded', () => {
      createComponent({ collapsed: true });

      expect(isCollapsed()).toBe(true);
    });
  });

  describe('highlighting', () => {
    it('scrolls to column when highlighted', async () => {
      createComponent();

      store.state.highlightedLists.push(listObj.id);

      await nextTick();

      expect(wrapper.element.scrollIntoView).toHaveBeenCalled();
    });
  });

  describe('on mount', () => {
    beforeEach(async () => {
      initStore();
      jest.spyOn(store, 'dispatch').mockImplementation();
    });

    describe('when list is collapsed', () => {
      it('does not call fetchItemsForList when', async () => {
        createComponent({ collapsed: true });

        await nextTick();

        expect(store.dispatch).toHaveBeenCalledTimes(0);
      });
    });

    describe('when the list is not collapsed', () => {
      it('calls fetchItemsForList when', async () => {
        createComponent({ collapsed: false });

        await nextTick();

        expect(store.dispatch).toHaveBeenCalledWith('fetchItemsForList', { listId: 300 });
      });
    });
  });
});