feat(assessment): watermark the task text of real attempts
This commit is contained in:
1 parent
24b64d698a
commit
c975a0d506
57 files changed
+2429
-92
No files matched your search
@@ -44,17 +44,26 @@ export type MockedAttempt = {
|
||||
acknowledgements: unknown[];
|
||||
};
|
||||
|
||||
export const watermarkCode = "7K3QD-9XM2T";
|
||||
/** The notice text version the page knows; the mock server requires the same one. */
|
||||
export const noticeVersion = 3;
|
||||
|
||||
type Options = {
|
||||
content: MockItemContent;
|
||||
/** The candidate already acknowledged the notice, so the start asks nothing. */
|
||||
noticeAcknowledged?: boolean;
|
||||
/** The task text the server sends, with its invisible mark when it has one. */
|
||||
prompt?: string;
|
||||
/** The visible code of the attempt, or null for an attempt without one. */
|
||||
watermark?: string | null;
|
||||
};
|
||||
|
||||
function isoSeconds(ms: number): string {
|
||||
return `${new Date(ms).toISOString().slice(0, 19)}Z`;
|
||||
}
|
||||
|
||||
function attemptBody(version: number, content: MockItemContent) {
|
||||
function attemptBody(version: number, options: Options) {
|
||||
const { content, prompt = taskPrompt, watermark = watermarkCode } = options;
|
||||
return {
|
||||
id: attemptId,
|
||||
version,
|
||||
@@ -76,8 +85,9 @@ function attemptBody(version: number, content: MockItemContent) {
|
||||
sessions: { used: 1, max: 2, idle_timeout_seconds: 1800 },
|
||||
finished_at: null,
|
||||
progress: { answered_items: 0, max_items: 5 },
|
||||
current_item: { id: itemId, sequence: 1, prompt: taskPrompt, content },
|
||||
current_item: { id: itemId, sequence: 1, prompt, content },
|
||||
practices: [],
|
||||
...(watermark ? { watermark: { code: watermark } } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -118,16 +128,16 @@ export async function mockAttemptApi(page: Page, options: Options): Promise<Mock
|
||||
recorded.acknowledgements.push(JSON.parse(request.postData() ?? "{}"));
|
||||
}
|
||||
return reply({
|
||||
notice_version: 2,
|
||||
notice_version: noticeVersion,
|
||||
acknowledged,
|
||||
acknowledged_at: acknowledged ? "2026-10-10T10:00:00Z" : null,
|
||||
});
|
||||
}
|
||||
if (path === base && method === "GET") return reply(attemptBody(1, options.content));
|
||||
if (path === `${base}/sessions`) return reply(attemptBody(2, options.content));
|
||||
if (path === base && method === "GET") return reply(attemptBody(1, options));
|
||||
if (path === `${base}/sessions`) return reply(attemptBody(2, options));
|
||||
if (path === `${base}/answers`) {
|
||||
recorded.answers.push(JSON.parse(request.postData() ?? "{}"));
|
||||
return reply(attemptBody(3, options.content));
|
||||
return reply(attemptBody(3, options));
|
||||
}
|
||||
if (path === `${base}/signals`) {
|
||||
const body = JSON.parse(request.postData() ?? "{}") as { events: SignalEvent[] };
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
attemptId,
|
||||
isFullscreen,
|
||||
mockAttemptApi,
|
||||
noticeVersion,
|
||||
numberContent,
|
||||
setTabHidden,
|
||||
startAttempt,
|
||||
@@ -156,5 +157,5 @@ test("closing the notice without confirming leaves fullscreen and starts nothing
|
||||
await page.getByRole("button", { name: "Подтверждаю ознакомление и начинаю" }).click();
|
||||
await expect(page.getByRole("heading", { name: "Задание 1" })).toBeVisible();
|
||||
await expect.poll(() => isFullscreen(page)).toBe(true);
|
||||
expect(recorded.acknowledgements).toEqual([{ notice_version: 2 }]);
|
||||
expect(recorded.acknowledgements).toEqual([{ notice_version: noticeVersion }]);
|
||||
});
|
||||
@@ -0,0 +1,82 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import {
|
||||
mockAttemptApi,
|
||||
numberContent,
|
||||
startAttempt,
|
||||
watermarkCode,
|
||||
} from "./assessment-attempt-mock";
|
||||
|
||||
// The watermark of a real attempt: a faint visible tile with the attempt code and
|
||||
// the time, and an invisible mark in the task text that assistive technology
|
||||
// never meets. The API is mocked: these specs check what the page does with the
|
||||
// mark the server sends, not how the server makes it.
|
||||
|
||||
const mark = "\u200b\u200c\u200d\u2060\u200b\u200c";
|
||||
const markedPrompt = `SECRET-PROMPT: which HTTP status ${mark}code means that a resource ${mark}was created?`;
|
||||
const readablePrompt = "SECRET-PROMPT: which HTTP status code means that a resource was created?";
|
||||
|
||||
test.use({ actionTimeout: 10_000, trace: "off", screenshot: "off", video: "off" });
|
||||
|
||||
test("the task screen shows a faint tile with the attempt code and the time, and nothing personal", async ({
|
||||
page,
|
||||
}) => {
|
||||
await mockAttemptApi(page, { content: numberContent });
|
||||
await startAttempt(page);
|
||||
await expect(page.getByRole("heading", { name: "Задание 1" })).toBeVisible();
|
||||
|
||||
const tile = page.getByTestId("watermark-tile");
|
||||
await expect(tile).toHaveAttribute("data-code", watermarkCode);
|
||||
await expect(tile).toHaveAttribute("aria-hidden", "true");
|
||||
const text = (await tile.textContent()) ?? "";
|
||||
expect(text).toMatch(new RegExp(`${watermarkCode} \\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}Z`));
|
||||
// The tile carries no name or contact of the candidate: the mocked account has an e-mail.
|
||||
expect(text).not.toContain("candidate@example.test");
|
||||
expect(text).not.toContain("@");
|
||||
|
||||
// It is faint, it covers the screen, and it takes no click.
|
||||
const style = await tile.evaluate((element) => {
|
||||
const mark = element.firstElementChild as HTMLElement;
|
||||
return {
|
||||
opacity: Number(getComputedStyle(mark).opacity),
|
||||
pointerEvents: getComputedStyle(element).pointerEvents,
|
||||
position: getComputedStyle(element).position,
|
||||
};
|
||||
});
|
||||
expect(style.opacity).toBeGreaterThan(0.02);
|
||||
expect(style.opacity).toBeLessThan(0.15);
|
||||
expect(style.pointerEvents).toBe("none");
|
||||
expect(style.position).toBe("fixed");
|
||||
await page.getByRole("textbox", { name: /^Числовой ответ/ }).fill("201");
|
||||
await expect(page.getByRole("textbox", { name: /^Числовой ответ/ })).toHaveValue("201");
|
||||
});
|
||||
|
||||
test("an attempt without a watermark shows no tile", async ({ page }) => {
|
||||
await mockAttemptApi(page, { content: numberContent, watermark: null });
|
||||
await startAttempt(page);
|
||||
await expect(page.getByRole("heading", { name: "Задание 1" })).toBeVisible();
|
||||
await expect(page.getByTestId("watermark-tile")).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("the invisible mark stays in the page but out of the accessibility tree", async ({ page }) => {
|
||||
await mockAttemptApi(page, { content: numberContent, prompt: markedPrompt });
|
||||
await startAttempt(page);
|
||||
await expect(page.getByRole("heading", { name: "Задание 1" })).toBeVisible();
|
||||
|
||||
const prompt = page.locator("article p").first();
|
||||
// The page keeps the mark, so that anything taken out of the page carries it.
|
||||
expect(await prompt.evaluate((element) => element.textContent)).toBe(markedPrompt);
|
||||
// Every run of invisible characters sits in an element hidden from assistive technology.
|
||||
const hidden = await prompt.evaluate((element) => {
|
||||
const runs = [...element.querySelectorAll("[data-watermark-mark]")];
|
||||
return {
|
||||
count: runs.length,
|
||||
allHidden: runs.every((run) => run.getAttribute("aria-hidden") === "true"),
|
||||
};
|
||||
});
|
||||
expect(hidden).toEqual({ count: 2, allHidden: true });
|
||||
|
||||
// The accessibility tree holds the words and no format character.
|
||||
const snapshot = await prompt.ariaSnapshot();
|
||||
expect(snapshot).toContain(readablePrompt);
|
||||
expect(snapshot).not.toMatch(/[\u200b-\u200d\u2060]/u);
|
||||
});
|
||||
@@ -806,7 +806,7 @@ test("closing the notice does not start the attempt and a confirmation is rememb
|
||||
await page.getByRole("button", { name: "Закрыть без подтверждения" }).click();
|
||||
await expect(dialog).toBeHidden();
|
||||
expect(creates).toHaveLength(0);
|
||||
expect(await readNotice(page)).toMatchObject({ acknowledged: false, notice_version: 2 });
|
||||
expect(await readNotice(page)).toMatchObject({ acknowledged: false, notice_version: 3 });
|
||||
|
||||
await start.click();
|
||||
await expect(dialog).toBeVisible();
|
||||
|
||||
Reference in new issue
Block a user