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

runner_type_icon_spec.js « components « runner « ci « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 01f3de10aa6b374a5d4d183962965819cf5e59e8 (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
65
66
67
import { GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import RunnerTypeIcon from '~/ci/runner/components/runner_type_icon.vue';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import { assertProps } from 'helpers/assert_props';
import {
  INSTANCE_TYPE,
  GROUP_TYPE,
  PROJECT_TYPE,
  I18N_INSTANCE_TYPE,
  I18N_GROUP_TYPE,
  I18N_PROJECT_TYPE,
} from '~/ci/runner/constants';

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

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

  const createComponent = ({ props = {} } = {}) => {
    wrapper = shallowMount(RunnerTypeIcon, {
      propsData: {
        ...props,
      },
      directives: {
        GlTooltip: createMockDirective('gl-tooltip'),
      },
    });
  };

  describe.each`
    type             | tooltipText
    ${INSTANCE_TYPE} | ${I18N_INSTANCE_TYPE}
    ${GROUP_TYPE}    | ${I18N_GROUP_TYPE}
    ${PROJECT_TYPE}  | ${I18N_PROJECT_TYPE}
  `('displays $type runner', ({ type, tooltipText }) => {
    beforeEach(() => {
      createComponent({ props: { type } });
    });

    it(`with no text`, () => {
      expect(findIcon().text()).toBe('');
    });

    it(`with aria-label`, () => {
      expect(findIcon().props('ariaLabel')).toBeDefined();
    });

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

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

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

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