debian-mirror-gitlab/spec/frontend/runner/components/registration/registration_token_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-12-11 22:18:48 +05:30
import { GlToast } from '@gitlab/ui';
2022-08-27 11:52:29 +05:30
import Vue from 'vue';
2022-06-21 17:19:12 +05:30
import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
2021-12-11 22:18:48 +05:30
import RegistrationToken from '~/runner/components/registration/registration_token.vue';
2022-06-21 17:19:12 +05:30
import InputCopyToggleVisibility from '~/vue_shared/components/form/input_copy_toggle_visibility.vue';
2021-12-11 22:18:48 +05:30
const mockToken = '01234567890';
const mockMasked = '***********';
describe('RegistrationToken', () => {
let wrapper;
let showToast;
2022-08-27 11:52:29 +05:30
Vue.use(GlToast);
2021-12-11 22:18:48 +05:30
2022-08-27 11:52:29 +05:30
const findInputCopyToggleVisibility = () => wrapper.findComponent(InputCopyToggleVisibility);
2021-12-11 22:18:48 +05:30
2022-08-27 11:52:29 +05:30
const createComponent = ({ props = {}, mountFn = shallowMountExtended } = {}) => {
2022-06-21 17:19:12 +05:30
wrapper = mountFn(RegistrationToken, {
2022-04-04 11:22:00 +05:30
propsData: {
value: mockToken,
2022-07-23 23:45:48 +05:30
inputId: 'token-value',
2022-04-04 11:22:00 +05:30
...props,
},
});
2021-12-11 22:18:48 +05:30
showToast = wrapper.vm.$toast ? jest.spyOn(wrapper.vm.$toast, 'show') : null;
};
afterEach(() => {
wrapper.destroy();
});
2022-06-21 17:19:12 +05:30
it('Displays value and copy button', () => {
createComponent();
2021-12-11 22:18:48 +05:30
2022-06-21 17:19:12 +05:30
expect(findInputCopyToggleVisibility().props('value')).toBe(mockToken);
expect(findInputCopyToggleVisibility().props('copyButtonTitle')).toBe(
'Copy registration token',
);
2021-12-11 22:18:48 +05:30
});
2022-06-21 17:19:12 +05:30
// Component integration test to ensure secure masking
it('Displays masked value by default', () => {
createComponent({ mountFn: mountExtended });
expect(wrapper.find('input').element.value).toBe(mockMasked);
2021-12-11 22:18:48 +05:30
});
2022-06-21 17:19:12 +05:30
describe('When the copy to clipboard button is clicked', () => {
2021-12-11 22:18:48 +05:30
beforeEach(() => {
2022-06-21 17:19:12 +05:30
createComponent();
2021-12-11 22:18:48 +05:30
});
it('shows a copied message', () => {
2022-06-21 17:19:12 +05:30
findInputCopyToggleVisibility().vm.$emit('copy');
2021-12-11 22:18:48 +05:30
expect(showToast).toHaveBeenCalledTimes(1);
expect(showToast).toHaveBeenCalledWith('Registration token copied!');
});
});
});