debian-mirror-gitlab/spec/frontend/blob/pipeline_tour_success_modal_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

129 lines
4 KiB
JavaScript
Raw Normal View History

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';
import Cookies from 'js-cookie';
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(() => {
wrapper.destroy();
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', () => {
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-04-22 19:07:51 +05:30
});
it('has expected structure', () => {
const modal = wrapper.find(GlModal);
const sprintf = modal.find(GlSprintf);
2021-03-08 18:12:59 +05:30
const emoji = modal.find(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', () => {
2021-01-29 00:20:46 +05:30
expect(wrapper.find(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);
2020-11-24 15:15:51 +05:30
const goToBtn = wrapper.find({ 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);
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-04-22 19:07:51 +05:30
});
});