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

slot_switch_spec.js « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3a2147c6c894011587a6b51fc84a8837df944cfd (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
import { shallowMount } from '@vue/test-utils';
import { assertProps } from 'helpers/assert_props';

import SlotSwitch from '~/vue_shared/components/slot_switch.vue';

describe('SlotSwitch', () => {
  const slots = {
    first: '<a>AGP</a>',
    second: '<p>PCI</p>',
  };

  let wrapper;

  const createComponent = (propsData) => {
    wrapper = shallowMount(SlotSwitch, {
      propsData,
      slots,
    });
  };

  const getChildrenHtml = () => wrapper.findAll('* *').wrappers.map((c) => c.html());

  it('throws an error if activeSlotNames is missing', () => {
    expect(() => assertProps(SlotSwitch, {})).toThrow(
      '[Vue warn]: Missing required prop: "activeSlotNames"',
    );
  });

  it('renders no slots if activeSlotNames is empty', () => {
    createComponent({
      activeSlotNames: [],
    });

    expect(getChildrenHtml().length).toBe(0);
  });

  it('renders one slot if activeSlotNames contains single slot name', () => {
    createComponent({
      activeSlotNames: ['first'],
    });

    expect(getChildrenHtml()).toEqual([slots.first]);
  });

  it('renders multiple slots if activeSlotNames contains multiple slot names', () => {
    createComponent({
      activeSlotNames: Object.keys(slots),
    });

    expect(getChildrenHtml()).toEqual(Object.values(slots));
  });
});