Skip to content

Commit

Permalink
Fix flaky content report form test (#3880)
Browse files Browse the repository at this point in the history
* Fix the content-report-form.spec.ts and update the snapshots

* Small adjustments
  • Loading branch information
zackkrida committed Mar 6, 2024
1 parent bd197a7 commit 433d92c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,41 @@ const getReportButton = (page: Page) => {
})
}

const getReportForm = (page: Page) => {
return page.getByRole("dialog", {
name: t("mediaDetails.contentReport.long"),
})
}

// Flaky: https://github.com/WordPress/openverse/issues/2020
test.describe.skip("content report form", () => {
/**
* This test was previoiusly known to be flaky:
* https://github.com/WordPress/openverse/issues/2020
*
* The flake involved an offset of 1-2 pixels in both
* the content and width of the popover (the locator
* produced with `getReportButton`). To fix this, the
* test now uses a screenshot of the entire page, rather
* than the isolated report element, and an increased
* maxDiffPixel ratio.
*
* Additionally, previously there were focused/unfocused
* tests to confirm the proper focus state of the
* report popover close button. However, that state
* only appears on focus visible and the snapshots
* were identical, so the tests were redundant.
*/
test.describe("content report form", () => {
test.describe.configure({ retries: 2 })

breakpoints.describeMd(({ expectSnapshot }) => {
test("unfocused close button", async ({ page }) => {
await preparePageForTests(page, "md")
await page.goto(imageUrl)

await getReportButton(page).click()

await expectSnapshot("content-report-unfocused", getReportForm(page))
})
})

breakpoints.describeMd(({ expectSnapshot }) => {
test("focused close button", async ({ page }) => {
await preparePageForTests(page, "md")
await page.goto(imageUrl)

await getReportButton(page).click()
const button = getReportButton(page)

const form = getReportForm(page)
// Scroll the button to the bottom of the page
await button.evaluate((element) => element.scrollIntoView(false))

await form.getByRole("button", { name: t("modal.close") }).focus()
await button.click()

await expectSnapshot("content-report-focused", form)
await expectSnapshot("content-report", page, undefined, {
maxDiffPixelRatio: 0.1,
})
})
})
})
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.

0 comments on commit 433d92c

Please sign in to comment.