Skip to content

Commit

Permalink
Fix e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: Olga Bulat <obulat@gmail.com>
  • Loading branch information
obulat committed Dec 5, 2023
1 parent 6440c51 commit f1c6cac
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
8 changes: 7 additions & 1 deletion frontend/test/playwright/e2e/external-sources.spec.ts
@@ -1,6 +1,10 @@
import { test } from "@playwright/test"

import { goToSearchTerm, t } from "~~/test/playwright/utils/navigation"
import {
goToSearchTerm,
t,
turnOnAnalytics,
} from "~~/test/playwright/utils/navigation"

import {
collectAnalyticsEvents,
Expand All @@ -11,6 +15,7 @@ test("sends VIEW_EXTERNAL_SOURCES analytics events", async ({
page,
context,
}) => {
await turnOnAnalytics(page)
const events = collectAnalyticsEvents(context)

await goToSearchTerm(page, "cat", { searchType: "image", mode: "SSR" })
Expand All @@ -33,6 +38,7 @@ test("sends SELECT_EXTERNAL_SOURCE analytics events", async ({
page,
context,
}) => {
await turnOnAnalytics(page)
const pagePromise = page.context().waitForEvent("page")

const events = collectAnalyticsEvents(context)
Expand Down
9 changes: 6 additions & 3 deletions frontend/test/playwright/e2e/global-audio.spec.ts
Expand Up @@ -16,7 +16,7 @@ test.describe("Global Audio", () => {
// Navigate to the details page of the playing audio track
await firstAudioRow.click()
// and confirm is still playing (or loading to play)
const mainPlayerButton = page.locator(".main-track >> button")
const mainPlayerButton = page.locator(".main-track >> button").first()
await sleep(600) // Doesn't seem to make a difference for the status
await expect(mainPlayerButton).toHaveAttribute(
"aria-label",
Expand Down Expand Up @@ -53,8 +53,11 @@ test.describe("Global Audio", () => {
const secondAudioRow = await audio.getNthAudioRow(page, 1)
await secondAudioRow.click()
// and confirm is not playing
const mainPlayerButton = page.locator(".main-track >> button")
await expect(mainPlayerButton).toHaveAttribute("aria-label", "Play")
await expect(
page
.locator(".main-track")
.getByRole("button", { name: t("playPause.play") })
).toBeVisible()
})
})
})
11 changes: 10 additions & 1 deletion frontend/test/playwright/e2e/image-detail.spec.ts
@@ -1,7 +1,11 @@
import { test, expect, Page } from "@playwright/test"

import { mockProviderApis } from "~~/test/playwright/utils/route"
import { t } from "~~/test/playwright/utils/navigation"
import {
setCookies,
t,
turnOnAnalytics,
} from "~~/test/playwright/utils/navigation"
import {
collectAnalyticsEvents,
expectEventPayloadToMatch,
Expand All @@ -26,6 +30,9 @@ test.beforeEach(async ({ context }) => {
})

test("shows the author and title of the image", async ({ page }) => {
await setCookies(page.context(), {
features: { additional_search_views: "off" },
})
await goToCustomImagePage(page)
const author = page.locator('a[aria-label^="author"]')
await expect(author).toBeVisible()
Expand Down Expand Up @@ -69,6 +76,7 @@ test.describe("analytics", () => {
context,
page,
}) => {
await turnOnAnalytics(page)
const analyticsEvents = collectAnalyticsEvents(context)

await goToCustomImagePage(page)
Expand All @@ -90,6 +98,7 @@ test.describe("analytics", () => {
context,
page,
}) => {
await turnOnAnalytics(page)
const analyticsEvents = collectAnalyticsEvents(context)

await goToCustomImagePage(page)
Expand Down
7 changes: 6 additions & 1 deletion frontend/test/playwright/utils/navigation.ts
Expand Up @@ -443,5 +443,10 @@ export const setBreakpointCookie = async (page: Page, breakpoint: string) => {

export const turnOnAnalytics = async (page: Page) => {
await page.goto("/preferences")
await page.getByLabel("Record custom events and page views.").click()
const analyticsCheckbox = page.getByLabel(
"Record custom events and page views."
)
if (!(await analyticsCheckbox.isChecked())) {
await analyticsCheckbox.click()
}
}

0 comments on commit f1c6cac

Please sign in to comment.