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