datahub/datahub-web/@datahub/shared/tests/unit/services/unified-tracking-test.ts

49 lines
1.8 KiB
TypeScript
Raw Normal View History

2019-08-31 20:51:14 -07:00
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { TestContext } from 'ember-test-helpers';
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';
import Metrics from 'ember-metrics';
import MetricsServiceStub from '../../stubs/services/metrics';
2019-08-31 20:51:14 -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);
});
test('service exists and is registered', function(assert): void {
assert.ok(this.owner.lookup('service:unified-tracking'));
2019-08-31 20:51:14 -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);
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'
);
});
});