Commit c50790c1 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Fix `view_alert_integrations_list` Snowplow event

parent 13a73325
......@@ -92,7 +92,17 @@ export default {
};
},
mounted() {
this.trackPageViews();
const callback = entries => {
const isVisible = entries.some(entry => entry.isIntersecting);
if (isVisible) {
this.trackPageViews();
this.observer.disconnect();
}
};
this.observer = new IntersectionObserver(callback);
this.observer.observe(this.$el);
},
methods: {
tbodyTrClass(item) {
......
---
title: Fix alerts integration list Snowplow tracking event
merge_request: 47413
author:
type: fixed
import { GlTable, GlIcon, GlButton } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import { useMockIntersectionObserver } from 'helpers/mock_dom_observer';
import Tracking from '~/tracking';
import AlertIntegrationsList, {
i18n,
......@@ -23,6 +24,7 @@ const mockIntegrations = [
describe('AlertIntegrationsList', () => {
let wrapper;
const { trigger: triggerIntersection } = useMockIntersectionObserver();
function mountComponent({ data = {}, props = {} } = {}) {
wrapper = mount(AlertIntegrationsList, {
......@@ -100,12 +102,23 @@ describe('AlertIntegrationsList', () => {
describe('Snowplow tracking', () => {
beforeEach(() => {
jest.spyOn(Tracking, 'event');
mountComponent();
jest.spyOn(Tracking, 'event');
});
it('should NOT track alert list page views when list is collapsed', () => {
triggerIntersection(wrapper.vm.$el, { entry: { isIntersecting: false } });
expect(Tracking.event).not.toHaveBeenCalled();
});
it('should track alert list page views', () => {
it('should track alert list page views only once when list is expanded', () => {
triggerIntersection(wrapper.vm.$el, { entry: { isIntersecting: true } });
triggerIntersection(wrapper.vm.$el, { entry: { isIntersecting: true } });
triggerIntersection(wrapper.vm.$el, { entry: { isIntersecting: true } });
const { category, action } = trackAlertIntegrationsViewsOptions;
expect(Tracking.event).toHaveBeenCalledTimes(1);
expect(Tracking.event).toHaveBeenCalledWith(category, action);
});
});
......
......@@ -3,6 +3,7 @@ import { mount, createLocalVue } from '@vue/test-utils';
import createMockApollo from 'jest/helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import { GlLoadingIcon, GlAlert } from '@gitlab/ui';
import { useMockIntersectionObserver } from 'helpers/mock_dom_observer';
import AlertsSettingsWrapper from '~/alerts_settings/components/alerts_settings_wrapper.vue';
import AlertsSettingsFormOld from '~/alerts_settings/components/alerts_settings_form_old.vue';
import AlertsSettingsFormNew from '~/alerts_settings/components/alerts_settings_form_new.vue';
......@@ -47,6 +48,7 @@ describe('AlertsSettingsWrapper', () => {
let wrapper;
let fakeApollo;
let destroyIntegrationHandler;
useMockIntersectionObserver();
const findLoader = () => wrapper.find(IntegrationsList).find(GlLoadingIcon);
const findIntegrations = () => wrapper.find(IntegrationsList).findAll('table tbody tr');
......
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