-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add VIEW_EXTERNAL_SOURCES event (#2450)
Co-authored-by: Olga Bulat <obulat@gmail.com>
- Loading branch information
Showing
3 changed files
with
69 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,43 @@ | ||
import { test, expect } from "@playwright/test" | ||
|
||
import { goToSearchTerm, setCookies } from "~~/test/playwright/utils/navigation" | ||
|
||
test("sends analytics event on external source click", async ({ page }) => { | ||
let eventData: { | ||
name: string | ||
mediaType: string | ||
query: string | ||
} = { name: "", mediaType: "", query: "" } | ||
page.on("request", (req) => { | ||
if (req.method() === "POST") { | ||
const requestData = req.postDataJSON() | ||
if (requestData?.n == "SELECT_EXTERNAL_SOURCE") { | ||
eventData = JSON.parse(requestData?.p) | ||
} | ||
} | ||
}) | ||
// Start waiting for new page before clicking. | ||
import { test } from "@playwright/test" | ||
|
||
import { goToSearchTerm } from "~~/test/playwright/utils/navigation" | ||
|
||
import { | ||
collectAnalyticsEvents, | ||
expectEventPayloadToMatch, | ||
} from "~~/test/playwright/utils/analytics" | ||
|
||
test("sends correct analytics events", async ({ page, context }) => { | ||
const pagePromise = page.context().waitForEvent("page") | ||
|
||
const mediaType = "image" | ||
const name = "Centre For Ageing Better" | ||
const query = "cat" | ||
const events = collectAnalyticsEvents(context) | ||
|
||
await setCookies(page.context(), { analytics: "true" }) | ||
await goToSearchTerm(page, "cat", { mode: "SSR", query: "ff_analytics=on" }) | ||
await goToSearchTerm(page, "cat", { mode: "SSR" }) | ||
|
||
await page.getByRole("button", { name: "Source list" }).click() | ||
await page.getByRole("link", { name: "Centre for Ageing Better" }).click() | ||
|
||
const newPage = await pagePromise | ||
await newPage.close() | ||
|
||
expect(eventData.name).toEqual(name) | ||
expect(eventData.mediaType).toEqual(mediaType) | ||
expect(eventData.query).toEqual(query) | ||
const viewEvent = events.find((event) => event.n === "VIEW_EXTERNAL_SOURCES") | ||
const selectEvent = events.find( | ||
(event) => event.n === "SELECT_EXTERNAL_SOURCE" | ||
) | ||
|
||
if (!viewEvent || !selectEvent) { | ||
throw new Error("Analytics events were not triggered properly.") | ||
} | ||
|
||
expectEventPayloadToMatch(viewEvent, { | ||
searchType: "all", | ||
query: "cat", | ||
resultPage: 1, | ||
}) | ||
expectEventPayloadToMatch(selectEvent, { | ||
name: "Centre For Ageing Better", | ||
mediaType: "image", | ||
query: "cat", | ||
component: "VExternalSourceList", | ||
}) | ||
}) |