Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
obulat committed Feb 15, 2023
1 parent d8ed82b commit cb94d7c
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/layouts/content-layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<div class="main-page flex h-full w-full min-w-0 flex-col justify-between">
<Nuxt />
<VFooter
mode="content"
:mode="isSearchHeader ? 'content' : 'search'"
class="border-t border-dark-charcoal-20 bg-white"
/>
</div>
Expand Down
72 changes: 72 additions & 0 deletions test/playwright/e2e/filters-sidebar-keyboard.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { test, expect, Page } from "@playwright/test"

import {
LanguageDirection,
pathWithDir,
setCookies,
t,
} from "~~/test/playwright/utils/navigation"

import { keycodes } from "~/constants/key-codes"

const isFilterButtonFocused = async (page: Page) => {
return page.evaluate(() => document.activeElement?.id === "filter-button")
}

const walkToFilterButton = async (page: Page) => {
while (!(await isFilterButtonFocused(page))) {
await page.keyboard.press(keycodes.Tab)
}
}

const firstFilterCheckbox = (page: Page, dir: LanguageDirection) => {
return page
.getByRole("region", { name: t("filters.filter-by", dir) })
.getByRole("checkbox")
.first()
}

test.describe.configure({ mode: "parallel" })

for (const dir of ["ltr", "rtl"]) {
test.describe(`search header keyboard accessibility test in ${dir}`, () => {
test.beforeEach(async ({ page }) => {
await setCookies(page.context(), { uiBreakpoint: "lg" })
/**
* To simplify finding the last focusable element in the filters sidebar,
* we use the image search page. After the removal of the "searchBy" filter,
* the last element on the all media search page is the "license explanation"
* button, not a checkbox.
*/
await page.goto(pathWithDir("/search/image?q=birds", dir))
})

test("should move focus to the sidebar after header", async ({ page }) => {
await walkToFilterButton(page)

// Check that the filters sidebar is open
expect(
await page.locator("#filter-button").getAttribute("aria-expanded")
).toBe("true")

await page.keyboard.press(keycodes.Tab)

await expect(
firstFilterCheckbox(page, dir as LanguageDirection)
).toBeFocused()
})

test("should move focus to main after filters sidebar", async ({
page,
}) => {
await page.getByRole("checkbox").last().focus()

await page.keyboard.press(keycodes.Tab)

const href = await page.evaluate(
() => (document.activeElement as HTMLAnchorElement | null)?.href
)
expect(href).toBeDefined()
})
})
}
2 changes: 1 addition & 1 deletion test/playwright/e2e/header-internal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test.describe("Header internal", () => {
const homeUrl = page.url()
await clickMenuButton(page)
await page.getByRole("link", { name: t("navigation.about") }).click()
await page.locator("a[href='/']").click()
await page.getByRole("link", { name: t("header.home-link") }).click()
expect(page.url()).toBe(homeUrl)
})
})
Expand Down
60 changes: 0 additions & 60 deletions test/storybook/visual-regression/v-filter-button-old.spec.ts

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit cb94d7c

Please sign in to comment.