Commit 12e19a78 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch '37910-refactor-tracking-code-in-container-registry' into 'master'

Resolve "Refactor tracking code in container registry"

Closes #37910

See merge request gitlab-org/gitlab!21029
parents 94020485 f17ba11d
...@@ -31,7 +31,7 @@ export default { ...@@ -31,7 +31,7 @@ export default {
GlTooltip: GlTooltipDirective, GlTooltip: GlTooltipDirective,
GlModal: GlModalDirective, GlModal: GlModalDirective,
}, },
mixins: [Tracking.mixin({})], mixins: [Tracking.mixin()],
props: { props: {
repo: { repo: {
type: Object, type: Object,
...@@ -43,7 +43,6 @@ export default { ...@@ -43,7 +43,6 @@ export default {
isOpen: false, isOpen: false,
modalId: `confirm-repo-deletion-modal-${this.repo.id}`, modalId: `confirm-repo-deletion-modal-${this.repo.id}`,
tracking: { tracking: {
category: document.body.dataset.page,
label: 'registry_repository_delete', label: 'registry_repository_delete',
}, },
}; };
...@@ -67,7 +66,7 @@ export default { ...@@ -67,7 +66,7 @@ export default {
} }
}, },
handleDeleteRepository() { handleDeleteRepository() {
this.track('confirm_delete', {}); this.track('confirm_delete');
return this.deleteItem(this.repo) return this.deleteItem(this.repo)
.then(() => { .then(() => {
createFlash(__('This container registry has been scheduled for deletion.'), 'notice'); createFlash(__('This container registry has been scheduled for deletion.'), 'notice');
...@@ -103,7 +102,7 @@ export default { ...@@ -103,7 +102,7 @@ export default {
:aria-label="s__('ContainerRegistry|Remove repository')" :aria-label="s__('ContainerRegistry|Remove repository')"
class="js-remove-repo btn-inverted" class="js-remove-repo btn-inverted"
variant="danger" variant="danger"
@click="track('click_button', {})" @click="track('click_button')"
> >
<icon name="remove" /> <icon name="remove" />
</gl-button> </gl-button>
...@@ -132,7 +131,7 @@ export default { ...@@ -132,7 +131,7 @@ export default {
:modal-id="modalId" :modal-id="modalId"
ok-variant="danger" ok-variant="danger"
@ok="handleDeleteRepository" @ok="handleDeleteRepository"
@cancel="track('cancel_delete', {})" @cancel="track('cancel_delete')"
> >
<template v-slot:modal-title>{{ s__('ContainerRegistry|Remove repository') }}</template> <template v-slot:modal-title>{{ s__('ContainerRegistry|Remove repository') }}</template>
<p <p
......
...@@ -23,7 +23,7 @@ export default { ...@@ -23,7 +23,7 @@ export default {
directives: { directives: {
GlTooltip: GlTooltipDirective, GlTooltip: GlTooltipDirective,
}, },
mixins: [timeagoMixin], mixins: [timeagoMixin, Tracking.mixin()],
props: { props: {
repo: { repo: {
type: Object, type: Object,
...@@ -71,9 +71,6 @@ export default { ...@@ -71,9 +71,6 @@ export default {
}, },
methods: { methods: {
...mapActions(['fetchList', 'deleteItem', 'multiDeleteItems']), ...mapActions(['fetchList', 'deleteItem', 'multiDeleteItems']),
track(action) {
Tracking.event(document.body.dataset.page, action, this.tracking);
},
setModalDescription(itemIndex = -1) { setModalDescription(itemIndex = -1) {
if (itemIndex === -1) { if (itemIndex === -1) {
this.modalDescription = sprintf( this.modalDescription = sprintf(
......
...@@ -140,43 +140,33 @@ describe('collapsible registry container', () => { ...@@ -140,43 +140,33 @@ describe('collapsible registry container', () => {
}); });
describe('tracking', () => { describe('tracking', () => {
const category = 'mock_page'; const testTrackingCall = action => {
expect(Tracking.event).toHaveBeenCalledWith(undefined, action, {
label: 'registry_repository_delete',
});
};
beforeEach(() => { beforeEach(() => {
jest.spyOn(Tracking, 'event'); jest.spyOn(Tracking, 'event');
wrapper.vm.deleteItem = jest.fn().mockResolvedValue(); wrapper.vm.deleteItem = jest.fn().mockResolvedValue();
wrapper.vm.fetchRepos = jest.fn(); wrapper.vm.fetchRepos = jest.fn();
wrapper.setData({
tracking: {
...wrapper.vm.tracking,
category,
},
});
}); });
it('send an event when delete button is clicked', () => { it('send an event when delete button is clicked', () => {
const deleteBtn = findDeleteBtn(); const deleteBtn = findDeleteBtn();
deleteBtn.trigger('click'); deleteBtn.trigger('click');
expect(Tracking.event).toHaveBeenCalledWith(category, 'click_button', { testTrackingCall('click_button');
label: 'registry_repository_delete',
category,
});
}); });
it('send an event when cancel is pressed on modal', () => { it('send an event when cancel is pressed on modal', () => {
const deleteModal = findDeleteModal(); const deleteModal = findDeleteModal();
deleteModal.vm.$emit('cancel'); deleteModal.vm.$emit('cancel');
expect(Tracking.event).toHaveBeenCalledWith(category, 'cancel_delete', { testTrackingCall('cancel_delete');
label: 'registry_repository_delete',
category,
});
}); });
it('send an event when confirm is clicked on modal', () => { it('send an event when confirm is clicked on modal', () => {
const deleteModal = findDeleteModal(); const deleteModal = findDeleteModal();
deleteModal.vm.$emit('ok'); deleteModal.vm.$emit('ok');
expect(Tracking.event).toHaveBeenCalledWith(category, 'confirm_delete', { testTrackingCall('confirm_delete');
label: 'registry_repository_delete',
category,
});
}); });
}); });
}); });
...@@ -304,17 +304,14 @@ describe('table registry', () => { ...@@ -304,17 +304,14 @@ describe('table registry', () => {
}); });
describe('event tracking', () => { describe('event tracking', () => {
const mockPageName = 'mock_page'; const testTrackingCall = (action, label = 'registry_tag_delete') => {
expect(Tracking.event).toHaveBeenCalledWith(undefined, action, { label, property: 'foo' });
};
beforeEach(() => { beforeEach(() => {
jest.spyOn(Tracking, 'event'); jest.spyOn(Tracking, 'event');
wrapper.vm.handleSingleDelete = jest.fn(); wrapper.vm.handleSingleDelete = jest.fn();
wrapper.vm.handleMultipleDelete = jest.fn(); wrapper.vm.handleMultipleDelete = jest.fn();
document.body.dataset.page = mockPageName;
});
afterEach(() => {
document.body.dataset.page = null;
}); });
describe('single tag delete', () => { describe('single tag delete', () => {
...@@ -325,29 +322,25 @@ describe('table registry', () => { ...@@ -325,29 +322,25 @@ describe('table registry', () => {
it('send an event when delete button is clicked', () => { it('send an event when delete button is clicked', () => {
const deleteBtn = findDeleteButtonsRow(); const deleteBtn = findDeleteButtonsRow();
deleteBtn.at(0).trigger('click'); deleteBtn.at(0).trigger('click');
expect(Tracking.event).toHaveBeenCalledWith(mockPageName, 'click_button', {
label: 'registry_tag_delete', testTrackingCall('click_button');
property: 'foo',
});
}); });
it('send an event when cancel is pressed on modal', () => { it('send an event when cancel is pressed on modal', () => {
const deleteModal = findDeleteModal(); const deleteModal = findDeleteModal();
deleteModal.vm.$emit('cancel'); deleteModal.vm.$emit('cancel');
expect(Tracking.event).toHaveBeenCalledWith(mockPageName, 'cancel_delete', {
label: 'registry_tag_delete', testTrackingCall('cancel_delete');
property: 'foo',
});
}); });
it('send an event when confirm is clicked on modal', () => { it('send an event when confirm is clicked on modal', () => {
const deleteModal = findDeleteModal(); const deleteModal = findDeleteModal();
deleteModal.vm.$emit('ok'); deleteModal.vm.$emit('ok');
expect(Tracking.event).toHaveBeenCalledWith(mockPageName, 'confirm_delete', { testTrackingCall('confirm_delete');
label: 'registry_tag_delete',
property: 'foo',
});
}); });
}); });
describe('bulk tag delete', () => { describe('bulk tag delete', () => {
beforeEach(() => { beforeEach(() => {
const items = [0, 1, 2]; const items = [0, 1, 2];
...@@ -357,27 +350,22 @@ describe('table registry', () => { ...@@ -357,27 +350,22 @@ describe('table registry', () => {
it('send an event when delete button is clicked', () => { it('send an event when delete button is clicked', () => {
const deleteBtn = findDeleteButton(); const deleteBtn = findDeleteButton();
deleteBtn.vm.$emit('click'); deleteBtn.vm.$emit('click');
expect(Tracking.event).toHaveBeenCalledWith(mockPageName, 'click_button', {
label: 'bulk_registry_tag_delete', testTrackingCall('click_button', 'bulk_registry_tag_delete');
property: 'foo',
});
}); });
it('send an event when cancel is pressed on modal', () => { it('send an event when cancel is pressed on modal', () => {
const deleteModal = findDeleteModal(); const deleteModal = findDeleteModal();
deleteModal.vm.$emit('cancel'); deleteModal.vm.$emit('cancel');
expect(Tracking.event).toHaveBeenCalledWith(mockPageName, 'cancel_delete', {
label: 'bulk_registry_tag_delete', testTrackingCall('cancel_delete', 'bulk_registry_tag_delete');
property: 'foo',
});
}); });
it('send an event when confirm is clicked on modal', () => { it('send an event when confirm is clicked on modal', () => {
const deleteModal = findDeleteModal(); const deleteModal = findDeleteModal();
deleteModal.vm.$emit('ok'); deleteModal.vm.$emit('ok');
expect(Tracking.event).toHaveBeenCalledWith(mockPageName, 'confirm_delete', { testTrackingCall('confirm_delete', 'bulk_registry_tag_delete');
label: 'bulk_registry_tag_delete',
property: 'foo',
});
}); });
}); });
}); });
......
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