summaryrefslogtreecommitdiff
path: root/spec/frontend/groups/components/item_type_icon_spec.js
blob: 5e7056be218583b0408e52f8414d738cfd8e7b0f (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
import { shallowMount } from '@vue/test-utils';
import { GlIcon } from '@gitlab/ui';
import ItemTypeIcon from '~/groups/components/item_type_icon.vue';
import { ITEM_TYPE } from '../mock_data';

describe('ItemTypeIcon', () => {
  let wrapper;

  const defaultProps = {
    itemType: ITEM_TYPE.GROUP,
    isGroupOpen: false,
  };

  const createComponent = (props = {}) => {
    wrapper = shallowMount(ItemTypeIcon, {
      propsData: { ...defaultProps, ...props },
    });
  };

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

  const findGlIcon = () => wrapper.find(GlIcon);

  describe('template', () => {
    it('renders component template correctly', () => {
      createComponent();

      expect(wrapper.classes()).toContain('item-type-icon');
    });

    it.each`
      type                 | isGroupOpen | icon
      ${ITEM_TYPE.GROUP}   | ${true}     | ${'folder-open'}
      ${ITEM_TYPE.GROUP}   | ${false}    | ${'folder-o'}
      ${ITEM_TYPE.PROJECT} | ${true}     | ${'bookmark'}
      ${ITEM_TYPE.PROJECT} | ${false}    | ${'bookmark'}
    `(
      'shows "$icon" icon when `itemType` is "$type" and `isGroupOpen` is $isGroupOpen',
      ({ type, isGroupOpen, icon }) => {
        createComponent({
          itemType: type,
          isGroupOpen,
        });
        expect(findGlIcon().props('name')).toBe(icon);
      },
    );
  });
});