datahub/datahub-web/@datahub/shared/tests/integration/modifiers/track-control-interaction-test.ts
Charlie Tran 843a6c5bbb
feat(frontend): update datahub-web client UI code (#1806)
* Releases updated version of datahub-web client UI code

* Fix typo in yarn lock

* Change yarn lock to match yarn registry directories

* Previous commit missed some paths

* Even more changes to yarnlock missing in previous commit

* Include codegen file for typings

* Add files to get parity for datahub-web and current OS datahub-midtier

* Add in typo fix from previous commit - change to proper license

* Implement proper OS fix for person entity picture url

* Workarounds for open source DH issues

* Fixes institutional memory api and removes unopensourced tabs for datasets

* Fixes search dataset deprecation and user search issue as a result of changes

* Remove internal only options in the avatar menu
2020-08-26 15:44:50 -07:00

62 lines
2.5 KiB
TypeScript

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, click, triggerEvent } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import sinonTest from 'ember-sinon-qunit/test-support/test';
import UnifiedTracking from '@datahub/shared/services/unified-tracking';
import { ControlInteractionType } from '@datahub/shared/constants/tracking/event-tracking/control-interaction-events';
import { stubService } from '@datahub/utils/test-helpers/stub-service';
import { TrackingEventCategory } from '@datahub/shared/constants/tracking/event-tracking';
module('Integration | Modifier | track-control-interaction', function(hooks): void {
setupRenderingTest(hooks);
sinonTest('It calls the track event action when triggered', async function(
this: SinonTestContext,
assert
): Promise<void> {
const service: UnifiedTracking = this.owner.lookup('service:unified-tracking');
const stubbedTrackEvent = this.stub(service, 'trackEvent');
this.setProperties({
type: ControlInteractionType.click,
name: 'pika-test'
});
await render(hbs`<button {{track-control-interaction type=this.type name=this.name}} type="button" />`);
await click('button');
assert.ok(stubbedTrackEvent.called, "Expected the UnifiedTracking service's trackEvent to have been called");
});
test('it works as expected with various interaction types', async function(assert) {
assert.expect(6);
stubService('unified-tracking', {
trackEvent(params: { category: TrackingEventCategory.ControlInteraction; action: string }): void {
assert.equal(
params.category,
TrackingEventCategory.ControlInteraction,
'Passes the correct category parameter'
);
assert.equal(params.action, 'pika-test', 'Passes the correct action parameter');
}
});
this.setProperties({
type: ControlInteractionType.click,
name: 'pika-test'
});
await render(hbs`<button {{track-control-interaction type=this.type name=this.name}} type="button" />`);
await click('button');
this.set('type', ControlInteractionType.hover);
await render(hbs`<button {{track-control-interaction type=this.type name=this.name}} type="button" />`);
await triggerEvent('button', 'mouseenter');
this.set('type', ControlInteractionType.focus);
await render(hbs`<input {{track-control-interaction type=this.type name=this.name}} />`);
await triggerEvent('input', 'focus');
});
});