41 lines
1.7 KiB
TypeScript
41 lines
1.7 KiB
TypeScript
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);
|
|
}
|