summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/runner_instructions/runner_instructions_spec.js
blob: afbcee506c7875793cf39953eec28d81a445f881 (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
import { shallowMount, createLocalVue } from '@vue/test-utils';
import VueApollo from 'vue-apollo';
import createMockApollo from 'jest/helpers/mock_apollo_helper';
import RunnerInstructions from '~/vue_shared/components/runner_instructions/runner_instructions.vue';
import getRunnerPlatforms from '~/vue_shared/components/runner_instructions/graphql/queries/get_runner_platforms.query.graphql';
import getRunnerSetupInstructions from '~/vue_shared/components/runner_instructions/graphql/queries/get_runner_setup.query.graphql';

import { mockGraphqlRunnerPlatforms, mockGraphqlInstructions } from './mock_data';

const projectPath = 'gitlab-org/gitlab';
const localVue = createLocalVue();
localVue.use(VueApollo);

describe('RunnerInstructions component', () => {
  let wrapper;
  let fakeApollo;

  const findModalButton = () => wrapper.find('[data-testid="show-modal-button"]');
  const findPlatformButtons = () => wrapper.findAll('[data-testid="platform-button"]');
  const findArchitectureDropdownItems = () =>
    wrapper.findAll('[data-testid="architecture-dropdown-item"]');
  const findBinaryInstructionsSection = () => wrapper.find('[data-testid="binary-instructions"]');
  const findRunnerInstructionsSection = () => wrapper.find('[data-testid="runner-instructions"]');

  beforeEach(() => {
    const requestHandlers = [
      [getRunnerPlatforms, jest.fn().mockResolvedValue(mockGraphqlRunnerPlatforms)],
      [getRunnerSetupInstructions, jest.fn().mockResolvedValue(mockGraphqlInstructions)],
    ];

    fakeApollo = createMockApollo(requestHandlers);

    wrapper = shallowMount(RunnerInstructions, {
      provide: {
        projectPath,
      },
      localVue,
      apolloProvider: fakeApollo,
    });
  });

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

  it('should show the "Show Runner installation instructions" button', () => {
    const button = findModalButton();

    expect(button.exists()).toBe(true);
    expect(button.text()).toBe('Show Runner installation instructions');
  });

  it('should contain a number of platforms buttons', () => {
    const buttons = findPlatformButtons();

    expect(buttons).toHaveLength(mockGraphqlRunnerPlatforms.data.runnerPlatforms.nodes.length);
  });

  it('should contain a number of dropdown items for the architecture options', () => {
    const platformButton = findPlatformButtons().at(0);
    platformButton.vm.$emit('click');

    return wrapper.vm.$nextTick(() => {
      const dropdownItems = findArchitectureDropdownItems();

      expect(dropdownItems).toHaveLength(
        mockGraphqlRunnerPlatforms.data.runnerPlatforms.nodes[0].architectures.nodes.length,
      );
    });
  });

  it('should display the binary installation instructions for a selected architecture', async () => {
    const platformButton = findPlatformButtons().at(0);
    platformButton.vm.$emit('click');

    await wrapper.vm.$nextTick();

    const dropdownItem = findArchitectureDropdownItems().at(0);
    dropdownItem.vm.$emit('click');

    await wrapper.vm.$nextTick();

    const runner = findBinaryInstructionsSection();

    expect(runner.text()).toEqual(
      expect.stringContaining('sudo chmod +x /usr/local/bin/gitlab-runner'),
    );
    expect(runner.text()).toEqual(
      expect.stringContaining(
        `sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash`,
      ),
    );
    expect(runner.text()).toEqual(
      expect.stringContaining(
        'sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner',
      ),
    );
    expect(runner.text()).toEqual(expect.stringContaining('sudo gitlab-runner start'));
  });

  it('should display the runner register instructions for a selected architecture', async () => {
    const platformButton = findPlatformButtons().at(0);
    platformButton.vm.$emit('click');

    await wrapper.vm.$nextTick();

    const dropdownItem = findArchitectureDropdownItems().at(0);
    dropdownItem.vm.$emit('click');

    await wrapper.vm.$nextTick();

    const runner = findRunnerInstructionsSection();

    expect(runner.text()).toEqual(
      expect.stringContaining(mockGraphqlInstructions.data.runnerSetup.registerInstructions),
    );
  });
});