-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add VIEW_EXTERNAL_SOURCES event #2450
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
11f813e
Add VIEW_EXTERNAL_SOURCES event
zackkrida df81932
Merge branch 'main' into fix-#1075
zackkrida 78db537
Merge main
zackkrida ee584d0
Merge branch 'main' into fix-#1075
zackkrida d46006e
Add current page to the event
zackkrida b104ea2
Add test
zackkrida ddbe42c
Merge branch 'main' into fix-#1075
zackkrida 0ca5f5e
Update frontend/test/playwright/e2e/external-sources.spec.ts
zackkrida f4df09a
Remove inaccurate comment and add resultPage to event type definition
zackkrida 7d65cf5
Fix lint error
zackkrida fbfcab9
Update frontend/test/playwright/e2e/external-sources.spec.ts
zackkrida e3b2cf7
Merge main + fix import
zackkrida File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,46 @@ | ||
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 "../utils/analytics" | ||
zackkrida marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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", | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says something different from what's happening.
searhType
is being used from thesearchStore
on L169.