diff options
Diffstat (limited to 'spec/frontend/vue_shared/components/runner_instructions/runner_instructions_modal_spec.js')
-rw-r--r-- | spec/frontend/vue_shared/components/runner_instructions/runner_instructions_modal_spec.js | 67 |
1 files changed, 58 insertions, 9 deletions
diff --git a/spec/frontend/vue_shared/components/runner_instructions/runner_instructions_modal_spec.js b/spec/frontend/vue_shared/components/runner_instructions/runner_instructions_modal_spec.js index 32ef2d27ba7..8536ffed573 100644 --- a/spec/frontend/vue_shared/components/runner_instructions/runner_instructions_modal_spec.js +++ b/spec/frontend/vue_shared/components/runner_instructions/runner_instructions_modal_spec.js @@ -1,4 +1,4 @@ -import { GlAlert, GlButton, GlLoadingIcon, GlSkeletonLoader } from '@gitlab/ui'; +import { GlAlert, GlModal, GlButton, GlLoadingIcon, GlSkeletonLoader } from '@gitlab/ui'; import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils'; import { shallowMount, createLocalVue } from '@vue/test-utils'; import { nextTick } from 'vue'; @@ -52,7 +52,7 @@ describe('RunnerInstructionsModal component', () => { const findBinaryInstructions = () => wrapper.findByTestId('binary-instructions'); const findRegisterCommand = () => wrapper.findByTestId('register-command'); - const createComponent = () => { + const createComponent = ({ props, ...options } = {}) => { const requestHandlers = [ [getRunnerPlatformsQuery, runnerPlatformsHandler], [getRunnerSetupInstructionsQuery, runnerSetupInstructionsHandler], @@ -64,9 +64,12 @@ describe('RunnerInstructionsModal component', () => { shallowMount(RunnerInstructionsModal, { propsData: { modalId: 'runner-instructions-modal', + registrationToken: 'MY_TOKEN', + ...props, }, localVue, apolloProvider: fakeApollo, + ...options, }), ); }; @@ -118,18 +121,30 @@ describe('RunnerInstructionsModal component', () => { expect(instructions).toBe(installInstructions); }); - it('register command is shown', () => { + it('register command is shown with a replaced token', () => { const instructions = findRegisterCommand().text(); - expect(instructions).toBe(registerInstructions); + expect(instructions).toBe( + 'sudo gitlab-runner register --url http://gdk.test:3000/ --registration-token MY_TOKEN', + ); + }); + + describe('when a register token is not shown', () => { + beforeEach(async () => { + createComponent({ props: { registrationToken: undefined } }); + await nextTick(); + }); + + it('register command is shown without a defined registration token', () => { + const instructions = findRegisterCommand().text(); + + expect(instructions).toBe(registerInstructions); + }); }); }); describe('after a platform and architecture are selected', () => { - const { - installInstructions, - registerInstructions, - } = mockGraphqlInstructionsWindows.data.runnerSetup; + const { installInstructions } = mockGraphqlInstructionsWindows.data.runnerSetup; beforeEach(async () => { runnerSetupInstructionsHandler.mockResolvedValue(mockGraphqlInstructionsWindows); @@ -157,7 +172,9 @@ describe('RunnerInstructionsModal component', () => { it('register command is shown', () => { const command = findRegisterCommand().text(); - expect(command).toBe(registerInstructions); + expect(command).toBe( + './gitlab-runner.exe register --url http://gdk.test:3000/ --registration-token MY_TOKEN', + ); }); }); @@ -217,4 +234,36 @@ describe('RunnerInstructionsModal component', () => { expect(findRegisterCommand().exists()).toBe(false); }); }); + + describe('GlModal API', () => { + const getGlModalStub = (methods) => { + return { + ...GlModal, + methods: { + ...GlModal.methods, + ...methods, + }, + }; + }; + + describe('show()', () => { + let mockShow; + + beforeEach(() => { + mockShow = jest.fn(); + + createComponent({ + stubs: { + GlModal: getGlModalStub({ show: mockShow }), + }, + }); + }); + + it('delegates show()', () => { + wrapper.vm.show(); + + expect(mockShow).toHaveBeenCalledTimes(1); + }); + }); + }); }); |