diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /spec/frontend/ci/runner/components/registration/registration_token_spec.js | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'spec/frontend/ci/runner/components/registration/registration_token_spec.js')
-rw-r--r-- | spec/frontend/ci/runner/components/registration/registration_token_spec.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/frontend/ci/runner/components/registration/registration_token_spec.js b/spec/frontend/ci/runner/components/registration/registration_token_spec.js new file mode 100644 index 00000000000..d2a51c0d910 --- /dev/null +++ b/spec/frontend/ci/runner/components/registration/registration_token_spec.js @@ -0,0 +1,62 @@ +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'; + +const mockToken = '01234567890'; +const mockMasked = '***********'; + +describe('RegistrationToken', () => { + let wrapper; + let showToast; + + Vue.use(GlToast); + + const findInputCopyToggleVisibility = () => wrapper.findComponent(InputCopyToggleVisibility); + + const createComponent = ({ props = {}, mountFn = shallowMountExtended } = {}) => { + wrapper = mountFn(RegistrationToken, { + propsData: { + value: mockToken, + inputId: 'token-value', + ...props, + }, + }); + + showToast = wrapper.vm.$toast ? jest.spyOn(wrapper.vm.$toast, 'show') : null; + }; + + afterEach(() => { + wrapper.destroy(); + }); + + it('Displays value and copy button', () => { + createComponent(); + + expect(findInputCopyToggleVisibility().props('value')).toBe(mockToken); + expect(findInputCopyToggleVisibility().props('copyButtonTitle')).toBe( + 'Copy registration token', + ); + }); + + // Component integration test to ensure secure masking + it('Displays masked value by default', () => { + createComponent({ mountFn: mountExtended }); + + expect(wrapper.find('input').element.value).toBe(mockMasked); + }); + + describe('When the copy to clipboard button is clicked', () => { + beforeEach(() => { + createComponent(); + }); + + it('shows a copied message', () => { + findInputCopyToggleVisibility().vm.$emit('copy'); + + expect(showToast).toHaveBeenCalledTimes(1); + expect(showToast).toHaveBeenCalledWith('Registration token copied!'); + }); + }); +}); |