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

runner_type_badge_spec.js « components « runner « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fb344e65389902a6ad10172391537fb423ea1f00 (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
import { GlBadge } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import RunnerTypeBadge from '~/runner/components/runner_type_badge.vue';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import { INSTANCE_TYPE, GROUP_TYPE, PROJECT_TYPE } from '~/runner/constants';

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

  const findBadge = () => wrapper.findComponent(GlBadge);
  const getTooltip = () => getBinding(findBadge().element, 'gl-tooltip');

  const createComponent = ({ props = {} } = {}) => {
    wrapper = shallowMount(RunnerTypeBadge, {
      propsData: {
        ...props,
      },
      directives: {
        GlTooltip: createMockDirective(),
      },
    });
  };

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

  describe.each`
    type             | text          | variant
    ${INSTANCE_TYPE} | ${'shared'}   | ${'success'}
    ${GROUP_TYPE}    | ${'group'}    | ${'success'}
    ${PROJECT_TYPE}  | ${'specific'} | ${'info'}
  `('displays $type runner', ({ type, text, variant }) => {
    beforeEach(() => {
      createComponent({ props: { type } });
    });

    it(`as "${text}" with a ${variant} variant`, () => {
      expect(findBadge().text()).toBe(text);
      expect(findBadge().props('variant')).toBe(variant);
    });

    it('with a tooltip', () => {
      expect(getTooltip().value).toBeDefined();
    });
  });

  it('validation fails for an incorrect type', () => {
    expect(() => {
      createComponent({ props: { type: 'AN_UNKNOWN_VALUE' } });
    }).toThrow();
  });

  it('does not render content when type is missing', () => {
    createComponent({ props: { type: undefined } });

    expect(findBadge().exists()).toBe(false);
  });
});