summaryrefslogtreecommitdiff
path: root/spec/frontend/runner/components/runner_type_alert_spec.js
blob: 5b136a77eeb85e06520aae247ed68d3f0f3b5adc (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
import { GlAlert, GlLink } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import RunnerTypeAlert from '~/runner/components/runner_type_alert.vue';
import { INSTANCE_TYPE, GROUP_TYPE, PROJECT_TYPE } from '~/runner/constants';

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

  const findAlert = () => wrapper.findComponent(GlAlert);
  const findLink = () => wrapper.findComponent(GlLink);

  const createComponent = ({ props = {} } = {}) => {
    wrapper = shallowMount(RunnerTypeAlert, {
      propsData: {
        type: INSTANCE_TYPE,
        ...props,
      },
    });
  };

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

  describe.each`
    type             | exampleText                                                           | anchor                 | variant
    ${INSTANCE_TYPE} | ${'Shared runners are available to every project'}                    | ${'#shared-runners'}   | ${'success'}
    ${GROUP_TYPE}    | ${'Use Group runners when you want all projects in a group'}          | ${'#group-runners'}    | ${'success'}
    ${PROJECT_TYPE}  | ${'You can set up a specific runner to be used by multiple projects'} | ${'#specific-runners'} | ${'info'}
  `('When it is an $type level runner', ({ type, exampleText, anchor, variant }) => {
    beforeEach(() => {
      createComponent({ props: { type } });
    });

    it('Describes runner type', () => {
      expect(wrapper.text()).toMatch(exampleText);
    });

    it(`Shows a ${variant} variant`, () => {
      expect(findAlert().props('variant')).toBe(variant);
    });

    it(`Links to anchor "${anchor}"`, () => {
      expect(findLink().attributes('href')).toBe(`/help/ci/runners/runners_scope${anchor}`);
    });
  });

  describe('When runner type is not correct', () => {
    it('Does not render content when type is missing', () => {
      createComponent({ props: { type: undefined } });

      expect(wrapper.html()).toBe('');
    });

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