summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/new_namespace/components/welcome_spec.js
blob: 2d51f6dbeeb1869cec97edf067f4309132187649 (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
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { mockTracking } from 'helpers/tracking_helper';
import WelcomePage from '~/vue_shared/new_namespace/components/welcome.vue';

describe('Welcome page', () => {
  let wrapper;
  let trackingSpy;

  const DEFAULT_PROPS = {
    title: 'Create new something',
  };

  const createComponent = ({ propsData, slots }) => {
    wrapper = shallowMount(WelcomePage, {
      slots,
      propsData: {
        ...DEFAULT_PROPS,
        ...propsData,
      },
    });
  };

  beforeEach(() => {
    trackingSpy = mockTracking('_category_', document, jest.spyOn);
    trackingSpy.mockImplementation(() => {});
  });

  afterEach(() => {
    wrapper.destroy();
    window.location.hash = '';
    wrapper = null;
  });

  it('tracks link clicks', async () => {
    createComponent({ propsData: { panels: [{ name: 'test', href: '#' }] } });
    const link = wrapper.find('a');
    link.trigger('click');
    await nextTick();
    return wrapper.vm.$nextTick().then(() => {
      expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_tab', { label: 'test' });
    });
  });

  it('renders footer slot if provided', () => {
    const DUMMY = 'Test message';
    createComponent({
      slots: { footer: DUMMY },
      propsData: { panels: [{ name: 'test', href: '#' }] },
    });

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