summaryrefslogtreecommitdiff
path: root/spec/frontend/security_configuration/components/upgrade_banner_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/security_configuration/components/upgrade_banner_spec.js')
-rw-r--r--spec/frontend/security_configuration/components/upgrade_banner_spec.js85
1 files changed, 66 insertions, 19 deletions
diff --git a/spec/frontend/security_configuration/components/upgrade_banner_spec.js b/spec/frontend/security_configuration/components/upgrade_banner_spec.js
index a35fded72fb..ff44acfc4f9 100644
--- a/spec/frontend/security_configuration/components/upgrade_banner_spec.js
+++ b/spec/frontend/security_configuration/components/upgrade_banner_spec.js
@@ -1,15 +1,22 @@
import { GlBanner } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
-import UpgradeBanner from '~/security_configuration/components/upgrade_banner.vue';
+import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
+import UpgradeBanner, {
+ SECURITY_UPGRADE_BANNER,
+ UPGRADE_OR_FREE_TRIAL,
+} from '~/security_configuration/components/upgrade_banner.vue';
const upgradePath = '/upgrade';
describe('UpgradeBanner component', () => {
let wrapper;
let closeSpy;
+ let primarySpy;
+ let trackingSpy;
const createComponent = (propsData) => {
closeSpy = jest.fn();
+ primarySpy = jest.fn();
wrapper = shallowMountExtended(UpgradeBanner, {
provide: {
@@ -18,43 +25,83 @@ describe('UpgradeBanner component', () => {
propsData,
listeners: {
close: closeSpy,
+ primary: primarySpy,
},
});
};
const findGlBanner = () => wrapper.findComponent(GlBanner);
+ const expectTracking = (action, label) => {
+ return expect(trackingSpy).toHaveBeenCalledWith(undefined, action, {
+ label,
+ property: SECURITY_UPGRADE_BANNER,
+ });
+ };
+
beforeEach(() => {
- createComponent();
+ trackingSpy = mockTracking(undefined, undefined, jest.spyOn);
});
afterEach(() => {
wrapper.destroy();
+ unmockTracking();
});
- it('passes the expected props to GlBanner', () => {
- expect(findGlBanner().props()).toMatchObject({
- title: UpgradeBanner.i18n.title,
- buttonText: UpgradeBanner.i18n.buttonText,
- buttonLink: upgradePath,
+ describe('when the component renders', () => {
+ it('tracks an event', () => {
+ expect(trackingSpy).not.toHaveBeenCalled();
+
+ createComponent();
+
+ expectTracking('render', SECURITY_UPGRADE_BANNER);
});
});
- it('renders the list of benefits', () => {
- const wrapperText = wrapper.text();
+ describe('when ready', () => {
+ beforeEach(() => {
+ createComponent();
+ trackingSpy.mockClear();
+ });
- 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');
- expect(wrapperText).toContain('More scan types, including Container Scanning,');
- });
+ it('passes the expected props to GlBanner', () => {
+ expect(findGlBanner().props()).toMatchObject({
+ title: UpgradeBanner.i18n.title,
+ buttonText: UpgradeBanner.i18n.buttonText,
+ buttonLink: upgradePath,
+ });
+ });
- it(`re-emits GlBanner's close event`, () => {
- expect(closeSpy).not.toHaveBeenCalled();
+ it('renders the list of benefits', () => {
+ const wrapperText = wrapper.text();
- wrapper.findComponent(GlBanner).vm.$emit('close');
+ 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');
+ expect(wrapperText).toContain('More scan types, including Container Scanning,');
+ });
+
+ 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);
+ });
- expect(closeSpy).toHaveBeenCalledTimes(1);
+ 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);
+ });
+ });
});
});