summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/registry/details_row_spec.js
blob: ebc9816f98324ee48cfd2d4c703089ce1525d6d8 (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
import { GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import component from '~/vue_shared/components/registry/details_row.vue';

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

  const findIcon = () => wrapper.findComponent(GlIcon);
  const findDefaultSlot = () => wrapper.find('[data-testid="default-slot"]');

  const mountComponent = (props) => {
    wrapper = shallowMount(component, {
      propsData: {
        icon: 'clock',
        ...props,
      },
      slots: {
        default: '<div data-testid="default-slot"></div>',
      },
    });
  };

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

  it('has a default slot', () => {
    mountComponent();
    expect(findDefaultSlot().exists()).toBe(true);
  });

  describe('icon prop', () => {
    it('contains an icon', () => {
      mountComponent();
      expect(findIcon().exists()).toBe(true);
    });

    it('icon has the correct props', () => {
      mountComponent();
      expect(findIcon().props()).toMatchObject({
        name: 'clock',
      });
    });
  });

  describe('padding prop', () => {
    it('padding has a default', () => {
      mountComponent();
      expect(wrapper.classes('gl-py-2')).toBe(true);
    });

    it('is reflected in the template', () => {
      mountComponent({ padding: 'gl-py-4' });
      expect(wrapper.classes('gl-py-4')).toBe(true);
    });
  });

  describe('dashed prop', () => {
    const borderClasses = ['gl-border-b-solid', 'gl-border-gray-100', 'gl-border-b-1'];
    it('by default component has no border', () => {
      mountComponent();
      expect(wrapper.classes).not.toEqual(expect.arrayContaining(borderClasses));
    });

    it('has a border when dashed is true', () => {
      mountComponent({ dashed: true });
      expect(wrapper.classes()).toEqual(expect.arrayContaining(borderClasses));
    });
  });
});