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

runner_list_empty_state_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: 22797433b58608e5ff5f888896cc559c64b63ddb (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import EMPTY_STATE_SVG_URL from '@gitlab/svgs/dist/illustrations/empty-state/empty-pipeline-md.svg?url';
import FILTERED_SVG_URL from '@gitlab/svgs/dist/illustrations/empty-state/empty-search-md.svg?url';
import { GlEmptyState, GlLink, GlSprintf } from '@gitlab/ui';
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 {
  I18N_GET_STARTED,
  I18N_RUNNERS_ARE_AGENTS,
  I18N_CREATE_RUNNER_LINK,
  I18N_STILL_USING_REGISTRATION_TOKENS,
  I18N_CONTACT_ADMIN_TO_REGISTER,
  I18N_FOLLOW_REGISTRATION_INSTRUCTIONS,
  I18N_NO_RESULTS,
  I18N_EDIT_YOUR_SEARCH,
} from '~/ci/runner/constants';

import {
  mockRegistrationToken,
  newRunnerPath as mockNewRunnerPath,
} from 'jest/ci/runner/mock_data';

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

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

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

  const expectTitleToBe = (title) => {
    expect(findEmptyState().find('h1').text()).toBe(title);
  };
  const expectDescriptionToBe = (sentences) => {
    expect(findEmptyState().find('p').text()).toMatchInterpolatedText(sentences.join(' '));
  };

  const createComponent = ({ props, mountFn = shallowMountExtended } = {}) => {
    wrapper = mountFn(RunnerListEmptyState, {
      propsData: {
        ...props,
      },
      directives: {
        GlModal: createMockDirective('gl-modal'),
      },
      stubs: {
        GlEmptyState,
        GlSprintf,
      },
      provide: { glFeatures },
    });
  };

  beforeEach(() => {
    glFeatures = null;
  });

  describe('when search is not filtered', () => {
    describe.each([
      { createRunnerWorkflowForAdmin: true },
      { createRunnerWorkflowForNamespace: true },
    ])('when createRunnerWorkflow is enabled by %o', (currentGlFeatures) => {
      beforeEach(() => {
        glFeatures = currentGlFeatures;
      });

      describe.each`
        newRunnerPath        | registrationToken        | expectedMessages
        ${mockNewRunnerPath} | ${mockRegistrationToken} | ${[I18N_CREATE_RUNNER_LINK, I18N_STILL_USING_REGISTRATION_TOKENS]}
        ${mockNewRunnerPath} | ${null}                  | ${[I18N_CREATE_RUNNER_LINK]}
        ${null}              | ${mockRegistrationToken} | ${[I18N_STILL_USING_REGISTRATION_TOKENS]}
        ${null}              | ${null}                  | ${[I18N_CONTACT_ADMIN_TO_REGISTER]}
      `(
        'when newRunnerPath is $newRunnerPath and registrationToken is $registrationToken',
        ({ newRunnerPath, registrationToken, expectedMessages }) => {
          beforeEach(() => {
            createComponent({
              props: {
                newRunnerPath,
                registrationToken,
              },
            });
          });

          it('shows title', () => {
            expectTitleToBe(I18N_GET_STARTED);
          });

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

          it(`shows description: "${expectedMessages.join(' ')}"`, () => {
            expectDescriptionToBe([I18N_RUNNERS_ARE_AGENTS, ...expectedMessages]);
          });
        },
      );

      describe('with newRunnerPath and registration token', () => {
        beforeEach(() => {
          createComponent({
            props: {
              registrationToken: mockRegistrationToken,
              newRunnerPath: mockNewRunnerPath,
            },
          });
        });

        it('shows links to the new runner page and registration instructions', () => {
          expect(findLinks().at(0).attributes('href')).toBe(mockNewRunnerPath);

          const { value } = getBinding(findLinks().at(1).element, 'gl-modal');
          expect(findRunnerInstructionsModal().props('modalId')).toEqual(value);
        });
      });

      describe('with newRunnerPath and no registration token', () => {
        beforeEach(() => {
          createComponent({
            props: {
              registrationToken: mockRegistrationToken,
              newRunnerPath: null,
            },
          });
        });

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

      describe('with no newRunnerPath nor registration token', () => {
        beforeEach(() => {
          createComponent({
            props: {
              registrationToken: null,
              newRunnerPath: null,
            },
          });
        });

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

    describe('when createRunnerWorkflow is disabled', () => {
      describe('when there is a registration token', () => {
        beforeEach(() => {
          createComponent({
            props: {
              registrationToken: mockRegistrationToken,
            },
          });
        });

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

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

        it('displays text with registration instructions', () => {
          expectTitleToBe(I18N_GET_STARTED);

          expectDescriptionToBe([I18N_RUNNERS_ARE_AGENTS, I18N_FOLLOW_REGISTRATION_INSTRUCTIONS]);
        });
      });

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

        it('displays "contact admin" text', () => {
          expectTitleToBe(I18N_GET_STARTED);

          expectDescriptionToBe([I18N_RUNNERS_ARE_AGENTS, I18N_CONTACT_ADMIN_TO_REGISTER]);
        });

        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(FILTERED_SVG_URL);
    });

    it('displays "no filtered results" text', () => {
      expectTitleToBe(I18N_NO_RESULTS);

      expectDescriptionToBe([I18N_EDIT_YOUR_SEARCH]);
    });
  });
});