2020-03-04 09:08:20 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import Popover from '~/blob/suggest_gitlab_ci_yml/components/popover.vue';
|
2020-04-06 09:09:17 +00:00
|
|
|
import { mockTracking, unmockTracking, triggerEvent } from 'helpers/tracking_helper';
|
2020-03-09 18:07:59 +00:00
|
|
|
import * as utils from '~/lib/utils/common_utils';
|
2020-08-11 18:10:06 +00:00
|
|
|
import { GlButton } from '@gitlab/ui';
|
2020-03-04 09:08:20 +00:00
|
|
|
|
2020-03-09 18:07:59 +00:00
|
|
|
jest.mock('~/lib/utils/common_utils', () => ({
|
|
|
|
...jest.requireActual('~/lib/utils/common_utils'),
|
|
|
|
scrollToElement: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
|
|
|
const target = 'gitlab-ci-yml-selector';
|
2020-03-25 09:08:11 +00:00
|
|
|
const dismissKey = '99';
|
2020-03-09 18:07:59 +00:00
|
|
|
const defaultTrackLabel = 'suggest_gitlab_ci_yml';
|
2020-03-12 21:09:45 +00:00
|
|
|
const commitTrackLabel = 'suggest_commit_first_project_gitlab_ci_yml';
|
2020-03-25 09:08:11 +00:00
|
|
|
|
|
|
|
const dismissCookie = 'suggest_gitlab_ci_yml_99';
|
2020-03-12 21:09:45 +00:00
|
|
|
const humanAccess = 'owner';
|
2020-03-04 09:08:20 +00:00
|
|
|
|
|
|
|
describe('Suggest gitlab-ci.yml Popover', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2020-03-09 18:07:59 +00:00
|
|
|
function createWrapper(trackLabel) {
|
2020-03-04 09:08:20 +00:00
|
|
|
wrapper = shallowMount(Popover, {
|
|
|
|
propsData: {
|
2020-03-09 18:07:59 +00:00
|
|
|
target,
|
|
|
|
trackLabel,
|
2020-03-04 09:08:20 +00:00
|
|
|
dismissKey,
|
2020-03-12 21:09:45 +00:00
|
|
|
humanAccess,
|
2020-03-04 09:08:20 +00:00
|
|
|
},
|
2020-04-06 09:09:17 +00:00
|
|
|
stubs: {
|
|
|
|
'gl-popover': '<div><slot name="title"></slot><slot></slot></div>',
|
|
|
|
},
|
2020-03-04 09:08:20 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when no dismiss cookie is set', () => {
|
|
|
|
beforeEach(() => {
|
2020-03-09 18:07:59 +00:00
|
|
|
createWrapper(defaultTrackLabel);
|
2020-03-04 09:08:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('sets popoverDismissed to false', () => {
|
|
|
|
expect(wrapper.vm.popoverDismissed).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when the dismiss cookie is set', () => {
|
|
|
|
beforeEach(() => {
|
2020-03-25 09:08:11 +00:00
|
|
|
utils.setCookie(dismissCookie, true);
|
|
|
|
|
2020-03-09 18:07:59 +00:00
|
|
|
createWrapper(defaultTrackLabel);
|
2020-03-04 09:08:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('sets popoverDismissed to true', () => {
|
|
|
|
expect(wrapper.vm.popoverDismissed).toEqual(true);
|
|
|
|
});
|
2020-03-09 18:07:59 +00:00
|
|
|
|
2020-03-12 21:09:45 +00:00
|
|
|
afterEach(() => {
|
2020-03-25 09:08:11 +00:00
|
|
|
utils.removeCookie(dismissCookie);
|
2020-03-09 18:07:59 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-12 21:09:45 +00:00
|
|
|
describe('tracking', () => {
|
|
|
|
let trackingSpy;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-05-07 06:09:38 +00:00
|
|
|
document.body.dataset.page = 'projects:blob:new';
|
|
|
|
trackingSpy = mockTracking('_category_', undefined, jest.spyOn);
|
|
|
|
|
2020-03-12 21:09:45 +00:00
|
|
|
createWrapper(commitTrackLabel);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
unmockTracking();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sends a tracking event with the expected properties for the popover being viewed', () => {
|
|
|
|
const expectedCategory = undefined;
|
|
|
|
const expectedAction = undefined;
|
|
|
|
const expectedLabel = 'suggest_commit_first_project_gitlab_ci_yml';
|
|
|
|
const expectedProperty = 'owner';
|
|
|
|
|
|
|
|
expect(trackingSpy).toHaveBeenCalledWith(expectedCategory, expectedAction, {
|
|
|
|
label: expectedLabel,
|
|
|
|
property: expectedProperty,
|
|
|
|
});
|
|
|
|
});
|
2020-04-06 09:09:17 +00:00
|
|
|
|
|
|
|
it('sends a tracking event when the popover is dismissed', () => {
|
|
|
|
const expectedLabel = commitTrackLabel;
|
|
|
|
const expectedAction = 'click_button';
|
|
|
|
const expectedProperty = 'owner';
|
|
|
|
const expectedValue = '10';
|
2020-08-11 18:10:06 +00:00
|
|
|
const dismissButton = wrapper.find(GlButton);
|
2020-05-07 06:09:38 +00:00
|
|
|
trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
|
2020-04-06 09:09:17 +00:00
|
|
|
|
|
|
|
triggerEvent(dismissButton.element);
|
|
|
|
|
|
|
|
expect(trackingSpy).toHaveBeenCalledWith('_category_', expectedAction, {
|
|
|
|
label: expectedLabel,
|
|
|
|
property: expectedProperty,
|
|
|
|
value: expectedValue,
|
|
|
|
});
|
|
|
|
});
|
2020-03-12 21:09:45 +00:00
|
|
|
});
|
|
|
|
|
2020-03-09 18:07:59 +00:00
|
|
|
describe('when the popover is mounted with the trackLabel of the Confirm button popover at the bottom of the page', () => {
|
|
|
|
it('calls scrollToElement so that the Confirm button and popover will be in sight', () => {
|
|
|
|
const scrollToElementSpy = jest.spyOn(utils, 'scrollToElement');
|
|
|
|
|
|
|
|
createWrapper(commitTrackLabel);
|
|
|
|
|
|
|
|
expect(scrollToElementSpy).toHaveBeenCalled();
|
|
|
|
});
|
2020-03-04 09:08:20 +00:00
|
|
|
});
|
|
|
|
});
|