import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; import { render, click } from '@ember/test-helpers'; import hbs from 'htmlbars-inline-precompile'; import { assertThrownException } from '@datahub/utils/test-helpers/test-exception'; import { TrackingEventCategory } from '@datahub/tracking/constants/event-tracking'; import { getRenderedComponent } from '@datahub/utils/test-helpers/register-component'; import TrackUiEvent from '@datahub/tracking/components/track-ui-event'; import sinonTest from 'ember-sinon-qunit/test-support/test'; import UnifiedTracking from '@datahub/tracking/services/unified-tracking'; const category = TrackingEventCategory.Entity; const action = 'testAction'; module('Integration | Component | track-ui-event', function(hooks): void { setupRenderingTest(hooks); test('instantiation errors are raised as expected', async function(assert): Promise { const category = TrackingEventCategory.Entity; await assertThrownException( assert, async (): Promise => { await render(hbs`

Nested Template

`); }, (err: Error) => err.message.includes('Expected a category to be provided on initialization of TrackUiEvent') ); this.set('category', category); await assertThrownException( assert, async (): Promise => { await render(hbs`

Nested Template

`); }, (err: Error) => err.message.includes('Expected an action to be provided on initialization of TrackUiEvent') ); }); test('component renders nested template', async function(assert): Promise { this.setProperties({ action, category }); await render(hbs`

Nested Template

`); assert.dom('p').hasText('Nested Template'); }); sinonTest('', async function(this: SinonTestContext, assert): Promise { const service: UnifiedTracking = this.owner.lookup('service:unified-tracking'); const stubbedTrackEvent = this.stub(service, 'trackEvent'); this.setProperties({ action, category }); const component = await getRenderedComponent({ ComponentToRender: TrackUiEvent, testContext: this, template: hbs`