2021-10-22 14:13:20 -04:00
|
|
|
import { GlDropdown, GlDropdownItem, GlDropdownForm } from '@gitlab/ui';
|
2022-01-20 13:14:18 -05:00
|
|
|
import { createLocalVue, createWrapper } from '@vue/test-utils';
|
2021-10-22 14:13:20 -04:00
|
|
|
import { nextTick } from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
2022-01-20 13:14:18 -05:00
|
|
|
import { shallowMountExtended, mountExtended } from 'helpers/vue_test_utils_helper';
|
2021-10-22 14:13:20 -04:00
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
|
|
|
|
import RegistrationDropdown from '~/runner/components/registration/registration_dropdown.vue';
|
|
|
|
import RegistrationTokenResetDropdownItem from '~/runner/components/registration/registration_token_reset_dropdown_item.vue';
|
|
|
|
|
|
|
|
import { INSTANCE_TYPE, GROUP_TYPE, PROJECT_TYPE } from '~/runner/constants';
|
|
|
|
|
|
|
|
import getRunnerPlatformsQuery from '~/vue_shared/components/runner_instructions/graphql/queries/get_runner_platforms.query.graphql';
|
|
|
|
import getRunnerSetupInstructionsQuery from '~/vue_shared/components/runner_instructions/graphql/queries/get_runner_setup.query.graphql';
|
|
|
|
|
|
|
|
import {
|
|
|
|
mockGraphqlRunnerPlatforms,
|
|
|
|
mockGraphqlInstructions,
|
|
|
|
} from 'jest/vue_shared/components/runner_instructions/mock_data';
|
|
|
|
|
|
|
|
const mockToken = '0123456789';
|
|
|
|
const maskToken = '**********';
|
|
|
|
|
|
|
|
describe('RegistrationDropdown', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const findDropdown = () => wrapper.findComponent(GlDropdown);
|
|
|
|
|
|
|
|
const findRegistrationInstructionsDropdownItem = () => wrapper.findComponent(GlDropdownItem);
|
|
|
|
const findTokenDropdownItem = () => wrapper.findComponent(GlDropdownForm);
|
|
|
|
const findTokenResetDropdownItem = () =>
|
|
|
|
wrapper.findComponent(RegistrationTokenResetDropdownItem);
|
|
|
|
|
|
|
|
const findToggleMaskButton = () => wrapper.findByTestId('toggle-masked');
|
|
|
|
|
2022-01-20 13:14:18 -05:00
|
|
|
const createComponent = ({ props = {}, ...options } = {}, mountFn = shallowMountExtended) => {
|
|
|
|
wrapper = mountFn(RegistrationDropdown, {
|
|
|
|
propsData: {
|
|
|
|
registrationToken: mockToken,
|
|
|
|
type: INSTANCE_TYPE,
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
...options,
|
|
|
|
});
|
2021-10-22 14:13:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
type | text
|
|
|
|
${INSTANCE_TYPE} | ${'Register an instance runner'}
|
|
|
|
${GROUP_TYPE} | ${'Register a group runner'}
|
|
|
|
${PROJECT_TYPE} | ${'Register a project runner'}
|
|
|
|
`('Dropdown text for type $type is "$text"', () => {
|
2022-01-20 13:14:18 -05:00
|
|
|
createComponent({ props: { type: INSTANCE_TYPE } }, mountExtended);
|
2021-10-22 14:13:20 -04:00
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('Register an instance runner');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Passes attributes to the dropdown component', () => {
|
|
|
|
createComponent({ attrs: { right: true } });
|
|
|
|
|
|
|
|
expect(findDropdown().attributes()).toMatchObject({ right: 'true' });
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Instructions dropdown item', () => {
|
|
|
|
it('Displays "Show runner" dropdown item', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findRegistrationInstructionsDropdownItem().text()).toBe(
|
|
|
|
'Show runner installation and registration instructions',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When the dropdown item is clicked', () => {
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(VueApollo);
|
|
|
|
|
|
|
|
const requestHandlers = [
|
|
|
|
[getRunnerPlatformsQuery, jest.fn().mockResolvedValue(mockGraphqlRunnerPlatforms)],
|
|
|
|
[getRunnerSetupInstructionsQuery, jest.fn().mockResolvedValue(mockGraphqlInstructions)],
|
|
|
|
];
|
|
|
|
|
|
|
|
const findModalInBody = () =>
|
|
|
|
createWrapper(document.body).find('[data-testid="runner-instructions-modal"]');
|
|
|
|
|
2022-01-24 16:14:06 -05:00
|
|
|
beforeEach(async () => {
|
2021-10-22 14:13:20 -04:00
|
|
|
createComponent(
|
|
|
|
{
|
|
|
|
localVue,
|
|
|
|
// Mock load modal contents from API
|
|
|
|
apolloProvider: createMockApollo(requestHandlers),
|
|
|
|
// Use `attachTo` to find the modal
|
|
|
|
attachTo: document.body,
|
|
|
|
},
|
2022-01-20 13:14:18 -05:00
|
|
|
mountExtended,
|
2021-10-22 14:13:20 -04:00
|
|
|
);
|
|
|
|
|
2022-01-24 16:14:06 -05:00
|
|
|
await findRegistrationInstructionsDropdownItem().trigger('click');
|
2021-10-22 14:13:20 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('opens the modal with contents', () => {
|
|
|
|
const modalText = findModalInBody()
|
|
|
|
.text()
|
|
|
|
.replace(/[\n\t\s]+/g, ' ');
|
|
|
|
|
|
|
|
expect(modalText).toContain('Install a runner');
|
|
|
|
|
|
|
|
// Environment selector
|
|
|
|
expect(modalText).toContain('Environment');
|
|
|
|
expect(modalText).toContain('Linux macOS Windows Docker Kubernetes');
|
|
|
|
|
|
|
|
// Architecture selector
|
|
|
|
expect(modalText).toContain('Architecture');
|
|
|
|
expect(modalText).toContain('amd64 amd64 386 arm arm64');
|
|
|
|
|
|
|
|
expect(modalText).toContain('Download and install binary');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Registration token', () => {
|
|
|
|
it('Displays dropdown form for the registration token', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findTokenDropdownItem().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Displays masked value by default', () => {
|
2022-01-20 13:14:18 -05:00
|
|
|
createComponent({}, mountExtended);
|
2021-10-22 14:13:20 -04:00
|
|
|
|
|
|
|
expect(findTokenDropdownItem().text()).toMatchInterpolatedText(
|
|
|
|
`Registration token ${maskToken}`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Reset token item', () => {
|
|
|
|
it('Displays registration token reset item', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findTokenResetDropdownItem().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each([INSTANCE_TYPE, GROUP_TYPE, PROJECT_TYPE])('Set up token reset for %s', (type) => {
|
|
|
|
createComponent({ props: { type } });
|
|
|
|
|
|
|
|
expect(findTokenResetDropdownItem().props('type')).toBe(type);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Updates the token when it gets reset', async () => {
|
2022-01-20 13:14:18 -05:00
|
|
|
createComponent({}, mountExtended);
|
2021-10-22 14:13:20 -04:00
|
|
|
|
|
|
|
const newToken = 'mock1';
|
|
|
|
|
|
|
|
findTokenResetDropdownItem().vm.$emit('tokenReset', newToken);
|
|
|
|
findToggleMaskButton().vm.$emit('click', { stopPropagation: jest.fn() });
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(findTokenDropdownItem().text()).toMatchInterpolatedText(
|
|
|
|
`Registration token ${newToken}`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|