import { visit, click } from '@ember/test-helpers'; import { TestContext } from 'ember-test-helpers'; import { getQueue } from 'wherehows-web/tests/helpers/analytics'; import { IBaseTrackingEvent } from '@datahub/tracking/types/event-tracking'; import UnifiedTracking from '@datahub/tracking/services/unified-tracking'; /** * Asynchronously navigates to a url and clicks on a search result item * @param {string} url * @returns {Promise} */ export const navigateToSearchAndClickResult = async (url: string): Promise => { await visit(url); await click('[data-content-name="searchResult@1"]'); }; /** * Stubs the tracking services trackEvent method to add received events to the tracking queue * @param {TestContext} testContext the test cases `this` reference * @param {ReturnType} queue tracking activity queue * @returns {ReturnType} */ export const mockTrackingEventQueue = ( testContext: TestContext, queue: ReturnType ): ReturnType => { const trackingService: UnifiedTracking = testContext.owner.lookup('service:unified-tracking'); // Stub tracking service with trackEvent stub function that adds seen events to supplied queue trackingService.trackEvent = ({ action, category, name = '' }: IBaseTrackingEvent): void => { // Push new events onto the queue. The the same queue needs to be mutated as expectation by the implementation queue.push([action, category, name]); }; return queue; };