diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-19 21:06:29 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-19 21:06:29 +0000 |
commit | b35b9ac7e2fd4a707ea9291eb57769c690403b4c (patch) | |
tree | ae746b64cc7d3a19926e6d4a39a5daeb990a4154 /spec/javascripts | |
parent | 81f7adf08b4557c38ac2ef1c730e72e07db2f1a3 (diff) | |
download | gitlab-ce-b35b9ac7e2fd4a707ea9291eb57769c690403b4c.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/javascripts')
6 files changed, 56 insertions, 19 deletions
diff --git a/spec/javascripts/helpers/tracking_helper.js b/spec/javascripts/helpers/tracking_helper.js new file mode 100644 index 00000000000..68c1bd2dbca --- /dev/null +++ b/spec/javascripts/helpers/tracking_helper.js @@ -0,0 +1,25 @@ +import Tracking from '~/tracking'; + +export default Tracking; + +let document; +let handlers; + +export function mockTracking(category = '_category_', documentOverride, spyMethod) { + document = documentOverride || window.document; + window.snowplow = () => {}; + Tracking.bindDocument(category, document); + return spyMethod ? spyMethod(Tracking, 'event') : null; +} + +export function unmockTracking() { + window.snowplow = undefined; + handlers.forEach(event => document.removeEventListener(event.name, event.func)); +} + +export function triggerEvent(selectorOrEl, eventName = 'click') { + const event = new Event(eventName, { bubbles: true }); + const el = typeof selectorOrEl === 'string' ? document.querySelector(selectorOrEl) : selectorOrEl; + + el.dispatchEvent(event); +} diff --git a/spec/javascripts/integrations/integration_settings_form_spec.js b/spec/javascripts/integrations/integration_settings_form_spec.js index 069e2cb07b5..82d1f815ca8 100644 --- a/spec/javascripts/integrations/integration_settings_form_spec.js +++ b/spec/javascripts/integrations/integration_settings_form_spec.js @@ -126,6 +126,7 @@ describe('IntegrationSettingsForm', () => { spyOn(axios, 'put').and.callThrough(); integrationSettingsForm = new IntegrationSettingsForm('.js-integration-settings-form'); + // eslint-disable-next-line no-jquery/no-serialize formData = integrationSettingsForm.$form.serialize(); }); diff --git a/spec/javascripts/sidebar/assignee_title_spec.js b/spec/javascripts/sidebar/assignee_title_spec.js index 7fff7c075d9..6c65a55ff29 100644 --- a/spec/javascripts/sidebar/assignee_title_spec.js +++ b/spec/javascripts/sidebar/assignee_title_spec.js @@ -1,13 +1,12 @@ import Vue from 'vue'; import AssigneeTitle from '~/sidebar/components/assignees/assignee_title.vue'; +import { mockTracking, triggerEvent } from 'spec/helpers/tracking_helper'; describe('AssigneeTitle component', () => { let component; let AssigneeTitleComponent; - let statsSpy; beforeEach(() => { - statsSpy = spyOnDependency(AssigneeTitle, 'trackEvent'); AssigneeTitleComponent = Vue.extend(AssigneeTitle); }); @@ -105,15 +104,20 @@ describe('AssigneeTitle component', () => { expect(component.$el.querySelector('.edit-link')).not.toBeNull(); }); - it('calls trackEvent when edit is clicked', () => { + it('tracks the event when edit is clicked', () => { component = new AssigneeTitleComponent({ propsData: { numberOfAssignees: 0, editable: true, }, }).$mount(); - component.$el.querySelector('.js-sidebar-dropdown-toggle').click(); - expect(statsSpy).toHaveBeenCalled(); + const spy = mockTracking('_category_', component.$el, spyOn); + triggerEvent('.js-sidebar-dropdown-toggle'); + + expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', { + label: 'right_sidebar', + property: 'assignee', + }); }); }); diff --git a/spec/javascripts/sidebar/confidential_issue_sidebar_spec.js b/spec/javascripts/sidebar/confidential_issue_sidebar_spec.js index ea9e5677bc5..50374b8973f 100644 --- a/spec/javascripts/sidebar/confidential_issue_sidebar_spec.js +++ b/spec/javascripts/sidebar/confidential_issue_sidebar_spec.js @@ -1,13 +1,12 @@ import Vue from 'vue'; import confidentialIssueSidebar from '~/sidebar/components/confidential/confidential_issue_sidebar.vue'; +import { mockTracking, triggerEvent } from 'spec/helpers/tracking_helper'; describe('Confidential Issue Sidebar Block', () => { let vm1; let vm2; - let statsSpy; beforeEach(() => { - statsSpy = spyOnDependency(confidentialIssueSidebar, 'trackEvent'); const Component = Vue.extend(confidentialIssueSidebar); const service = { update: () => Promise.resolve(true), @@ -70,9 +69,13 @@ describe('Confidential Issue Sidebar Block', () => { }); }); - it('calls trackEvent when "Edit" is clicked', () => { - vm1.$el.querySelector('.confidential-edit').click(); + it('tracks the event when "Edit" is clicked', () => { + const spy = mockTracking('_category_', vm1.$el, spyOn); + triggerEvent('.confidential-edit'); - expect(statsSpy).toHaveBeenCalled(); + expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', { + label: 'right_sidebar', + property: 'confidentiality', + }); }); }); diff --git a/spec/javascripts/sidebar/lock/lock_issue_sidebar_spec.js b/spec/javascripts/sidebar/lock/lock_issue_sidebar_spec.js index 2d930428230..decccbb8964 100644 --- a/spec/javascripts/sidebar/lock/lock_issue_sidebar_spec.js +++ b/spec/javascripts/sidebar/lock/lock_issue_sidebar_spec.js @@ -1,13 +1,12 @@ import Vue from 'vue'; import lockIssueSidebar from '~/sidebar/components/lock/lock_issue_sidebar.vue'; +import { mockTracking, triggerEvent } from 'spec/helpers/tracking_helper'; describe('LockIssueSidebar', () => { let vm1; let vm2; - let statsSpy; beforeEach(() => { - statsSpy = spyOnDependency(lockIssueSidebar, 'trackEvent'); const Component = Vue.extend(lockIssueSidebar); const mediator = { @@ -61,10 +60,14 @@ describe('LockIssueSidebar', () => { }); }); - it('calls trackEvent when "Edit" is clicked', () => { - vm1.$el.querySelector('.lock-edit').click(); + it('tracks an event when "Edit" is clicked', () => { + const spy = mockTracking('_category_', vm1.$el, spyOn); + triggerEvent('.lock-edit'); - expect(statsSpy).toHaveBeenCalled(); + expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', { + label: 'right_sidebar', + property: 'lock_issue', + }); }); it('displays the edit form when opened from collapsed state', done => { diff --git a/spec/javascripts/sidebar/subscriptions_spec.js b/spec/javascripts/sidebar/subscriptions_spec.js index 2efa13f3fe8..a97608d6b8a 100644 --- a/spec/javascripts/sidebar/subscriptions_spec.js +++ b/spec/javascripts/sidebar/subscriptions_spec.js @@ -2,14 +2,13 @@ import Vue from 'vue'; import subscriptions from '~/sidebar/components/subscriptions/subscriptions.vue'; import eventHub from '~/sidebar/event_hub'; import mountComponent from 'spec/helpers/vue_mount_component_helper'; +import { mockTracking } from 'spec/helpers/tracking_helper'; describe('Subscriptions', function() { let vm; let Subscriptions; - let statsSpy; beforeEach(() => { - statsSpy = spyOnDependency(subscriptions, 'trackEvent'); Subscriptions = Vue.extend(subscriptions); }); @@ -53,6 +52,7 @@ describe('Subscriptions', function() { vm = mountComponent(Subscriptions, { subscribed: true }); spyOn(eventHub, '$emit'); spyOn(vm, '$emit'); + spyOn(vm, 'track'); vm.toggleSubscription(); @@ -60,11 +60,12 @@ describe('Subscriptions', function() { expect(vm.$emit).toHaveBeenCalledWith('toggleSubscription', jasmine.any(Object)); }); - it('calls trackEvent when toggled', () => { + it('tracks the event when toggled', () => { vm = mountComponent(Subscriptions, { subscribed: true }); + const spy = mockTracking('_category_', vm.$el, spyOn); vm.toggleSubscription(); - expect(statsSpy).toHaveBeenCalled(); + expect(spy).toHaveBeenCalled(); }); it('onClickCollapsedIcon method emits `toggleSidebar` event on component', () => { |