summaryrefslogtreecommitdiff
path: root/spec/frontend/tracking_spec.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-27 09:06:29 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-27 09:06:29 +0000
commitc02f53288a838166a28518983fae3b80ca5936d8 (patch)
treecd8af90618ac55809e7782bad09246874876f7c2 /spec/frontend/tracking_spec.js
parent688e33953d34ab8cd348d02ce79d8fdfe5353a03 (diff)
downloadgitlab-ce-c02f53288a838166a28518983fae3b80ca5936d8.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/tracking_spec.js')
-rw-r--r--spec/frontend/tracking_spec.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/frontend/tracking_spec.js b/spec/frontend/tracking_spec.js
index 964f8b8787e..c3c52844c2c 100644
--- a/spec/frontend/tracking_spec.js
+++ b/spec/frontend/tracking_spec.js
@@ -177,4 +177,70 @@ describe('Tracking', () => {
expect(eventSpy).toHaveBeenCalledWith('_category_', 'nested_event', {});
});
});
+
+ describe('tracking mixin', () => {
+ describe('trackingOptions', () => {
+ it('return the options defined on initialisation', () => {
+ const mixin = Tracking.mixin({ foo: 'bar' });
+ expect(mixin.computed.trackingOptions()).toEqual({ foo: 'bar' });
+ });
+
+ it('local tracking value override and extend options', () => {
+ const mixin = Tracking.mixin({ foo: 'bar' });
+ // the value of this in the vue lifecyle is different, but this serve the tests purposes
+ mixin.computed.tracking = { foo: 'baz', baz: 'bar' };
+ expect(mixin.computed.trackingOptions()).toEqual({ foo: 'baz', baz: 'bar' });
+ });
+ });
+
+ describe('trackingCategory', () => {
+ it('return the category set in the component properties first', () => {
+ const mixin = Tracking.mixin({ category: 'foo' });
+ mixin.computed.tracking = {
+ category: 'bar',
+ };
+ expect(mixin.computed.trackingCategory()).toBe('bar');
+ });
+
+ it('return the category set in the options', () => {
+ const mixin = Tracking.mixin({ category: 'foo' });
+ expect(mixin.computed.trackingCategory()).toBe('foo');
+ });
+
+ it('if no category is selected returns undefined', () => {
+ const mixin = Tracking.mixin();
+ expect(mixin.computed.trackingCategory()).toBe(undefined);
+ });
+ });
+
+ describe('track', () => {
+ let eventSpy;
+ let mixin;
+
+ beforeEach(() => {
+ eventSpy = jest.spyOn(Tracking, 'event').mockReturnValue();
+ mixin = Tracking.mixin();
+ mixin = {
+ ...mixin.computed,
+ ...mixin.methods,
+ };
+ });
+
+ it('calls the event method', () => {
+ mixin.trackingCategory = mixin.trackingCategory();
+ mixin.trackingOptions = mixin.trackingOptions();
+
+ mixin.track('foo');
+ expect(eventSpy).toHaveBeenCalledWith(undefined, 'foo', {});
+ });
+
+ it('give precedence to data for category and options', () => {
+ mixin.trackingCategory = mixin.trackingCategory();
+ mixin.trackingOptions = mixin.trackingOptions();
+ const data = { category: 'foo', label: 'baz' };
+ mixin.track('foo', data);
+ expect(eventSpy).toHaveBeenCalledWith('foo', 'foo', data);
+ });
+ });
+ });
});