summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/dismissible_container_spec.js
blob: b8aeea38e77a71259a4cf76093a8ab988fd9e877 (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
import { shallowMount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import dismissibleContainer from '~/vue_shared/components/dismissible_container.vue';

describe('DismissibleContainer', () => {
  let wrapper;
  const propsData = {
    path: 'some/path',
    featureId: 'some-feature-id',
  };

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

  describe('template', () => {
    const findBtn = () => wrapper.find('[data-testid="close"]');
    let mockAxios;

    beforeEach(() => {
      mockAxios = new MockAdapter(axios);
      wrapper = shallowMount(dismissibleContainer, { propsData });
    });

    afterEach(() => {
      mockAxios.restore();
    });

    it('successfully dismisses', () => {
      mockAxios.onPost(propsData.path).replyOnce(200);
      const button = findBtn();

      button.trigger('click');

      expect(wrapper.emitted().dismiss).toBeTruthy();
    });
  });

  describe('slots', () => {
    const slots = {
      title: 'Foo Title',
      default: 'default slot',
    };

    it.each(Object.keys(slots))('renders the %s slot', (slot) => {
      const slotContent = slots[slot];
      wrapper = shallowMount(dismissibleContainer, {
        propsData,
        slots: {
          [slot]: `<span>${slotContent}</span>`,
        },
      });

      expect(wrapper.text()).toContain(slotContent);
    });
  });
});