2021-02-14 13:09:20 -05:00
|
|
|
import { GlSprintf, GlModal, GlLink } from '@gitlab/ui';
|
2020-02-24 16:09:08 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import Cookies from 'js-cookie';
|
2021-01-11 07:10:41 -05:00
|
|
|
import { stubComponent } from 'helpers/stub_component';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { mockTracking, triggerEvent, unmockTracking } from 'helpers/tracking_helper';
|
2020-08-17 17:09:56 -04:00
|
|
|
import pipelineTourSuccess from '~/blob/pipeline_tour_success_modal.vue';
|
2020-03-31 14:07:42 -04:00
|
|
|
import modalProps from './pipeline_tour_success_mock_data';
|
2020-02-24 16:09:08 -05:00
|
|
|
|
|
|
|
describe('PipelineTourSuccessModal', () => {
|
|
|
|
let wrapper;
|
|
|
|
let cookieSpy;
|
2020-03-31 14:07:42 -04:00
|
|
|
let trackingSpy;
|
2020-02-24 16:09:08 -05:00
|
|
|
|
2020-12-24 04:10:15 -05:00
|
|
|
const GlEmoji = { template: '<img/>' };
|
2020-08-26 14:11:43 -04:00
|
|
|
const createComponent = () => {
|
2020-02-24 16:09:08 -05:00
|
|
|
wrapper = shallowMount(pipelineTourSuccess, {
|
2020-03-31 14:07:42 -04:00
|
|
|
propsData: modalProps,
|
2020-04-01 11:07:45 -04:00
|
|
|
stubs: {
|
2021-01-11 07:10:41 -05:00
|
|
|
GlModal: stubComponent(GlModal, {
|
|
|
|
template: `
|
|
|
|
<div>
|
|
|
|
<slot name="modal-title"></slot>
|
|
|
|
<slot></slot>
|
|
|
|
<slot name="modal-footer"></slot>
|
|
|
|
</div>`,
|
|
|
|
}),
|
2020-07-17 20:09:34 -04:00
|
|
|
GlSprintf,
|
2020-12-24 04:10:15 -05:00
|
|
|
GlEmoji,
|
2020-04-01 11:07:45 -04:00
|
|
|
},
|
2020-02-24 16:09:08 -05:00
|
|
|
});
|
2020-08-26 14:11:43 -04:00
|
|
|
};
|
2020-02-24 16:09:08 -05:00
|
|
|
|
2020-08-26 14:11:43 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
document.body.dataset.page = 'projects:blob:show';
|
|
|
|
trackingSpy = mockTracking('_category_', undefined, jest.spyOn);
|
2020-02-24 16:09:08 -05:00
|
|
|
cookieSpy = jest.spyOn(Cookies, 'remove');
|
2020-08-26 14:11:43 -04:00
|
|
|
createComponent();
|
2020-02-24 16:09:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
2020-03-31 14:07:42 -04:00
|
|
|
unmockTracking();
|
2020-08-26 14:11:43 -04:00
|
|
|
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', () => {
|
|
|
|
const goToMrBtn = wrapper.find({ ref: 'goToMergeRequest' });
|
|
|
|
|
|
|
|
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', () => {
|
|
|
|
const goToMrBtn = wrapper.find({ ref: 'goToMergeRequest' });
|
|
|
|
|
|
|
|
expect(goToMrBtn.attributes('href')).toBe(expectedMrPath);
|
|
|
|
});
|
2020-02-24 16:09:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('has expected structure', () => {
|
|
|
|
const modal = wrapper.find(GlModal);
|
|
|
|
const sprintf = modal.find(GlSprintf);
|
2020-12-24 04:10:15 -05:00
|
|
|
const emoji = modal.find(GlEmoji);
|
2020-02-24 16:09:08 -05:00
|
|
|
|
2020-10-19 05:08:58 -04:00
|
|
|
expect(wrapper.text()).toContain("That's it, well done!");
|
2020-02-24 16:09:08 -05:00
|
|
|
expect(sprintf.exists()).toBe(true);
|
2020-10-19 05:08:58 -04:00
|
|
|
expect(emoji.exists()).toBe(true);
|
2020-02-24 16:09:08 -05:00
|
|
|
});
|
|
|
|
|
2020-07-17 20:09:34 -04:00
|
|
|
it('renders the link for codeQualityLink', () => {
|
2020-11-09 16:08:48 -05:00
|
|
|
expect(wrapper.find(GlLink).attributes('href')).toBe('/code-quality-link');
|
2020-07-17 20:09:34 -04:00
|
|
|
});
|
|
|
|
|
2020-02-24 16:09:08 -05:00
|
|
|
it('calls to remove cookie', () => {
|
|
|
|
wrapper.vm.disableModalFromRenderingAgain();
|
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
expect(cookieSpy).toHaveBeenCalledWith(modalProps.commitCookie);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('tracking', () => {
|
2020-04-01 11:07:45 -04:00
|
|
|
it('send event for basic view of modal', () => {
|
2020-03-31 14:07:42 -04:00
|
|
|
expect(trackingSpy).toHaveBeenCalledWith(undefined, undefined, {
|
|
|
|
label: 'congratulate_first_pipeline',
|
|
|
|
property: modalProps.humanAccess,
|
|
|
|
});
|
|
|
|
});
|
2020-04-01 11:07:45 -04:00
|
|
|
|
|
|
|
it('send an event when go to pipelines is clicked', () => {
|
|
|
|
trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
|
2020-08-26 14:11:43 -04:00
|
|
|
const goToBtn = wrapper.find({ ref: 'goToPipelines' });
|
2020-04-01 11:07:45 -04:00
|
|
|
triggerEvent(goToBtn.element);
|
|
|
|
|
|
|
|
expect(trackingSpy).toHaveBeenCalledWith('_category_', 'click_button', {
|
|
|
|
label: 'congratulate_first_pipeline',
|
|
|
|
property: modalProps.humanAccess,
|
|
|
|
value: '10',
|
|
|
|
});
|
|
|
|
});
|
2020-08-26 14:11:43 -04:00
|
|
|
|
|
|
|
it('sends an event when back to the merge request is clicked', () => {
|
|
|
|
trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
|
|
|
|
const goToBtn = wrapper.find({ ref: 'goToMergeRequest' });
|
|
|
|
triggerEvent(goToBtn.element);
|
|
|
|
|
|
|
|
expect(trackingSpy).toHaveBeenCalledWith('_category_', 'click_button', {
|
|
|
|
label: 'congratulate_first_pipeline',
|
|
|
|
property: modalProps.humanAccess,
|
|
|
|
value: '20',
|
|
|
|
});
|
|
|
|
});
|
2020-02-24 16:09:08 -05:00
|
|
|
});
|
|
|
|
});
|