test(e2e): register assessment response waits right before their actions
This commit is contained in:
1 parent
cb08f212cc
commit
a38d7571ea
1 file changed
+29
-20
@@ -197,13 +197,15 @@ async function answerRequiredNumericItems(
|
|||||||
await focusWithKeyboard(page, answerField);
|
await focusWithKeyboard(page, answerField);
|
||||||
await page.keyboard.type("1");
|
await page.keyboard.type("1");
|
||||||
|
|
||||||
|
const submitButton = page.getByRole("button", { name: "Отправить ответ" });
|
||||||
|
await focusWithKeyboard(page, submitButton);
|
||||||
|
// A response wait expires after the action timeout counted from its
|
||||||
|
// registration, so it is registered only right before the key press.
|
||||||
const answerResponsePromise = page.waitForResponse(
|
const answerResponsePromise = page.waitForResponse(
|
||||||
(response) =>
|
(response) =>
|
||||||
response.request().method() === "POST" &&
|
response.request().method() === "POST" &&
|
||||||
new URL(response.url()).pathname === `/api/v1/me/assessment-attempts/${attemptId}/answers`,
|
new URL(response.url()).pathname === `/api/v1/me/assessment-attempts/${attemptId}/answers`,
|
||||||
);
|
);
|
||||||
const submitButton = page.getByRole("button", { name: "Отправить ответ" });
|
|
||||||
await focusWithKeyboard(page, submitButton);
|
|
||||||
await page.keyboard.press("Enter");
|
await page.keyboard.press("Enter");
|
||||||
expect((await answerResponsePromise).status()).toBe(200);
|
expect((await answerResponsePromise).status()).toBe(200);
|
||||||
submitted += 1;
|
submitted += 1;
|
||||||
@@ -308,6 +310,8 @@ test("candidate can review, resume, and finish separate assessment modes", async
|
|||||||
await expect(page.getByRole("button", { name: "Завершить проверку" })).toBeVisible();
|
await expect(page.getByRole("button", { name: "Завершить проверку" })).toBeVisible();
|
||||||
await expect(page.getByRole("heading", { name: "Результат с сервера" })).toHaveCount(0);
|
await expect(page.getByRole("heading", { name: "Результат с сервера" })).toHaveCount(0);
|
||||||
|
|
||||||
|
const finalizeRootButton = page.getByRole("button", { name: "Завершить проверку" });
|
||||||
|
await focusWithKeyboard(page, finalizeRootButton);
|
||||||
const finalizeRealResponsePromise = page.waitForResponse(
|
const finalizeRealResponsePromise = page.waitForResponse(
|
||||||
(response) =>
|
(response) =>
|
||||||
response.request().method() === "POST" &&
|
response.request().method() === "POST" &&
|
||||||
@@ -321,8 +325,6 @@ test("candidate can review, resume, and finish separate assessment modes", async
|
|||||||
new URL(response.url()).pathname ===
|
new URL(response.url()).pathname ===
|
||||||
`/api/v1/me/assessment-attempts/${realAttempt.id}/result`,
|
`/api/v1/me/assessment-attempts/${realAttempt.id}/result`,
|
||||||
);
|
);
|
||||||
const finalizeRootButton = page.getByRole("button", { name: "Завершить проверку" });
|
|
||||||
await focusWithKeyboard(page, finalizeRootButton);
|
|
||||||
await page.keyboard.press("Enter");
|
await page.keyboard.press("Enter");
|
||||||
expect((await finalizeRealResponsePromise).status()).toBe(200);
|
expect((await finalizeRealResponsePromise).status()).toBe(200);
|
||||||
const resultResponse = await resultResponsePromise;
|
const resultResponse = await resultResponsePromise;
|
||||||
@@ -487,28 +489,28 @@ test("candidate can review, resume, and finish separate assessment modes", async
|
|||||||
const answerField = page.getByRole("textbox", { name: /^Числовой ответ/ });
|
const answerField = page.getByRole("textbox", { name: /^Числовой ответ/ });
|
||||||
await focusWithKeyboard(page, answerField);
|
await focusWithKeyboard(page, answerField);
|
||||||
await page.keyboard.type("1");
|
await page.keyboard.type("1");
|
||||||
|
const submitButton = page.getByRole("button", { name: "Отправить ответ" });
|
||||||
|
await focusWithKeyboard(page, submitButton);
|
||||||
const answerResponsePromise = page.waitForResponse(
|
const answerResponsePromise = page.waitForResponse(
|
||||||
(response) =>
|
(response) =>
|
||||||
response.request().method() === "POST" &&
|
response.request().method() === "POST" &&
|
||||||
new URL(response.url()).pathname ===
|
new URL(response.url()).pathname ===
|
||||||
`/api/v1/me/assessment-attempts/${expressAttempt.id}/answers`,
|
`/api/v1/me/assessment-attempts/${expressAttempt.id}/answers`,
|
||||||
);
|
);
|
||||||
const submitButton = page.getByRole("button", { name: "Отправить ответ" });
|
|
||||||
await focusWithKeyboard(page, submitButton);
|
|
||||||
await page.keyboard.press("Enter");
|
await page.keyboard.press("Enter");
|
||||||
expect((await answerResponsePromise).status()).toBe(200);
|
expect((await answerResponsePromise).status()).toBe(200);
|
||||||
if (sequence < 3)
|
if (sequence < 3)
|
||||||
await expect(page.getByRole("heading", { name: `Задание ${sequence + 1}` })).toBeVisible();
|
await expect(page.getByRole("heading", { name: `Задание ${sequence + 1}` })).toBeVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const finalizeButton = page.getByRole("button", { name: "Завершить проверку" });
|
||||||
|
await focusWithKeyboard(page, finalizeButton);
|
||||||
const finalizeResponsePromise = page.waitForResponse(
|
const finalizeResponsePromise = page.waitForResponse(
|
||||||
(response) =>
|
(response) =>
|
||||||
response.request().method() === "POST" &&
|
response.request().method() === "POST" &&
|
||||||
new URL(response.url()).pathname ===
|
new URL(response.url()).pathname ===
|
||||||
`/api/v1/me/assessment-attempts/${expressAttempt.id}/finalize`,
|
`/api/v1/me/assessment-attempts/${expressAttempt.id}/finalize`,
|
||||||
);
|
);
|
||||||
const finalizeButton = page.getByRole("button", { name: "Завершить проверку" });
|
|
||||||
await focusWithKeyboard(page, finalizeButton);
|
|
||||||
await page.keyboard.press("Enter");
|
await page.keyboard.press("Enter");
|
||||||
expect((await finalizeResponsePromise).status()).toBe(200);
|
expect((await finalizeResponsePromise).status()).toBe(200);
|
||||||
await expect(
|
await expect(
|
||||||
@@ -871,11 +873,14 @@ function isFinalizeResponse(response: Response, attemptId: string): boolean {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates an attempt from the assessment page, resumes it, and answers every item. */
|
/**
|
||||||
|
* Creates an attempt from the assessment page, resumes it, answers every item,
|
||||||
|
* and finalizes it. Returns the attempt ID and the stored result the page read.
|
||||||
|
*/
|
||||||
async function runAttemptToResult(
|
async function runAttemptToResult(
|
||||||
page: Page,
|
page: Page,
|
||||||
start: { name: string; confirmNotice: boolean },
|
start: { name: string; confirmNotice: boolean },
|
||||||
): Promise<string> {
|
): Promise<{ id: string; result: Response }> {
|
||||||
const createResponse = page.waitForResponse(
|
const createResponse = page.waitForResponse(
|
||||||
(response) =>
|
(response) =>
|
||||||
response.request().method() === "POST" &&
|
response.request().method() === "POST" &&
|
||||||
@@ -895,13 +900,23 @@ async function runAttemptToResult(
|
|||||||
const resumed = (await (await resumeResponse).json()) as AttemptSnapshot;
|
const resumed = (await (await resumeResponse).json()) as AttemptSnapshot;
|
||||||
await answerRequiredNumericItems(page, attempt.id, resumed.progress.max_items);
|
await answerRequiredNumericItems(page, attempt.id, resumed.progress.max_items);
|
||||||
|
|
||||||
|
// The result is read only after the finalize command succeeds, so both waits
|
||||||
|
// start right before that click. A wait registered before the whole run
|
||||||
|
// would expire after the action timeout while items are still answered.
|
||||||
const finalizeResponse = page.waitForResponse((response) =>
|
const finalizeResponse = page.waitForResponse((response) =>
|
||||||
isFinalizeResponse(response, attempt.id),
|
isFinalizeResponse(response, attempt.id),
|
||||||
);
|
);
|
||||||
|
const resultResponse = page.waitForResponse(
|
||||||
|
(response) =>
|
||||||
|
response.request().method() === "GET" &&
|
||||||
|
response.status() === 200 &&
|
||||||
|
new URL(response.url()).pathname === `/api/v1/me/assessment-attempts/${attempt.id}/result`,
|
||||||
|
);
|
||||||
await page.getByRole("button", { name: "Завершить проверку" }).click();
|
await page.getByRole("button", { name: "Завершить проверку" }).click();
|
||||||
expect((await finalizeResponse).status()).toBe(200);
|
expect((await finalizeResponse).status()).toBe(200);
|
||||||
|
const result = await resultResponse;
|
||||||
await expect(page.getByRole("heading", { name: resultHeading })).toBeVisible();
|
await expect(page.getByRole("heading", { name: resultHeading })).toBeVisible();
|
||||||
return attempt.id;
|
return { id: attempt.id, result };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function signOut(page: Page): Promise<void> {
|
async function signOut(page: Page): Promise<void> {
|
||||||
@@ -955,17 +970,11 @@ test("results keep the express run apart and stay private to the signed-in candi
|
|||||||
await page.getByLabel("Язык задания").selectOption("python");
|
await page.getByLabel("Язык задания").selectOption("python");
|
||||||
|
|
||||||
// The full result: method, date, category state, and the provisional status.
|
// The full result: method, date, category state, and the provisional status.
|
||||||
const realResult = page.waitForResponse(
|
const { id: realId, result: realResult } = await runAttemptToResult(page, {
|
||||||
(response) =>
|
|
||||||
response.request().method() === "GET" &&
|
|
||||||
response.status() === 200 &&
|
|
||||||
/^\/api\/v1\/me\/assessment-attempts\/[^/]+\/result$/.test(new URL(response.url()).pathname),
|
|
||||||
);
|
|
||||||
const realId = await runAttemptToResult(page, {
|
|
||||||
name: "Начать полную проверку",
|
name: "Начать полную проверку",
|
||||||
confirmNotice: true,
|
confirmNotice: true,
|
||||||
});
|
});
|
||||||
const stored = (await (await realResult).json()) as { mode: "demo_basic" | "adaptive" };
|
const stored = (await realResult.json()) as { mode: "demo_basic" | "adaptive" };
|
||||||
// Only a short phrase is a live message; the record is ordinary content and
|
// Only a short phrase is a live message; the record is ordinary content and
|
||||||
// the focus moved to its heading.
|
// the focus moved to its heading.
|
||||||
await expect(page.getByRole("heading", { name: resultHeading })).toBeFocused();
|
await expect(page.getByRole("heading", { name: resultHeading })).toBeFocused();
|
||||||
@@ -990,7 +999,7 @@ test("results keep the express run apart and stay private to the signed-in candi
|
|||||||
// The express run is a demonstration: no category, and it offers the full test.
|
// The express run is a demonstration: no category, and it offers the full test.
|
||||||
await page.goto("/candidate/assessment");
|
await page.goto("/candidate/assessment");
|
||||||
await expect(page.getByRole("button", { name: "Начать демонстрацию" })).toBeVisible();
|
await expect(page.getByRole("button", { name: "Начать демонстрацию" })).toBeVisible();
|
||||||
const expressId = await runAttemptToResult(page, {
|
const { id: expressId } = await runAttemptToResult(page, {
|
||||||
name: "Начать демонстрацию",
|
name: "Начать демонстрацию",
|
||||||
confirmNotice: false,
|
confirmNotice: false,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user