mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-06 06:01:31 -05:00
refactor(e2e): create editor helpers (#54701)
This commit is contained in:
committed by
GitHub
parent
c7d3b1303e
commit
ca4e5db8b1
48
e2e/utils/editor.ts
Normal file
48
e2e/utils/editor.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { type Page } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* Retrieves any editor elements on the page.
|
||||
* @param page - The Playwright page object.
|
||||
* @returns The editor elements.
|
||||
*/
|
||||
export function getEditors(page: Page) {
|
||||
return page.getByLabel(
|
||||
'Editor content;Press Alt+F1 for Accessibility Options'
|
||||
);
|
||||
}
|
||||
|
||||
export async function focusEditor({
|
||||
page,
|
||||
isMobile,
|
||||
browserName
|
||||
}: {
|
||||
page: Page;
|
||||
isMobile: boolean;
|
||||
browserName: string;
|
||||
}) {
|
||||
// The editor has an overlay div, which prevents the click event from bubbling up in iOS Safari.
|
||||
// This is a quirk in this browser-OS combination, and the workaround here is to use `.focus()`
|
||||
// in place of `.click()` to focus on the editor.
|
||||
// Ref: https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
|
||||
if (isMobile && browserName === 'webkit') {
|
||||
await getEditors(page).focus();
|
||||
} else {
|
||||
await getEditors(page).click();
|
||||
}
|
||||
}
|
||||
|
||||
export async function clearEditor({
|
||||
page,
|
||||
browserName
|
||||
}: {
|
||||
page: Page;
|
||||
browserName: string;
|
||||
}) {
|
||||
// TODO: replace with ControlOrMeta when it's supported
|
||||
if (browserName === 'webkit') {
|
||||
await page.keyboard.press('Meta+a');
|
||||
} else {
|
||||
await page.keyboard.press('Control+a');
|
||||
}
|
||||
await page.keyboard.press('Backspace');
|
||||
}
|
||||
Reference in New Issue
Block a user