2021-09-04 01:27:46 +05:30
|
|
|
import { GlBanner } from '@gitlab/ui';
|
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
|
|
|
|
import UpgradeBanner, {
|
|
|
|
SECURITY_UPGRADE_BANNER,
|
|
|
|
UPGRADE_OR_FREE_TRIAL,
|
|
|
|
} from '~/security_configuration/components/upgrade_banner.vue';
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
const upgradePath = '/upgrade';
|
|
|
|
|
|
|
|
describe('UpgradeBanner component', () => {
|
|
|
|
let wrapper;
|
|
|
|
let closeSpy;
|
2022-04-04 11:22:00 +05:30
|
|
|
let primarySpy;
|
|
|
|
let trackingSpy;
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
const createComponent = (propsData) => {
|
|
|
|
closeSpy = jest.fn();
|
2022-04-04 11:22:00 +05:30
|
|
|
primarySpy = jest.fn();
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
wrapper = shallowMountExtended(UpgradeBanner, {
|
|
|
|
provide: {
|
|
|
|
upgradePath,
|
|
|
|
},
|
|
|
|
propsData,
|
|
|
|
listeners: {
|
|
|
|
close: closeSpy,
|
2022-04-04 11:22:00 +05:30
|
|
|
primary: primarySpy,
|
2021-09-04 01:27:46 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const findGlBanner = () => wrapper.findComponent(GlBanner);
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
const expectTracking = (action, label) => {
|
|
|
|
return expect(trackingSpy).toHaveBeenCalledWith(undefined, action, {
|
|
|
|
label,
|
|
|
|
property: SECURITY_UPGRADE_BANNER,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
beforeEach(() => {
|
2022-04-04 11:22:00 +05:30
|
|
|
trackingSpy = mockTracking(undefined, undefined, jest.spyOn);
|
2021-09-04 01:27:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2022-04-04 11:22:00 +05:30
|
|
|
unmockTracking();
|
2021-09-04 01:27:46 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
describe('when the component renders', () => {
|
|
|
|
it('tracks an event', () => {
|
|
|
|
expect(trackingSpy).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expectTracking('render', SECURITY_UPGRADE_BANNER);
|
2021-09-04 01:27:46 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
describe('when ready', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
trackingSpy.mockClear();
|
|
|
|
});
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('passes the expected props to GlBanner', () => {
|
|
|
|
expect(findGlBanner().props()).toMatchObject({
|
|
|
|
title: UpgradeBanner.i18n.title,
|
|
|
|
buttonText: UpgradeBanner.i18n.buttonText,
|
|
|
|
buttonLink: upgradePath,
|
|
|
|
});
|
|
|
|
});
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('renders the list of benefits', () => {
|
|
|
|
const wrapperText = wrapper.text();
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(wrapperText).toContain('Immediately begin risk analysis and remediation');
|
|
|
|
expect(wrapperText).toContain('statistics in the merge request');
|
|
|
|
expect(wrapperText).toContain('statistics across projects');
|
|
|
|
expect(wrapperText).toContain('Runtime security metrics');
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(wrapperText).toContain('More scan types, including DAST,');
|
2022-04-04 11:22:00 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('when user interacts', () => {
|
|
|
|
it(`re-emits GlBanner's close event & tracks an event`, () => {
|
|
|
|
expect(closeSpy).not.toHaveBeenCalled();
|
|
|
|
expect(trackingSpy).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
wrapper.findComponent(GlBanner).vm.$emit('close');
|
|
|
|
|
|
|
|
expect(closeSpy).toHaveBeenCalledTimes(1);
|
|
|
|
expectTracking('dismiss_banner', SECURITY_UPGRADE_BANNER);
|
|
|
|
});
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it(`re-emits GlBanner's primary event & tracks an event`, () => {
|
|
|
|
expect(primarySpy).not.toHaveBeenCalled();
|
|
|
|
expect(trackingSpy).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
wrapper.findComponent(GlBanner).vm.$emit('primary');
|
|
|
|
|
|
|
|
expect(primarySpy).toHaveBeenCalledTimes(1);
|
|
|
|
expectTracking('click_button', UPGRADE_OR_FREE_TRIAL);
|
|
|
|
});
|
|
|
|
});
|
2021-09-04 01:27:46 +05:30
|
|
|
});
|
|
|
|
});
|