test(e2e): leave fullscreen before resizing and read the watermarked statement
This commit is contained in:
1 parent
72d8f54d1a
commit
d5e169e71b
4 files changed
+57
-20
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { expect, type Page } from "@playwright/test";
|
||||
|
||||
const continueInFullscreenName = "Продолжить в полном экране";
|
||||
|
||||
/**
|
||||
* Resizes the viewport the way a user would while taking a real attempt.
|
||||
*
|
||||
* A real attempt holds the page in fullscreen, and the browser refuses to
|
||||
* resize a fullscreen window. The helper leaves fullscreen first. The page then
|
||||
* covers the task, as it does for a candidate who pressed Escape, so the helper
|
||||
* returns through the cover button, which also asks for fullscreen again, and
|
||||
* waits for the task to be back. Pages that never entered fullscreen are
|
||||
* resized directly.
|
||||
*/
|
||||
export async function resizeViewport(
|
||||
page: Page,
|
||||
size: { width: number; height: number },
|
||||
): Promise<void> {
|
||||
const wasFullscreen = await page.evaluate(() => document.fullscreenElement !== null);
|
||||
if (wasFullscreen) {
|
||||
await page.evaluate(() => document.exitFullscreen());
|
||||
await expect.poll(() => page.evaluate(() => document.fullscreenElement)).toBeNull();
|
||||
}
|
||||
await page.setViewportSize(size);
|
||||
if (!wasFullscreen) return;
|
||||
|
||||
const continueButton = page.getByRole("button", { name: continueInFullscreenName });
|
||||
await expect(continueButton).toBeVisible();
|
||||
await continueButton.click();
|
||||
await expect(continueButton).toHaveCount(0);
|
||||
await expect.poll(() => page.evaluate(() => document.fullscreenElement !== null)).toBe(true);
|
||||
}
|
||||
|
||||
export async function expectNoHorizontalOverflow(page: Page, width: number): Promise<void> {
|
||||
await resizeViewport(page, { width, height: 900 });
|
||||
const overflow = await page.evaluate(
|
||||
() => document.documentElement.scrollWidth > window.innerWidth,
|
||||
);
|
||||
expect(overflow, `no horizontal overflow at ${width}px`).toBe(false);
|
||||
}
|
||||
Reference in new issue
Block a user