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

runner_manual_setup_help_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: effef0e7ebfeb10f48e735ffc2c4ab2225f85376 (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
import { GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { TEST_HOST } from 'helpers/test_constants';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import MaskedValue from '~/runner/components/helpers/masked_value.vue';
import RunnerManualSetupHelp from '~/runner/components/runner_manual_setup_help.vue';
import RunnerRegistrationTokenReset from '~/runner/components/runner_registration_token_reset.vue';
import { INSTANCE_TYPE, GROUP_TYPE, PROJECT_TYPE } from '~/runner/constants';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import RunnerInstructions from '~/vue_shared/components/runner_instructions/runner_instructions.vue';

const mockRegistrationToken = 'MOCK_REGISTRATION_TOKEN';
const mockRunnerInstallHelpPage = 'https://docs.gitlab.com/runner/install/';

describe('RunnerManualSetupHelp', () => {
  let wrapper;
  let originalGon;

  const findRunnerInstructions = () => wrapper.findComponent(RunnerInstructions);
  const findRunnerRegistrationTokenReset = () =>
    wrapper.findComponent(RunnerRegistrationTokenReset);
  const findClipboardButtons = () => wrapper.findAllComponents(ClipboardButton);
  const findRunnerHelpTitle = () => wrapper.findByTestId('runner-help-title');
  const findCoordinatorUrl = () => wrapper.findByTestId('coordinator-url');
  const findRegistrationToken = () => wrapper.findByTestId('registration-token');
  const findRunnerHelpLink = () => wrapper.findByTestId('runner-help-link');

  const createComponent = ({ props = {} } = {}) => {
    wrapper = extendedWrapper(
      shallowMount(RunnerManualSetupHelp, {
        provide: {
          runnerInstallHelpPage: mockRunnerInstallHelpPage,
        },
        propsData: {
          registrationToken: mockRegistrationToken,
          type: INSTANCE_TYPE,
          ...props,
        },
        stubs: {
          MaskedValue,
          GlSprintf,
        },
      }),
    );
  };

  beforeAll(() => {
    originalGon = global.gon;
    global.gon = { gitlab_url: TEST_HOST };
  });

  afterAll(() => {
    global.gon = originalGon;
  });

  beforeEach(() => {
    createComponent();
  });

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

  it('Title contains the shared runner type', () => {
    createComponent({ props: { type: INSTANCE_TYPE } });

    expect(findRunnerHelpTitle().text()).toMatchInterpolatedText('Set up a shared runner manually');
  });

  it('Title contains the group runner type', () => {
    createComponent({ props: { type: GROUP_TYPE } });

    expect(findRunnerHelpTitle().text()).toMatchInterpolatedText('Set up a group runner manually');
  });

  it('Title contains the specific runner type', () => {
    createComponent({ props: { type: PROJECT_TYPE } });

    expect(findRunnerHelpTitle().text()).toMatchInterpolatedText(
      'Set up a specific runner manually',
    );
  });

  it('Runner Install Page link', () => {
    expect(findRunnerHelpLink().attributes('href')).toBe(mockRunnerInstallHelpPage);
  });

  it('Displays the coordinator URL token', () => {
    expect(findCoordinatorUrl().text()).toBe(TEST_HOST);
    expect(findClipboardButtons().at(0).props('text')).toBe(TEST_HOST);
  });

  it('Displays the runner instructions', () => {
    expect(findRunnerInstructions().exists()).toBe(true);
  });

  it('Displays the registration token', async () => {
    findRegistrationToken().find('[data-testid="toggle-masked"]').vm.$emit('click');

    await nextTick();

    expect(findRegistrationToken().text()).toBe(mockRegistrationToken);
    expect(findClipboardButtons().at(1).props('text')).toBe(mockRegistrationToken);
  });

  it('Displays the runner registration token reset button', () => {
    expect(findRunnerRegistrationTokenReset().exists()).toBe(true);
  });

  it('Replaces the runner reset button', async () => {
    const mockNewRegistrationToken = 'NEW_MOCK_REGISTRATION_TOKEN';

    findRegistrationToken().find('[data-testid="toggle-masked"]').vm.$emit('click');
    findRunnerRegistrationTokenReset().vm.$emit('tokenReset', mockNewRegistrationToken);

    await nextTick();

    expect(findRegistrationToken().text()).toBe(mockNewRegistrationToken);
    expect(findClipboardButtons().at(1).props('text')).toBe(mockNewRegistrationToken);
  });
});