summaryrefslogtreecommitdiff
path: root/spec/frontend/ci/runner/components/runner_list_empty_state_spec.js
blob: d351f7b6908b8401347c07463123fab5450e1a46 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { GlEmptyState, GlLink, GlSprintf } from '@gitlab/ui';
import { s__ } from '~/locale';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import RunnerInstructionsModal from '~/vue_shared/components/runner_instructions/runner_instructions_modal.vue';

import RunnerListEmptyState from '~/ci/runner/components/runner_list_empty_state.vue';

const mockSvgPath = 'mock-svg-path.svg';
const mockFilteredSvgPath = 'mock-filtered-svg-path.svg';
const mockRegistrationToken = 'REGISTRATION_TOKEN';

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

  const findEmptyState = () => wrapper.findComponent(GlEmptyState);
  const findLink = () => wrapper.findComponent(GlLink);
  const findRunnerInstructionsModal = () => wrapper.findComponent(RunnerInstructionsModal);

  const createComponent = ({ props, mountFn = shallowMountExtended } = {}) => {
    wrapper = mountFn(RunnerListEmptyState, {
      propsData: {
        svgPath: mockSvgPath,
        filteredSvgPath: mockFilteredSvgPath,
        registrationToken: mockRegistrationToken,
        ...props,
      },
      directives: {
        GlModal: createMockDirective(),
      },
      stubs: {
        GlEmptyState,
        GlSprintf,
        GlLink,
      },
    });
  };

  describe('when search is not filtered', () => {
    const title = s__('Runners|Get started with runners');

    describe('when there is a registration token', () => {
      beforeEach(() => {
        createComponent();
      });

      it('renders an illustration', () => {
        expect(findEmptyState().props('svgPath')).toBe(mockSvgPath);
      });

      it('displays "no results" text with instructions', () => {
        const desc = s__(
          'Runners|Runners are the agents that run your CI/CD jobs. Follow the %{linkStart}installation and registration instructions%{linkEnd} to set up a runner.',
        );

        expect(findEmptyState().text()).toMatchInterpolatedText(`${title} ${desc}`);
      });

      it('opens a runner registration instructions modal with a link', () => {
        const { value } = getBinding(findLink().element, 'gl-modal');

        expect(findRunnerInstructionsModal().props('modalId')).toEqual(value);
      });
    });

    describe('when there is no registration token', () => {
      beforeEach(() => {
        createComponent({ props: { registrationToken: null } });
      });

      it('renders an illustration', () => {
        expect(findEmptyState().props('svgPath')).toBe(mockSvgPath);
      });

      it('displays "no results" text', () => {
        const desc = s__(
          'Runners|Runners are the agents that run your CI/CD jobs. To register new runners, please contact your administrator.',
        );

        expect(findEmptyState().text()).toMatchInterpolatedText(`${title} ${desc}`);
      });

      it('has no registration instructions link', () => {
        expect(findLink().exists()).toBe(false);
      });
    });
  });

  describe('when search is filtered', () => {
    beforeEach(() => {
      createComponent({ props: { isSearchFiltered: true } });
    });

    it('renders a "filtered search" illustration', () => {
      expect(findEmptyState().props('svgPath')).toBe(mockFilteredSvgPath);
    });

    it('displays "no filtered results" text', () => {
      expect(findEmptyState().text()).toContain(s__('Runners|No results found'));
      expect(findEmptyState().text()).toContain(s__('Runners|Edit your search and try again'));
    });
  });
});