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)));
|
||||
|
||||
Reference in new issue
Block a user