diff options
Diffstat (limited to 'spec/frontend/vue_shared/components/runner_aws_deployments/runner_aws_deployments_modal_spec.js')
-rw-r--r-- | spec/frontend/vue_shared/components/runner_aws_deployments/runner_aws_deployments_modal_spec.js | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/spec/frontend/vue_shared/components/runner_aws_deployments/runner_aws_deployments_modal_spec.js b/spec/frontend/vue_shared/components/runner_aws_deployments/runner_aws_deployments_modal_spec.js index ad692a38e65..a9ba4946358 100644 --- a/spec/frontend/vue_shared/components/runner_aws_deployments/runner_aws_deployments_modal_spec.js +++ b/spec/frontend/vue_shared/components/runner_aws_deployments/runner_aws_deployments_modal_spec.js @@ -1,27 +1,29 @@ -import { GlLink } from '@gitlab/ui'; +import { GlModal, GlFormRadio } from '@gitlab/ui'; import { shallowMount } from '@vue/test-utils'; -import ExperimentTracking from '~/experimentation/experiment_tracking'; -import { getBaseURL } from '~/lib/utils/url_utility'; +import { getBaseURL, visitUrl } from '~/lib/utils/url_utility'; +import { mockTracking } from 'helpers/tracking_helper'; import { - EXPERIMENT_NAME, CF_BASE_URL, TEMPLATES_BASE_URL, EASY_BUTTONS, } from '~/vue_shared/components/runner_aws_deployments/constants'; import RunnerAwsDeploymentsModal from '~/vue_shared/components/runner_aws_deployments/runner_aws_deployments_modal.vue'; -jest.mock('~/experimentation/experiment_tracking'); +jest.mock('~/lib/utils/url_utility', () => ({ + ...jest.requireActual('~/lib/utils/url_utility'), + visitUrl: jest.fn(), +})); describe('RunnerAwsDeploymentsModal', () => { let wrapper; - const findEasyButtons = () => wrapper.findAllComponents(GlLink); + const findModal = () => wrapper.findComponent(GlModal); + const findEasyButtons = () => wrapper.findAllComponents(GlFormRadio); const createComponent = () => { wrapper = shallowMount(RunnerAwsDeploymentsModal, { propsData: { modalId: 'runner-aws-deployments-modal', - imgSrc: '/assets/aws-cloud-formation.png', }, }); }; @@ -43,34 +45,30 @@ describe('RunnerAwsDeploymentsModal', () => { }); describe('first easy button', () => { - const findFirstButton = () => findEasyButtons().at(0); - it('should contain the correct description', () => { - expect(findFirstButton().text()).toBe(EASY_BUTTONS[0].description); + expect(findEasyButtons().at(0).text()).toContain(EASY_BUTTONS[0].description); }); it('should contain the correct link', () => { - const link = findFirstButton().attributes('href'); + const templateUrl = encodeURIComponent(TEMPLATES_BASE_URL + EASY_BUTTONS[0].templateName); + const { stackName } = EASY_BUTTONS[0]; + const instanceUrl = encodeURIComponent(getBaseURL()); + const url = `${CF_BASE_URL}templateURL=${templateUrl}&stackName=${stackName}¶m_3GITLABRunnerInstanceURL=${instanceUrl}`; + + findModal().vm.$emit('primary'); - expect(link.startsWith(CF_BASE_URL)).toBe(true); - expect( - link.includes( - `templateURL=${encodeURIComponent(TEMPLATES_BASE_URL + EASY_BUTTONS[0].templateName)}`, - ), - ).toBe(true); - expect(link.includes(`stackName=${EASY_BUTTONS[0].stackName}`)).toBe(true); - expect( - link.includes(`param_3GITLABRunnerInstanceURL=${encodeURIComponent(getBaseURL())}`), - ).toBe(true); + expect(visitUrl).toHaveBeenCalledWith(url, true); }); it('should track an event when clicked', () => { - findFirstButton().vm.$emit('click'); + const trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn); + + findModal().vm.$emit('primary'); - expect(ExperimentTracking).toHaveBeenCalledWith(EXPERIMENT_NAME); - expect(ExperimentTracking.prototype.event).toHaveBeenCalledWith( - `template_clicked_${EASY_BUTTONS[0].stackName}`, - ); + expect(trackingSpy).toHaveBeenCalledTimes(1); + expect(trackingSpy).toHaveBeenCalledWith(undefined, 'template_clicked', { + label: EASY_BUTTONS[0].stackName, + }); }); }); }); |