Skip to content

Commit

Permalink
test(e2e): tab consistently across browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
giamir committed Jan 23, 2024
1 parent 01b4ae2 commit 9cb0d7c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 28 deletions.
70 changes: 46 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"devDependencies": {
"@commitlint/cli": "^17.4.4",
"@commitlint/config-conventional": "^17.4.4",
"@playwright/test": "^1.31.1",
"@playwright/test": "^1.41.1",
"@stackoverflow/commitlint-config": "^1.0.0",
"@stackoverflow/eslint-config": "^1.0.0",
"@stackoverflow/prettier-config": "^1.0.0",
Expand Down
8 changes: 5 additions & 3 deletions test/commonmark/editor.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
typeText,
switchMode,
clickEditorContent,
tab,
} from "../e2e-helpers";

const moreMenuDropdownSelector = ".js-more-formatting-dropdown";
Expand Down Expand Up @@ -74,6 +75,7 @@ test.describe.serial("markdown mode", () => {

test("should retain focus on the menu item after triggering via keyboard", async ({
page,
browserName,
}) => {
await expect(page.locator(moreMenuDropdownSelector)).toBeInViewport();

Expand All @@ -90,9 +92,9 @@ test.describe.serial("markdown mode", () => {
await page.keyboard.press("Enter");

// Tab to "Spoiler (Cmd-/)"
await page.keyboard.press("Tab");
await page.keyboard.press("Tab");
await page.keyboard.press("Tab");
await tab(page, browserName);
await tab(page, browserName);
await tab(page, browserName);

const activeElementDataKey = await page.evaluate(() =>
document.activeElement.getAttribute("data-key")
Expand Down
14 changes: 14 additions & 0 deletions test/e2e-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,17 @@ export async function clickEditorContent(
clickCount,
});
}

/**
* Simulate pressing the tab key consistently across browsers
* @param page
* @param browserName
*/
export async function tab(
page: Page,
browserName: "chromium" | "firefox" | "webkit"
): Promise<void> {
// see https://github.com/microsoft/playwright/issues/2114
const tabKey = browserName === "webkit" ? "Alt+Tab" : "Tab";
await page.keyboard.press(tabKey);
}

0 comments on commit 9cb0d7c

Please sign in to comment.