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
|
import { GlAlert, GlFormInputGroup, GlSprintf, GlLink, GlIcon } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { sprintf } from '~/locale';
import AgentToken from '~/clusters_list/components/agent_token.vue';
import {
I18N_AGENT_TOKEN,
INSTALL_AGENT_MODAL_ID,
NAME_MAX_LENGTH,
HELM_VERSION_POLICY_URL,
} from '~/clusters_list/constants';
import { generateAgentRegistrationCommand } from '~/clusters_list/clusters_util';
import CodeBlock from '~/vue_shared/components/code_block.vue';
import ModalCopyButton from '~/vue_shared/components/modal_copy_button.vue';
const kasAddress = 'kas.example.com';
const agentName = 'my-agent';
const agentToken = 'agent-token';
const kasVersion = '15.0.0';
const modalId = INSTALL_AGENT_MODAL_ID;
describe('InstallAgentModal', () => {
let wrapper;
const findAlert = () => wrapper.findComponent(GlAlert);
const findCodeBlock = () => wrapper.findComponent(CodeBlock);
const findCopyButton = () => wrapper.findComponent(ModalCopyButton);
const findInput = () => wrapper.findComponent(GlFormInputGroup);
const findHelmVersionPolicyLink = () => wrapper.findComponent(GlLink);
const findHelmExternalLinkIcon = () => wrapper.findComponent(GlIcon);
const createWrapper = (newAgentName = agentName) => {
const provide = {
kasAddress,
kasVersion,
};
const propsData = {
agentName: newAgentName,
agentToken,
modalId,
};
wrapper = shallowMountExtended(AgentToken, {
provide,
propsData,
stubs: {
GlSprintf,
},
});
};
beforeEach(() => {
createWrapper();
});
describe('initial state', () => {
it('shows basic agent installation instructions', () => {
expect(wrapper.text()).toContain(I18N_AGENT_TOKEN.basicInstallTitle);
expect(wrapper.text()).toContain(I18N_AGENT_TOKEN.basicInstallBody);
});
it('shows Helm version policy text with an external link', () => {
expect(wrapper.text()).toContain(
sprintf(I18N_AGENT_TOKEN.helmVersionText, { linkStart: '', linkEnd: ' ' }),
);
expect(findHelmVersionPolicyLink().attributes()).toMatchObject({
href: HELM_VERSION_POLICY_URL,
target: '_blank',
});
expect(findHelmExternalLinkIcon().props()).toMatchObject({ name: 'external-link', size: 12 });
});
it('shows advanced agent installation instructions', () => {
expect(wrapper.text()).toContain(I18N_AGENT_TOKEN.advancedInstallTitle);
});
it('shows agent token as an input value', () => {
expect(findInput().props('value')).toBe(agentToken);
});
it('renders a copy button', () => {
expect(findCopyButton().props()).toMatchObject({
title: 'Copy command',
text: generateAgentRegistrationCommand({
name: agentName,
token: agentToken,
version: kasVersion,
address: kasAddress,
}),
modalId,
});
});
it('shows warning alert', () => {
expect(findAlert().text()).toBe(I18N_AGENT_TOKEN.tokenSingleUseWarningTitle);
});
it('shows code block with agent installation command', () => {
expect(findCodeBlock().props('code')).toContain(`helm upgrade --install ${agentName}`);
expect(findCodeBlock().props('code')).toContain(`--namespace gitlab-agent-${agentName}`);
expect(findCodeBlock().props('code')).toContain(`--set config.token=${agentToken}`);
expect(findCodeBlock().props('code')).toContain(`--set config.kasAddress=${kasAddress}`);
expect(findCodeBlock().props('code')).toContain(`--set image.tag=v${kasVersion}`);
});
it('truncates the namespace name if it exceeds the maximum length', () => {
const newAgentName = 'agent-name-that-is-too-long-and-needs-to-be-truncated-to-use';
createWrapper(newAgentName);
expect(findCodeBlock().props('code')).toContain(
`--namespace gitlab-agent-${newAgentName.substring(0, NAME_MAX_LENGTH)}`,
);
});
});
});
|