Skip to content

Commit

Permalink
Fix openFirstResult
Browse files Browse the repository at this point in the history
  • Loading branch information
obulat committed Apr 20, 2023
1 parent f5a7424 commit ecceac3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
16 changes: 7 additions & 9 deletions frontend/test/playwright/utils/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,14 @@ export const searchFromHeader = async (page: Page, term: string) => {
* Scroll down and up to load all lazy-loaded content.
*/
export const openFirstResult = async (page: Page, mediaType: MediaType) => {
await Promise.all([
page.waitForNavigation(),
page
.locator(`a[href*="/${mediaType}/"]`)
.first()
.click({
position: { x: 32, y: 32 },
}),
])
const firstResult = page.locator(`a[href*="/${mediaType}/"]`).first()
const firstResultHref = await firstResult.getAttribute("href")
if (!firstResultHref) {
throw new Error(`Could not find a link to a ${mediaType} in the page`)
}
await firstResult.click({ position: { x: 32, y: 32 } })
await scrollDownAndUp(page)
await page.waitForURL(firstResultHref)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { test } from "@playwright/test"

import { removeHiddenOverflow } from "~~/test/playwright/utils/page"
import breakpoints from "~~/test/playwright/utils/breakpoints"
import {
goToSearchTerm,
Expand Down Expand Up @@ -30,8 +29,6 @@ for (const mediaType of supportedMediaTypes) {
test(`from search results`, async ({ page }) => {
// This will include the "Back to results" link.
await openFirstResult(page, mediaType)
await removeHiddenOverflow(page)
await page.waitForEvent("load")

await expectSnapshot(
`${mediaType}-${dir}-from-search-results`,
Expand Down

0 comments on commit ecceac3

Please sign in to comment.