Commit 0f861504 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch...

Merge branch '198525-tag-expiration-track-of-clicks-of-save-and-cancel-to-understand-how-users-are-interacting' into 'master'

Add event tracking to buttons in Docker container expiration settings

See merge request gitlab-org/gitlab!23844
parents 7d47ea84 3bd5b7d1
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
GlLoadingIcon, GlLoadingIcon,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { s__, __, sprintf } from '~/locale'; import { s__, __, sprintf } from '~/locale';
import Tracking from '~/tracking';
import { import {
NAME_REGEX_LENGTH, NAME_REGEX_LENGTH,
UPDATE_SETTINGS_ERROR_MESSAGE, UPDATE_SETTINGS_ERROR_MESSAGE,
...@@ -27,10 +28,18 @@ export default { ...@@ -27,10 +28,18 @@ export default {
GlCard, GlCard,
GlLoadingIcon, GlLoadingIcon,
}, },
mixins: [Tracking.mixin()],
labelsConfig: { labelsConfig: {
cols: 3, cols: 3,
align: 'right', align: 'right',
}, },
data() {
return {
tracking: {
label: 'docker_container_retention_and_expiration_policies',
},
};
},
computed: { computed: {
...mapState(['formOptions', 'isLoading']), ...mapState(['formOptions', 'isLoading']),
...mapComputed( ...mapComputed(
...@@ -86,7 +95,12 @@ export default { ...@@ -86,7 +95,12 @@ export default {
}, },
methods: { methods: {
...mapActions(['resetSettings', 'saveSettings']), ...mapActions(['resetSettings', 'saveSettings']),
reset() {
this.track('reset_form');
this.resetSettings();
},
submit() { submit() {
this.track('submit_form');
this.saveSettings() this.saveSettings()
.then(() => this.$toast.show(UPDATE_SETTINGS_SUCCESS_MESSAGE, { type: 'success' })) .then(() => this.$toast.show(UPDATE_SETTINGS_SUCCESS_MESSAGE, { type: 'success' }))
.catch(() => this.$toast.show(UPDATE_SETTINGS_ERROR_MESSAGE, { type: 'error' })); .catch(() => this.$toast.show(UPDATE_SETTINGS_ERROR_MESSAGE, { type: 'error' }));
...@@ -96,7 +110,7 @@ export default { ...@@ -96,7 +110,7 @@ export default {
</script> </script>
<template> <template>
<form ref="form-element" @submit.prevent="submit" @reset.prevent="resetSettings"> <form ref="form-element" @submit.prevent="submit" @reset.prevent="reset">
<gl-card> <gl-card>
<template #header> <template #header>
{{ s__('ContainerRegistry|Tag expiration policy') }} {{ s__('ContainerRegistry|Tag expiration policy') }}
......
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import Tracking from '~/tracking';
import stubChildren from 'helpers/stub_children'; import stubChildren from 'helpers/stub_children';
import component from '~/registry/settings/components/settings_form.vue'; import component from '~/registry/settings/components/settings_form.vue';
import { createStore } from '~/registry/settings/store/'; import { createStore } from '~/registry/settings/store/';
...@@ -15,6 +16,9 @@ describe('Settings Form', () => { ...@@ -15,6 +16,9 @@ describe('Settings Form', () => {
let dispatchSpy; let dispatchSpy;
const FORM_ELEMENTS_ID_PREFIX = '#expiration-policy'; const FORM_ELEMENTS_ID_PREFIX = '#expiration-policy';
const trackingPayload = {
label: 'docker_container_retention_and_expiration_policies',
};
const GlLoadingIcon = { name: 'gl-loading-icon-stub', template: '<svg></svg>' }; const GlLoadingIcon = { name: 'gl-loading-icon-stub', template: '<svg></svg>' };
...@@ -48,6 +52,7 @@ describe('Settings Form', () => { ...@@ -48,6 +52,7 @@ describe('Settings Form', () => {
store.dispatch('setInitialState', stringifiedFormOptions); store.dispatch('setInitialState', stringifiedFormOptions);
dispatchSpy = jest.spyOn(store, 'dispatch'); dispatchSpy = jest.spyOn(store, 'dispatch');
mountComponent(); mountComponent();
jest.spyOn(Tracking, 'event');
}); });
afterEach(() => { afterEach(() => {
...@@ -118,15 +123,23 @@ describe('Settings Form', () => { ...@@ -118,15 +123,23 @@ describe('Settings Form', () => {
beforeEach(() => { beforeEach(() => {
form = findForm(); form = findForm();
}); });
it('cancel has type reset', () => {
describe('form cancel event', () => {
it('has type reset', () => {
expect(findCancelButton().attributes('type')).toBe('reset'); expect(findCancelButton().attributes('type')).toBe('reset');
}); });
it('form reset event call the appropriate function', () => { it('calls the appropriate function', () => {
dispatchSpy.mockReturnValue();
form.trigger('reset');
expect(dispatchSpy).toHaveBeenCalledWith('resetSettings');
});
it('tracks the reset event', () => {
dispatchSpy.mockReturnValue(); dispatchSpy.mockReturnValue();
form.trigger('reset'); form.trigger('reset');
// expect.any(Object) is necessary because the event payload is passed to the function expect(Tracking.event).toHaveBeenCalledWith(undefined, 'reset_form', trackingPayload);
expect(dispatchSpy).toHaveBeenCalledWith('resetSettings', expect.any(Object)); });
}); });
it('save has type submit', () => { it('save has type submit', () => {
...@@ -177,6 +190,12 @@ describe('Settings Form', () => { ...@@ -177,6 +190,12 @@ describe('Settings Form', () => {
expect(dispatchSpy).toHaveBeenCalledWith('saveSettings'); expect(dispatchSpy).toHaveBeenCalledWith('saveSettings');
}); });
it('tracks the submit event', () => {
dispatchSpy.mockResolvedValue();
form.trigger('submit');
expect(Tracking.event).toHaveBeenCalledWith(undefined, 'submit_form', trackingPayload);
});
it('show a success toast when submit succeed', () => { it('show a success toast when submit succeed', () => {
dispatchSpy.mockResolvedValue(); dispatchSpy.mockResolvedValue();
form.trigger('submit'); form.trigger('submit');
......
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