summaryrefslogtreecommitdiff
path: root/spec/frontend/integrations/overrides/components/integration_tabs_spec.js
blob: a728b4d391f50e3cf66e45cfe624220431a2ac01 (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
import { mount, shallowMount } from '@vue/test-utils';
import { GlBadge, GlTab } from '@gitlab/ui';

import IntegrationTabs from '~/integrations/overrides/components/integration_tabs.vue';
import { settingsTabTitle, overridesTabTitle } from '~/integrations/constants';

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

  const editPath = 'mock/edit';

  const createComponent = ({ mountFn = shallowMount, props = {} } = {}) => {
    wrapper = mountFn(IntegrationTabs, {
      propsData: props,
      provide: {
        editPath,
      },
      stubs: {
        GlTab,
      },
    });
  };

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

  const findGlBadge = () => wrapper.findComponent(GlBadge);
  const findGlTab = () => wrapper.findComponent(GlTab);
  const findSettingsLink = () => wrapper.find('a');

  describe('template', () => {
    it('renders "Settings" tab as a link', () => {
      createComponent({ mountFn: mount });

      expect(findSettingsLink().text()).toMatchInterpolatedText(settingsTabTitle);
      expect(findSettingsLink().attributes('href')).toBe(editPath);
    });

    it('renders "Projects using custom settings" tab as active', () => {
      const projectOverridesCount = '1';

      createComponent({
        props: { projectOverridesCount },
      });

      expect(findGlTab().exists()).toBe(true);
      expect(findGlTab().text()).toMatchInterpolatedText(
        `${overridesTabTitle} ${projectOverridesCount}`,
      );
      expect(findGlBadge().text()).toBe(projectOverridesCount);
    });

    describe('when count is `null', () => {
      it('renders "Projects using custom settings" tab without count', () => {
        createComponent();

        expect(findGlTab().exists()).toBe(true);
        expect(findGlTab().text()).toMatchInterpolatedText(overridesTabTitle);
        expect(findGlBadge().exists()).toBe(false);
      });
    });
  });
});