2019-08-31 20:51:14 -07:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
import { TestContext } from 'ember-test-helpers';
|
2020-08-26 15:44:50 -07:00
|
|
|
import { IBaseTrackingEvent } from '@datahub/shared/types/tracking/event-tracking';
|
|
|
|
import { TrackingEventCategory, TrackingGoal } from '@datahub/shared/constants/tracking/event-tracking';
|
|
|
|
import { getPiwikActivityQueue } from '@datahub/shared/utils/tracking/piwik';
|
|
|
|
import UnifiedTracking from '@datahub/shared/services/unified-tracking';
|
2019-09-04 21:46:02 -07:00
|
|
|
import Metrics from 'ember-metrics';
|
2020-08-26 15:44:50 -07:00
|
|
|
import MetricsServiceStub from '../../stubs/services/metrics';
|
2019-08-31 20:51:14 -07:00
|
|
|
|
2020-08-26 15:44:50 -07:00
|
|
|
module('Unit | Service | tracking', function(hooks): void {
|
2019-08-31 20:51:14 -07:00
|
|
|
setupTest(hooks);
|
|
|
|
|
|
|
|
hooks.beforeEach(function(this: TestContext) {
|
|
|
|
this.owner.register('service:metrics', MetricsServiceStub);
|
|
|
|
});
|
|
|
|
|
2020-08-26 15:44:50 -07:00
|
|
|
test('service exists and is registered', function(assert): void {
|
2019-09-04 21:46:02 -07:00
|
|
|
assert.ok(this.owner.lookup('service:unified-tracking'));
|
2019-08-31 20:51:14 -07:00
|
|
|
});
|
|
|
|
|
2020-08-26 15:44:50 -07:00
|
|
|
test('service methods proxy to metrics service and display expected behavior', function(assert): void {
|
2019-08-31 20:51:14 -07:00
|
|
|
assert.expect(2);
|
2019-09-04 21:46:02 -07:00
|
|
|
const trackingService: UnifiedTracking = this.owner.lookup('service:unified-tracking');
|
|
|
|
const metricsService: Metrics = this.owner.lookup('service:metrics');
|
2019-08-31 20:51:14 -07:00
|
|
|
const event: IBaseTrackingEvent = {
|
|
|
|
category: TrackingEventCategory.Entity,
|
|
|
|
action: ''
|
|
|
|
};
|
|
|
|
metricsService.trackEvent = (trackedEvent: IBaseTrackingEvent) =>
|
|
|
|
assert.deepEqual(
|
|
|
|
event,
|
|
|
|
trackedEvent,
|
|
|
|
'expected metrics service trackEvent method to be called by Tracking Service method'
|
|
|
|
);
|
|
|
|
|
|
|
|
trackingService.trackEvent(event);
|
|
|
|
|
|
|
|
const activityQueue = getPiwikActivityQueue(true);
|
|
|
|
trackingService.trackGoal({ name: TrackingGoal.SatClick });
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
activityQueue,
|
|
|
|
[['trackGoal', TrackingGoal.SatClick]],
|
|
|
|
'expected TrackingService#trackGoal to add "trackGoal" to activity queue'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|