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
|
import { GlSprintf } from '@gitlab/ui';
import { s__ } from '~/locale';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { createAlert, VARIANT_SUCCESS } from '~/alert';
import GroupRunnerRunnerApp from '~/ci/runner/group_new_runner/group_new_runner_app.vue';
import { saveAlertToLocalStorage } from '~/ci/runner/local_storage_alert/save_alert_to_local_storage';
import RunnerPlatformsRadioGroup from '~/ci/runner/components/runner_platforms_radio_group.vue';
import {
PARAM_KEY_PLATFORM,
GROUP_TYPE,
DEFAULT_PLATFORM,
WINDOWS_PLATFORM,
} from '~/ci/runner/constants';
import RunnerCreateForm from '~/ci/runner/components/runner_create_form.vue';
import { redirectTo } from '~/lib/utils/url_utility';
import { runnerCreateResult } from '../mock_data';
const mockGroupId = 'gid://gitlab/Group/72';
jest.mock('~/ci/runner/local_storage_alert/save_alert_to_local_storage');
jest.mock('~/alert');
jest.mock('~/lib/utils/url_utility', () => ({
...jest.requireActual('~/lib/utils/url_utility'),
redirectTo: jest.fn(),
}));
const mockCreatedRunner = runnerCreateResult.data.runnerCreate.runner;
describe('GroupRunnerRunnerApp', () => {
let wrapper;
const findRunnerPlatformsRadioGroup = () => wrapper.findComponent(RunnerPlatformsRadioGroup);
const findRunnerCreateForm = () => wrapper.findComponent(RunnerCreateForm);
const createComponent = () => {
wrapper = shallowMountExtended(GroupRunnerRunnerApp, {
propsData: {
groupId: mockGroupId,
},
stubs: {
GlSprintf,
},
});
};
beforeEach(() => {
createComponent();
});
describe('Platform', () => {
it('shows the platforms radio group', () => {
expect(findRunnerPlatformsRadioGroup().props('value')).toBe(DEFAULT_PLATFORM);
});
});
describe('Runner form', () => {
it('shows the runner create form for an instance runner', () => {
expect(findRunnerCreateForm().props()).toEqual({
runnerType: GROUP_TYPE,
groupId: mockGroupId,
projectId: null,
});
});
describe('When a runner is saved', () => {
beforeEach(() => {
findRunnerCreateForm().vm.$emit('saved', mockCreatedRunner);
});
it('pushes an alert to be shown after redirection', () => {
expect(saveAlertToLocalStorage).toHaveBeenCalledWith({
message: s__('Runners|Runner created.'),
variant: VARIANT_SUCCESS,
});
});
it('redirects to the registration page', () => {
const url = `${mockCreatedRunner.ephemeralRegisterUrl}?${PARAM_KEY_PLATFORM}=${DEFAULT_PLATFORM}`;
expect(redirectTo).toHaveBeenCalledWith(url);
});
});
describe('When another platform is selected and a runner is saved', () => {
beforeEach(() => {
findRunnerPlatformsRadioGroup().vm.$emit('input', WINDOWS_PLATFORM);
findRunnerCreateForm().vm.$emit('saved', mockCreatedRunner);
});
it('redirects to the registration page with the platform', () => {
const url = `${mockCreatedRunner.ephemeralRegisterUrl}?${PARAM_KEY_PLATFORM}=${WINDOWS_PLATFORM}`;
expect(redirectTo).toHaveBeenCalledWith(url);
});
});
describe('When runner fails to save', () => {
const ERROR_MSG = 'Cannot save!';
beforeEach(() => {
findRunnerCreateForm().vm.$emit('error', new Error(ERROR_MSG));
});
it('shows an error message', () => {
expect(createAlert).toHaveBeenCalledWith({ message: ERROR_MSG });
});
});
});
});
|