2021-03-11 19:13:27 +05:30
|
|
|
import { GlSprintf, GlModal, GlLink } from '@gitlab/ui';
|
2020-04-22 19:07:51 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2022-07-16 23:28:13 +05:30
|
|
|
import Cookies from '~/lib/utils/cookies';
|
2021-03-08 18:12:59 +05:30
|
|
|
import { stubComponent } from 'helpers/stub_component';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mockTracking, triggerEvent, unmockTracking } from 'helpers/tracking_helper';
|
2020-10-24 23:57:45 +05:30
|
|
|
import pipelineTourSuccess from '~/blob/pipeline_tour_success_modal.vue';
|
2020-04-22 19:07:51 +05:30
|
|
|
import modalProps from './pipeline_tour_success_mock_data';
|
|
|
|
|
|
|
|
describe('PipelineTourSuccessModal', () => {
|
|
|
|
let wrapper;
|
|
|
|
let cookieSpy;
|
|
|
|
let trackingSpy;
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const GlEmoji = { template: '<img/>' };
|
2020-11-24 15:15:51 +05:30
|
|
|
const createComponent = () => {
|
2020-04-22 19:07:51 +05:30
|
|
|
wrapper = shallowMount(pipelineTourSuccess, {
|
|
|
|
propsData: modalProps,
|
|
|
|
stubs: {
|
2021-03-08 18:12:59 +05:30
|
|
|
GlModal: stubComponent(GlModal, {
|
|
|
|
template: `
|
|
|
|
<div>
|
|
|
|
<slot name="modal-title"></slot>
|
|
|
|
<slot></slot>
|
|
|
|
<slot name="modal-footer"></slot>
|
|
|
|
</div>`,
|
|
|
|
}),
|
2020-10-24 23:57:45 +05:30
|
|
|
GlSprintf,
|
2021-03-08 18:12:59 +05:30
|
|
|
GlEmoji,
|
2020-04-22 19:07:51 +05:30
|
|
|
},
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
};
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
document.body.dataset.page = 'projects:blob:show';
|
|
|
|
trackingSpy = mockTracking('_category_', undefined, jest.spyOn);
|
2020-04-22 19:07:51 +05:30
|
|
|
cookieSpy = jest.spyOn(Cookies, 'remove');
|
2020-11-24 15:15:51 +05:30
|
|
|
createComponent();
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
unmockTracking();
|
2020-11-24 15:15:51 +05:30
|
|
|
Cookies.remove(modalProps.commitCookie);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when the commitCookie contains the mr path', () => {
|
|
|
|
const expectedMrPath = 'expected_mr_path';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
Cookies.set(modalProps.commitCookie, expectedMrPath);
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the path from the commit cookie for back to the merge request button', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const goToMrBtn = wrapper.findComponent({ ref: 'goToMergeRequest' });
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
expect(goToMrBtn.attributes('href')).toBe(expectedMrPath);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when the commitCookie does not contain mr path', () => {
|
|
|
|
const expectedMrPath = modalProps.projectMergeRequestsPath;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
Cookies.set(modalProps.commitCookie, true);
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the path from projectMergeRequestsPath for back to the merge request button', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const goToMrBtn = wrapper.findComponent({ ref: 'goToMergeRequest' });
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
expect(goToMrBtn.attributes('href')).toBe(expectedMrPath);
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('has expected structure', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const modal = wrapper.findComponent(GlModal);
|
|
|
|
const sprintf = modal.findComponent(GlSprintf);
|
|
|
|
const emoji = modal.findComponent(GlEmoji);
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(wrapper.text()).toContain("That's it, well done!");
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(sprintf.exists()).toBe(true);
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(emoji.exists()).toBe(true);
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('renders the link for codeQualityLink', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(GlLink).attributes('href')).toBe('/code-quality-link');
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it('calls to remove cookie', () => {
|
|
|
|
wrapper.vm.disableModalFromRenderingAgain();
|
|
|
|
|
|
|
|
expect(cookieSpy).toHaveBeenCalledWith(modalProps.commitCookie);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('tracking', () => {
|
|
|
|
it('send event for basic view of modal', () => {
|
|
|
|
expect(trackingSpy).toHaveBeenCalledWith(undefined, undefined, {
|
|
|
|
label: 'congratulate_first_pipeline',
|
|
|
|
property: modalProps.humanAccess,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('send an event when go to pipelines is clicked', () => {
|
|
|
|
trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
|
2022-08-27 11:52:29 +05:30
|
|
|
const goToBtn = wrapper.findComponent({ ref: 'goToPipelines' });
|
2020-04-22 19:07:51 +05:30
|
|
|
triggerEvent(goToBtn.element);
|
|
|
|
|
|
|
|
expect(trackingSpy).toHaveBeenCalledWith('_category_', 'click_button', {
|
|
|
|
label: 'congratulate_first_pipeline',
|
|
|
|
property: modalProps.humanAccess,
|
|
|
|
value: '10',
|
|
|
|
});
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
it('sends an event when back to the merge request is clicked', () => {
|
|
|
|
trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
|
2022-08-27 11:52:29 +05:30
|
|
|
const goToBtn = wrapper.findComponent({ ref: 'goToMergeRequest' });
|
2020-11-24 15:15:51 +05:30
|
|
|
triggerEvent(goToBtn.element);
|
|
|
|
|
|
|
|
expect(trackingSpy).toHaveBeenCalledWith('_category_', 'click_button', {
|
|
|
|
label: 'congratulate_first_pipeline',
|
|
|
|
property: modalProps.humanAccess,
|
|
|
|
value: '20',
|
|
|
|
});
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
});
|