45 lines
1.6 KiB
TypeScript
Raw Normal View History

import DwellTime from '@datahub/tracking/utils/dwell-time';
2019-08-31 20:51:14 -07:00
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { triggerEvent } from '@ember/test-helpers';
import { searchRouteName } from '@datahub/tracking/constants/site-search-tracking';
2019-08-31 20:51:14 -07:00
module('Unit | Utility | analytics/search/dwell-time', function(hooks): void {
2019-08-31 20:51:14 -07:00
setupTest(hooks);
test('instantiation succeeds', function(assert): void {
2019-08-31 20:51:14 -07:00
const routerService = this.owner.lookup('service:router');
let dwellTime = new DwellTime(searchRouteName, routerService);
assert.ok(dwellTime);
});
test('dwellTime properties', function(assert): void {
2019-08-31 20:51:14 -07:00
const routerService = this.owner.lookup('service:router');
let dwellTime = new DwellTime(searchRouteName, routerService);
assert.equal(dwellTime.startTime, 0, 'expected startTime to be 0 on instantiation');
assert.equal(dwellTime.dwellTime, 0, 'expected dwellTime to be 0 on instantiation');
assert.equal(
dwellTime.searchRouteName,
searchRouteName,
`expected DwellTime#searchRouteName to match ${searchRouteName} on instantiation`
);
dwellTime.startTime = 10;
dwellTime.resetDwellTimeTracking();
assert.equal(dwellTime.startTime, 0, 'expected startTime to be reset by resetDwellTimeTracking');
});
test('dwellTime cleanup', function(assert): void {
2019-08-31 20:51:14 -07:00
assert.expect(1);
const dwellTime = new DwellTime(searchRouteName, this.owner.lookup('service:router'));
dwellTime.unbindListeners = () => {
assert.ok(true, 'expected onDestroy to be called when the beforeunload event is triggered');
};
triggerEvent(document.body, 'beforeunload');
});
});