Commit 2125a2c4 authored by Anna Vovchenko's avatar Anna Vovchenko Committed by Olena Horal-Koretska

Upsell the GitLab Terraform feature - tracking

parent 84c13147
...@@ -3,6 +3,10 @@ import { GlBanner } from '@gitlab/ui'; ...@@ -3,6 +3,10 @@ import { GlBanner } from '@gitlab/ui';
import { helpPagePath } from '~/helpers/help_page_helper'; import { helpPagePath } from '~/helpers/help_page_helper';
import { setCookie } from '~/lib/utils/common_utils'; import { setCookie } from '~/lib/utils/common_utils';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import Tracking from '~/tracking';
import { EVENT_LABEL, DISMISS_EVENT, CLICK_EVENT } from '../constants';
const trackingMixin = Tracking.mixin({ label: EVENT_LABEL });
export default { export default {
name: 'TerraformNotification', name: 'TerraformNotification',
...@@ -16,6 +20,7 @@ export default { ...@@ -16,6 +20,7 @@ export default {
components: { components: {
GlBanner, GlBanner,
}, },
mixins: [trackingMixin],
inject: ['terraformImagePath', 'bannerDismissedKey'], inject: ['terraformImagePath', 'bannerDismissedKey'],
data() { data() {
return { return {
...@@ -31,6 +36,10 @@ export default { ...@@ -31,6 +36,10 @@ export default {
handleClose() { handleClose() {
setCookie(this.bannerDismissedKey, true); setCookie(this.bannerDismissedKey, true);
this.isVisible = false; this.isVisible = false;
this.track(DISMISS_EVENT);
},
buttonClick() {
this.track(CLICK_EVENT);
}, },
}, },
}; };
...@@ -43,6 +52,7 @@ export default { ...@@ -43,6 +52,7 @@ export default {
:button-link="docsUrl" :button-link="docsUrl"
:svg-path="terraformImagePath" :svg-path="terraformImagePath"
variant="promotion" variant="promotion"
@primary="buttonClick"
@close="handleClose" @close="handleClose"
> >
<p>{{ $options.i18n.description }}</p> <p>{{ $options.i18n.description }}</p>
......
export const EVENT_LABEL = 'terraform_banner';
export const DISMISS_EVENT = 'dismiss_banner';
export const CLICK_EVENT = 'click_button';
import { GlBanner } from '@gitlab/ui'; import { GlBanner } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
import { setCookie, parseBoolean } from '~/lib/utils/common_utils'; import { setCookie, parseBoolean } from '~/lib/utils/common_utils';
import TerraformNotification from '~/projects/terraform_notification/components/terraform_notification.vue'; import TerraformNotification from '~/projects/terraform_notification/components/terraform_notification.vue';
import {
EVENT_LABEL,
DISMISS_EVENT,
CLICK_EVENT,
} from '~/projects/terraform_notification/constants';
jest.mock('~/lib/utils/common_utils'); jest.mock('~/lib/utils/common_utils');
...@@ -10,6 +16,7 @@ const bannerDismissedKey = 'terraform_notification_dismissed'; ...@@ -10,6 +16,7 @@ const bannerDismissedKey = 'terraform_notification_dismissed';
describe('TerraformNotificationBanner', () => { describe('TerraformNotificationBanner', () => {
let wrapper; let wrapper;
let trackingSpy;
const provideData = { const provideData = {
terraformImagePath, terraformImagePath,
...@@ -22,11 +29,13 @@ describe('TerraformNotificationBanner', () => { ...@@ -22,11 +29,13 @@ describe('TerraformNotificationBanner', () => {
provide: provideData, provide: provideData,
stubs: { GlBanner }, stubs: { GlBanner },
}); });
trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
}); });
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
parseBoolean.mockReturnValue(false); parseBoolean.mockReturnValue(false);
unmockTracking();
}); });
describe('when the dismiss cookie is not set', () => { describe('when the dismiss cookie is not set', () => {
...@@ -44,8 +53,26 @@ describe('TerraformNotificationBanner', () => { ...@@ -44,8 +53,26 @@ describe('TerraformNotificationBanner', () => {
expect(setCookie).toHaveBeenCalledWith(bannerDismissedKey, true); expect(setCookie).toHaveBeenCalledWith(bannerDismissedKey, true);
}); });
it('should send the dismiss event', () => {
expect(trackingSpy).toHaveBeenCalledWith(undefined, DISMISS_EVENT, {
label: EVENT_LABEL,
});
});
it('should remove the banner', () => { it('should remove the banner', () => {
expect(findBanner().exists()).toBe(false); expect(findBanner().exists()).toBe(false);
}); });
}); });
describe('when docs link is clicked', () => {
beforeEach(async () => {
await findBanner().vm.$emit('primary');
});
it('should send button click event', () => {
expect(trackingSpy).toHaveBeenCalledWith(undefined, CLICK_EVENT, {
label: EVENT_LABEL,
});
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment