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
|
import { GlToast } from '@gitlab/ui';
import Vue from 'vue';
import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
import RegistrationToken from '~/ci/runner/components/registration/registration_token.vue';
import InputCopyToggleVisibility from '~/vue_shared/components/form/input_copy_toggle_visibility.vue';
import { mockRegistrationToken } from '../../mock_data';
describe('RegistrationToken', () => {
let wrapper;
const showToastMock = jest.fn();
Vue.use(GlToast);
const findInputCopyToggleVisibility = () => wrapper.findComponent(InputCopyToggleVisibility);
const createComponent = ({ props = {}, mountFn = shallowMountExtended, ...options } = {}) => {
wrapper = mountFn(RegistrationToken, {
propsData: {
value: mockRegistrationToken,
inputId: 'token-value',
...props,
},
...options,
mocks: {
$toast: {
show: showToastMock,
},
},
});
};
it('Displays value and copy button', () => {
createComponent();
expect(findInputCopyToggleVisibility().props('value')).toBe(mockRegistrationToken);
expect(findInputCopyToggleVisibility().props('copyButtonTitle')).toBe(
'Copy registration token',
);
});
it('Renders readonly input', () => {
createComponent();
expect(findInputCopyToggleVisibility().props('readonly')).toBe(true);
});
// Component integration test to ensure secure masking
it('Displays masked value as password input by default', () => {
const mockToken = '0123456789';
createComponent({
props: {
value: mockToken,
},
mountFn: mountExtended,
});
expect(wrapper.find('input').element.type).toBe('password');
});
describe('When the copy to clipboard button is clicked', () => {
beforeEach(() => {
createComponent();
});
it('shows a copied message', () => {
findInputCopyToggleVisibility().vm.$emit('copy');
expect(showToastMock).toHaveBeenCalledTimes(1);
expect(showToastMock).toHaveBeenCalledWith('Registration token copied!');
});
it('emits a copy event', () => {
findInputCopyToggleVisibility().vm.$emit('copy');
expect(wrapper.emitted('copy')).toHaveLength(1);
});
});
describe('When slots are used', () => {
const slotName = 'label-description';
const slotContent = 'Label Description';
beforeEach(() => {
createComponent({
slots: {
[slotName]: slotContent,
},
});
});
it('passes slots to the input component', () => {
expect(findInputCopyToggleVisibility().text()).toBe(slotContent);
});
});
});
|