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
@@ -206,7 +206,7 @@ function apiResponse(method: string, path: string | RegExp) {
|
||||
// The answer of a rate-limit fixture item follows from its statement: count
|
||||
// the requests that find `limit` accepted ones in (t - window, t].
|
||||
function rejectedRequests(statement: string): number {
|
||||
const limit = Number(/fewer than (\d+) previously accepted/.exec(statement)?.[1]);
|
||||
const limit = Number(/(?:fewer|less) than (\d+) previously accepted/.exec(statement)?.[1]);
|
||||
const window = Number(/\(t - (\d+), t\]/.exec(statement)?.[1]);
|
||||
const times = /arrival times: ([\d ]+)\./.exec(statement)?.[1]?.trim().split(/\s+/).map(Number);
|
||||
if (!Number.isInteger(limit) || !Number.isInteger(window) || !times?.length) {
|
||||
@@ -264,6 +264,19 @@ async function grantC3(page: Page): Promise<void> {
|
||||
expect((await granted).status()).toBe(200);
|
||||
}
|
||||
|
||||
// The served statement of a real attempt carries an invisible mark (format
|
||||
// characters) and may use an interchangeable wording ("less than" for "fewer
|
||||
// than"), so the helper waits for the statement and drops the mark characters.
|
||||
async function readStatement(page: Page): Promise<string> {
|
||||
const paragraph = page.locator("article p").first();
|
||||
const readable = async () =>
|
||||
((await paragraph.textContent()) ?? "").replace(/\p{Cf}/gu, "").replace(/\s+/g, " ");
|
||||
await expect
|
||||
.poll(readable, { timeout: 15_000 })
|
||||
.toMatch(/^A gateway applies a sliding-window limiter/);
|
||||
return readable();
|
||||
}
|
||||
|
||||
// Takes the full Backend Junior test in the browser and answers every item
|
||||
// from its statement. With `reloadAfter` the page is reloaded after that many
|
||||
// answers: the same attempt and item come back and nothing is answered twice.
|
||||
@@ -297,9 +310,7 @@ async function passFullTest(page: Page, reloadAfter?: number): Promise<string> {
|
||||
await expect(page.getByRole("heading", { name: `Задание ${sequence}` })).toBeVisible({
|
||||
timeout: 20_000,
|
||||
});
|
||||
const statement = await page
|
||||
.getByText(/^A gateway applies a sliding-window limiter/)
|
||||
.innerText();
|
||||
const statement = await readStatement(page);
|
||||
await page
|
||||
.getByRole("textbox", { name: /^Числовой ответ/ })
|
||||
.fill(String(rejectedRequests(statement)));
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
type Response,
|
||||
type Route,
|
||||
} from "@playwright/test";
|
||||
import { expectNoHorizontalOverflow } from "./viewport";
|
||||
|
||||
type InboxMessage = {
|
||||
text?: string;
|
||||
@@ -173,14 +174,6 @@ async function focusWithKeyboard(page: Page, target: Locator): Promise<void> {
|
||||
throw new Error("Keyboard navigation did not reach the assessment action.");
|
||||
}
|
||||
|
||||
async function expectNoHorizontalOverflow(page: Page, width: number): Promise<void> {
|
||||
await page.setViewportSize({ width, height: 900 });
|
||||
const overflow = await page.evaluate(
|
||||
() => document.documentElement.scrollWidth > window.innerWidth,
|
||||
);
|
||||
expect(overflow, `no horizontal overflow at ${width}px`).toBe(false);
|
||||
}
|
||||
|
||||
async function navigateInApp(page: Page, path: string): Promise<void> {
|
||||
await page.evaluate((target) => {
|
||||
window.history.pushState(window.history.state, "", target);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { expect, test, type Locator, type Page, type Request, type Route } from "@playwright/test";
|
||||
import { expectNoHorizontalOverflow } from "./viewport";
|
||||
|
||||
// States, focus, and error binding of the minimal path with a stubbed API. The
|
||||
// API answers come from this file, so each test controls one failure at a time
|
||||
@@ -161,14 +162,6 @@ async function mockApi(page: Page, routes: Routes): Promise<Map<string, number>>
|
||||
return calls;
|
||||
}
|
||||
|
||||
async function expectNoHorizontalOverflow(page: Page, width: number): Promise<void> {
|
||||
await page.setViewportSize({ width, height: 900 });
|
||||
const overflow = await page.evaluate(
|
||||
() => document.documentElement.scrollWidth > window.innerWidth,
|
||||
);
|
||||
expect(overflow, `no horizontal overflow at ${width}px`).toBe(false);
|
||||
}
|
||||
|
||||
// The focus outline comes from the global :focus-visible rule. A control that
|
||||
// has focus from the keyboard must match that selector and draw an outline.
|
||||
async function expectFocusOutline(target: Locator): Promise<void> {
|
||||
|
||||
@@ -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