feat(frontend): complete candidate flow and public pages
This commit is contained in:
1 parent
a69b1a79bb
commit
e4be4a3956
63 files changed
+1903
-746
No files matched your search
@@ -400,6 +400,14 @@ function scenarioAnswer(scenario: Scenario, pathname: string): Stub {
|
||||
page: { has_more: false, next_cursor: null },
|
||||
},
|
||||
};
|
||||
case "/api/v1/me/invitations":
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
items: [],
|
||||
page: { has_more: false, next_cursor: null },
|
||||
},
|
||||
};
|
||||
case "/api/v1/me/privacy":
|
||||
return { status: 200, body: scenario.privacy ?? closedPrivacy };
|
||||
default:
|
||||
|
||||
@@ -221,30 +221,26 @@ async function expectNoHorizontalOverflow(page: Page, width: number): Promise<vo
|
||||
expect(overflow, `no horizontal overflow at ${width}px`).toBe(false);
|
||||
}
|
||||
|
||||
// The list of contacts that the grant covers, found by the heading above it.
|
||||
function grantList(page: Page): Locator {
|
||||
return page
|
||||
.getByRole("heading", { name: "Контакты, которые открыты компании" })
|
||||
.locator("xpath=following-sibling::ul[1]")
|
||||
.getByRole("listitem");
|
||||
}
|
||||
|
||||
// Opens an invitation screen by an action (a link click or a direct address)
|
||||
// and waits for the view the page records once when it opens.
|
||||
async function openInvitation(
|
||||
// Opens the answer form on the candidate home and waits for its one-time view.
|
||||
async function openHomeInvitation(
|
||||
candidatePage: Page,
|
||||
invitationId: string,
|
||||
navigate: () => Promise<unknown>,
|
||||
): Promise<void> {
|
||||
organizationName: string,
|
||||
): Promise<Locator> {
|
||||
await candidatePage.goto("/candidate");
|
||||
const card = candidatePage.locator("article").filter({ hasText: organizationName });
|
||||
await expect(card).toBeVisible();
|
||||
const viewed = candidatePage.waitForResponse(
|
||||
(response) =>
|
||||
response.request().method() === "POST" &&
|
||||
new URL(response.url()).pathname === `/api/v1/me/invitations/${invitationId}/view` &&
|
||||
response.status() === 200,
|
||||
);
|
||||
await navigate();
|
||||
await card.getByRole("button", { name: "Ответить на приглашение" }).click();
|
||||
expect((await viewed).status()).toBe(200);
|
||||
await expect(candidatePage.getByRole("heading", { level: 1, name: "Приглашение" })).toBeVisible();
|
||||
await expect(card.getByRole("heading", { name: "Принять приглашение" })).toBeVisible();
|
||||
await expect(candidatePage).toHaveURL(/\/candidate\/?$/);
|
||||
return card;
|
||||
}
|
||||
|
||||
test.describe("candidate invitations with the real backend", () => {
|
||||
@@ -318,16 +314,12 @@ test.describe("candidate invitations with the real backend", () => {
|
||||
await test.step("accepts with the email only at 360px, and the organization reads the email only", async () => {
|
||||
const candidatePage = accepting.candidate.page;
|
||||
await candidatePage.setViewportSize({ width: 360, height: 900 });
|
||||
await candidatePage.goto("/candidate/invitations");
|
||||
const link = candidatePage.getByRole("link", { name: new RegExp(organizationName) });
|
||||
await expect(link).toBeVisible();
|
||||
const card = await openHomeInvitation(
|
||||
candidatePage,
|
||||
accepting.invitationId,
|
||||
organizationName,
|
||||
);
|
||||
await expectNoHorizontalOverflow(candidatePage, 360);
|
||||
await openInvitation(candidatePage, accepting.invitationId, async () => {
|
||||
await link.click();
|
||||
await expect(candidatePage).toHaveURL(
|
||||
new RegExp(`/candidate/invitations/${accepting.invitationId}$`),
|
||||
);
|
||||
});
|
||||
|
||||
// Nothing is preselected: every kind and the confirmation start unchecked.
|
||||
for (const label of ["ФИО", "Электронная почта", "Телефон"]) {
|
||||
@@ -336,7 +328,7 @@ test.describe("candidate invitations with the real backend", () => {
|
||||
).not.toBeChecked();
|
||||
}
|
||||
await expect(candidatePage.getByRole("checkbox", { name: "Telegram" })).toHaveCount(0);
|
||||
const submit = candidatePage.getByRole("button", { name: "Принять и передать контакты" });
|
||||
const submit = card.getByRole("button", { name: "Принять и передать контакты" });
|
||||
await expect(submit).toHaveAttribute("aria-disabled", "true");
|
||||
|
||||
await candidatePage
|
||||
@@ -357,8 +349,11 @@ test.describe("candidate invitations with the real backend", () => {
|
||||
await submit.click();
|
||||
expect((await accepted).status()).toBe(200);
|
||||
|
||||
await expect(candidatePage.locator('[data-state="accepted"]')).toHaveText("Принято");
|
||||
await expect(grantList(candidatePage)).toHaveText(["Электронная почта"]);
|
||||
const confirmation = candidatePage
|
||||
.getByRole("status")
|
||||
.filter({ hasText: "Приглашение принято" });
|
||||
await expect(confirmation).toBeVisible();
|
||||
await expect(confirmation.getByRole("listitem")).toHaveText(["Электронная почта"]);
|
||||
await expectNoHorizontalOverflow(candidatePage, 360);
|
||||
|
||||
// The candidate's read: exactly one granted kind.
|
||||
@@ -388,9 +383,7 @@ test.describe("candidate invitations with the real backend", () => {
|
||||
const staleId = stale.invitationId;
|
||||
const candidatePage = stale.candidate.page;
|
||||
await candidatePage.setViewportSize({ width: 360, height: 900 });
|
||||
await openInvitation(candidatePage, staleId, () =>
|
||||
candidatePage.goto(`/candidate/invitations/${staleId}`),
|
||||
);
|
||||
const card = await openHomeInvitation(candidatePage, staleId, organizationName);
|
||||
await candidatePage.getByRole("checkbox", { name: "Телефон", exact: true }).check();
|
||||
await candidatePage
|
||||
.getByRole("checkbox", { name: /Я прочитал\(а\) текст согласия/ })
|
||||
@@ -439,7 +432,7 @@ test.describe("candidate invitations with the real backend", () => {
|
||||
});
|
||||
});
|
||||
|
||||
await candidatePage.getByRole("button", { name: "Принять и передать контакты" }).click();
|
||||
await card.getByRole("button", { name: "Принять и передать контакты" }).click();
|
||||
await expect(
|
||||
candidatePage.getByRole("status").filter({ hasText: "Приглашение изменилось" }),
|
||||
).toBeVisible();
|
||||
@@ -478,8 +471,10 @@ test.describe("candidate invitations with the real backend", () => {
|
||||
await test.step("declines without a comment, keeps the decline after a reload, and discloses nothing", async () => {
|
||||
const candidatePage = declining.candidate.page;
|
||||
await candidatePage.setViewportSize({ width: 360, height: 900 });
|
||||
await openInvitation(candidatePage, declining.invitationId, () =>
|
||||
candidatePage.goto(`/candidate/invitations/${declining.invitationId}`),
|
||||
const card = await openHomeInvitation(
|
||||
candidatePage,
|
||||
declining.invitationId,
|
||||
organizationName,
|
||||
);
|
||||
await candidatePage.getByRole("radio", { name: "Другая причина", exact: true }).check();
|
||||
// No comment is written: the neutral reason never asks for one.
|
||||
@@ -490,23 +485,25 @@ test.describe("candidate invitations with the real backend", () => {
|
||||
`/api/v1/me/invitations/${declining.invitationId}/decline` &&
|
||||
response.status() === 200,
|
||||
);
|
||||
await candidatePage.getByRole("button", { name: "Отклонить приглашение" }).click();
|
||||
await card.getByRole("button", { name: "Отклонить приглашение" }).click();
|
||||
expect((await declined).status()).toBe(200);
|
||||
await expect(candidatePage.locator('[data-state="declined"]')).toHaveText(
|
||||
"Вы отклонили приглашение",
|
||||
);
|
||||
await expect(candidatePage.getByText("Причина: Другая причина.")).toBeVisible();
|
||||
|
||||
await candidatePage.reload();
|
||||
await expect(candidatePage.locator('[data-state="declined"]')).toHaveText(
|
||||
"Вы отклонили приглашение",
|
||||
);
|
||||
await expect(candidatePage.getByText("Причина: Другая причина.")).toBeVisible();
|
||||
await expect(
|
||||
candidatePage.getByRole("button", { name: "Отклонить приглашение" }),
|
||||
).toHaveCount(0);
|
||||
candidatePage.getByRole("status").filter({ hasText: "Приглашение отклонено" }),
|
||||
).toBeVisible();
|
||||
await expect(candidatePage).toHaveURL(/\/candidate\/?$/);
|
||||
await expectNoHorizontalOverflow(candidatePage, 360);
|
||||
|
||||
const declinedInvitation = await api(
|
||||
candidatePage,
|
||||
"GET",
|
||||
`/api/v1/me/invitations/${declining.invitationId}`,
|
||||
);
|
||||
expect(declinedInvitation.body).toMatchObject({
|
||||
state: "declined",
|
||||
decline: { reason: "other", comment: null },
|
||||
contact_grant: null,
|
||||
});
|
||||
|
||||
const mine = await api(
|
||||
candidatePage,
|
||||
"GET",
|
||||
|
||||
@@ -443,30 +443,48 @@ test.describe("minimal path states with a stubbed API", () => {
|
||||
"GET /api/v1/identity/sessions/current": { status: 200, body: candidateSession() },
|
||||
"GET /api/v1/me/assessment-availability": () =>
|
||||
failing ? problem("internal_error", 500) : { status: 200, body: { specializations: [] } },
|
||||
"GET /api/v1/me/profile": {
|
||||
status: 200,
|
||||
body: { version: 0, confirmed_categories: [] },
|
||||
},
|
||||
"GET /api/v1/me/questionnaire": {
|
||||
status: 200,
|
||||
body: { version: 0, specializations: [], work_context: null, updated_at: null },
|
||||
},
|
||||
"GET /api/v1/me/assessment-results": {
|
||||
status: 200,
|
||||
body: { items: [], page: { has_more: false, next_cursor: null } },
|
||||
},
|
||||
});
|
||||
await page.goto("/candidate/assessment");
|
||||
await expect(page.getByRole("alert")).toContainText(
|
||||
const availabilityRegion = page.getByRole("region", { name: "Доступность проверки" });
|
||||
await expect(availabilityRegion.getByRole("alert")).toContainText(
|
||||
"Не удалось загрузить состояние проверки",
|
||||
{ timeout: 15_000 },
|
||||
);
|
||||
const progressAlert = page
|
||||
.getByRole("alert")
|
||||
.filter({ hasText: "Не удалось загрузить прогресс" });
|
||||
await expect(progressAlert).toBeVisible();
|
||||
await expectNoHorizontalOverflow(page, width);
|
||||
failing = false;
|
||||
await tabTo(page, page.getByRole("button", { name: "Повторить" }));
|
||||
await tabTo(page, availabilityRegion.getByRole("button", { name: "Повторить" }));
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(page.getByText("Сначала выберите специализацию")).toBeVisible();
|
||||
await expect(page.getByRole("link", { name: "Открыть анкету" })).toBeVisible();
|
||||
await tabTo(page, progressAlert.getByRole("button", { name: "Повторить" }));
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(page.getByRole("heading", { name: "Профиль, анкета и тест" })).toBeVisible();
|
||||
await expect(page.getByRole("alert")).toHaveCount(0);
|
||||
await expectNoHorizontalOverflow(page, width);
|
||||
});
|
||||
|
||||
test(`candidate profile at ${width}px: loading, an error with a retry, and access denied`, async ({
|
||||
page,
|
||||
}) => {
|
||||
// The profile query does not retry, so the state changes only when the
|
||||
// candidate presses the retry button: the second answer is a 403.
|
||||
// Hold every profile read until the form's loading state is visible.
|
||||
// The form retry then answers with a 403 while the journey error remains
|
||||
// independently retryable.
|
||||
const release = deferred<void>();
|
||||
let stage: "error" | "forbidden" = "error";
|
||||
await mockApi(page, {
|
||||
@@ -475,17 +493,44 @@ test.describe("minimal path states with a stubbed API", () => {
|
||||
await release.promise;
|
||||
return stage === "error" ? problem("internal_error", 500) : problem("forbidden", 403);
|
||||
},
|
||||
"GET /api/v1/me/questionnaire": {
|
||||
status: 200,
|
||||
body: { version: 0, specializations: [], work_context: null, updated_at: null },
|
||||
},
|
||||
"GET /api/v1/me/assessment-availability": {
|
||||
status: 200,
|
||||
body: { specializations: [] },
|
||||
},
|
||||
"GET /api/v1/me/assessment-results": {
|
||||
status: 200,
|
||||
body: { items: [], page: { has_more: false, next_cursor: null } },
|
||||
},
|
||||
"GET /api/v1/me/privacy/preview": {
|
||||
status: 200,
|
||||
body: {
|
||||
state: "closed",
|
||||
fields: [],
|
||||
card: null,
|
||||
evidence: null,
|
||||
generated_at: "2026-10-09T10:00:00Z",
|
||||
},
|
||||
},
|
||||
});
|
||||
await page.goto("/candidate/profile");
|
||||
await expect(page.getByText("Загружаем профиль кандидата...")).toBeVisible();
|
||||
await expect(page.getByText("Загружаем профиль кандидата...", { exact: true })).toBeVisible();
|
||||
await expectNoHorizontalOverflow(page, width);
|
||||
release.resolve();
|
||||
await expect(page.getByRole("alert")).toContainText("Не удалось загрузить профиль");
|
||||
const profileAlert = page
|
||||
.getByRole("alert")
|
||||
.filter({ hasText: "Не удалось загрузить профиль" });
|
||||
await expect(profileAlert).toContainText("Не удалось загрузить профиль");
|
||||
stage = "forbidden";
|
||||
await tabTo(page, page.getByRole("button", { name: "Повторить" }));
|
||||
await tabTo(page, profileAlert.getByRole("button", { name: "Повторить" }));
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(page.getByText("Профиль недоступен")).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: "Повторить" })).toHaveCount(0);
|
||||
const profileForbidden = page.getByRole("status").filter({ hasText: "Профиль недоступен" });
|
||||
await expect(profileForbidden).toBeVisible();
|
||||
await expect(profileForbidden.getByRole("button", { name: "Повторить" })).toHaveCount(0);
|
||||
await expect(profileForbidden.locator("input, textarea, select")).toHaveCount(0);
|
||||
await expectNoHorizontalOverflow(page, width);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
const legalPages = [
|
||||
{ href: "/terms", linkName: "Условия использования", heading: "Условия использования" },
|
||||
{ href: "/privacy", linkName: "Конфиденциальность", heading: "Конфиденциальность" },
|
||||
] as const;
|
||||
|
||||
test("public footer links navigate to Terms and Privacy", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
|
||||
const footer = page.getByRole("contentinfo");
|
||||
for (const legalPage of legalPages) {
|
||||
await expect(
|
||||
footer.getByRole("link", { name: legalPage.linkName, exact: true }),
|
||||
).toHaveAttribute("href", legalPage.href);
|
||||
}
|
||||
|
||||
for (const legalPage of legalPages) {
|
||||
await footer.getByRole("link", { name: legalPage.linkName, exact: true }).click();
|
||||
await expect(page.getByRole("heading", { level: 1, name: legalPage.heading })).toBeVisible();
|
||||
expect(new URL(page.url()).pathname).toBe(legalPage.href);
|
||||
}
|
||||
});
|
||||
|
||||
for (const legalPage of legalPages) {
|
||||
test(`public ${legalPage.href} page loads directly and after reload`, async ({ page }) => {
|
||||
await page.goto(legalPage.href);
|
||||
|
||||
await expect(page.getByRole("heading", { level: 1, name: legalPage.heading })).toBeVisible();
|
||||
expect(new URL(page.url()).pathname).toBe(legalPage.href);
|
||||
const footer = page.getByRole("contentinfo");
|
||||
for (const linkedPage of legalPages) {
|
||||
await expect(
|
||||
footer.getByRole("link", { name: linkedPage.linkName, exact: true }),
|
||||
).toHaveAttribute("href", linkedPage.href);
|
||||
}
|
||||
|
||||
await page.reload();
|
||||
|
||||
await expect(page.getByRole("heading", { level: 1, name: legalPage.heading })).toBeVisible();
|
||||
expect(new URL(page.url()).pathname).toBe(legalPage.href);
|
||||
await expect(page).not.toHaveURL(/\/login(?:\/|$)/);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import { expect, test, type Route } from "@playwright/test";
|
||||
|
||||
const accountId = "11111111-1111-4111-8111-111111111111";
|
||||
const session = {
|
||||
account: {
|
||||
id: accountId,
|
||||
email: "visual-candidate@example.test",
|
||||
email_verified: true,
|
||||
scenario: "candidate",
|
||||
onboarding_step: "candidate_questionnaire",
|
||||
created_at: "2026-10-07T12:00:00Z",
|
||||
},
|
||||
csrf_token: "synthetic-csrf-token-for-visual-test",
|
||||
};
|
||||
|
||||
const catalog = {
|
||||
directions: [
|
||||
{
|
||||
code: "development",
|
||||
title: "Разработка",
|
||||
specializations: [
|
||||
{
|
||||
code: "backend",
|
||||
title: "Backend",
|
||||
test_availability: {
|
||||
status: "available",
|
||||
grades: ["intern", "junior", "middle"],
|
||||
task_languages: ["python", "go"],
|
||||
note: null,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: "frontend",
|
||||
title: "Frontend",
|
||||
test_availability: {
|
||||
status: "in_development",
|
||||
grades: [],
|
||||
task_languages: [],
|
||||
note: "Тест по этой специализации готовится.",
|
||||
},
|
||||
},
|
||||
{
|
||||
code: "mobile",
|
||||
title: "Мобильная разработка",
|
||||
test_availability: {
|
||||
status: "in_development",
|
||||
grades: [],
|
||||
task_languages: [],
|
||||
note: "Тест по этой специализации готовится.",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
code: "security",
|
||||
title: "Безопасность",
|
||||
specializations: [
|
||||
{
|
||||
code: "information_security",
|
||||
title: "Информационная безопасность",
|
||||
test_availability: {
|
||||
status: "in_development",
|
||||
grades: [],
|
||||
task_languages: [],
|
||||
note: "Тест по этой специализации готовится.",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
grades: [
|
||||
{ code: "intern", title: "Стажер" },
|
||||
{ code: "junior", title: "Junior" },
|
||||
{ code: "middle", title: "Middle" },
|
||||
{ code: "senior", title: "Senior" },
|
||||
],
|
||||
};
|
||||
|
||||
const questionnaire = {
|
||||
version: 0,
|
||||
specializations: [],
|
||||
work_context: null,
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
async function respond(route: Route, body: unknown): Promise<void> {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
}
|
||||
|
||||
test("shows the populated specialization catalog on desktop and mobile", async ({
|
||||
page,
|
||||
}, testInfo) => {
|
||||
await page.route("**/api/v1/**", async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
if (url.pathname === "/api/v1/identity/sessions/current") {
|
||||
await respond(route, session);
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/v1/me/profile") {
|
||||
await respond(route, { version: 0, confirmed_categories: [] });
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/v1/me/questionnaire") {
|
||||
await respond(route, questionnaire);
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/v1/me/assessment-availability") {
|
||||
await respond(route, { specializations: [] });
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/v1/me/assessment-results") {
|
||||
await respond(route, { items: [], page: { has_more: false, next_cursor: null } });
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/v1/specializations") {
|
||||
await respond(route, catalog);
|
||||
return;
|
||||
}
|
||||
await route.continue();
|
||||
});
|
||||
|
||||
await page.setViewportSize({ width: 1440, height: 1100 });
|
||||
await page.goto("/candidate/questionnaire");
|
||||
await expect(page.getByRole("heading", { level: 1, name: "Анкета" })).toBeVisible();
|
||||
const specialization = page.getByLabel("Специализация", { exact: true });
|
||||
await expect(specialization.locator("option", { hasText: "Backend" })).toHaveCount(1);
|
||||
await expect(
|
||||
specialization.locator("option", { hasText: "Информационная безопасность" }),
|
||||
).toHaveCount(1);
|
||||
await specialization.selectOption("backend");
|
||||
await expect(page.getByText(/Проверка опубликована для уровней:/)).toBeVisible();
|
||||
await page.screenshot({
|
||||
path: testInfo.outputPath("questionnaire-catalog-desktop.png"),
|
||||
fullPage: true,
|
||||
});
|
||||
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await expect(specialization).toBeVisible();
|
||||
await page.screenshot({
|
||||
path: testInfo.outputPath("questionnaire-catalog-mobile.png"),
|
||||
fullPage: true,
|
||||
});
|
||||
});
|
||||
@@ -111,7 +111,7 @@ async function signIn(page: Page, email: string): Promise<void> {
|
||||
await page.getByRole("button", { name: "Войти" }).click();
|
||||
expect((await loginResponse).status()).toBe(201);
|
||||
await page.goto("/candidate/questionnaire");
|
||||
await expect(page.getByRole("heading", { name: "Анкета" })).toBeVisible();
|
||||
await expect(page.getByRole("heading", { name: "Анкета", level: 1, exact: true })).toBeVisible();
|
||||
await expect(page.getByRole("heading", { name: "Ответы кандидата" })).toBeVisible();
|
||||
}
|
||||
|
||||
@@ -390,7 +390,9 @@ test.describe("candidate questionnaire", () => {
|
||||
.getByRole("navigation", { name: "Разделы кабинета кандидата" })
|
||||
.getByRole("link", { name: "Профиль" })
|
||||
.click();
|
||||
await expect(page.getByRole("heading", { name: "Профиль" })).toBeVisible();
|
||||
await expect(
|
||||
page.getByRole("heading", { name: "Профиль", level: 1, exact: true }),
|
||||
).toBeVisible();
|
||||
await page.route("**/api/v1/me/questionnaire", async (route) => {
|
||||
if (route.request().method() === "GET") {
|
||||
await fulfillProblem(route, 401, "unauthenticated");
|
||||
@@ -404,7 +406,10 @@ test.describe("candidate questionnaire", () => {
|
||||
response.request().method() === "GET" &&
|
||||
new URL(response.url()).pathname === "/api/v1/me/questionnaire",
|
||||
);
|
||||
await page.getByRole("link", { name: "Анкета" }).click();
|
||||
await page
|
||||
.getByRole("navigation", { name: "Разделы профиля" })
|
||||
.getByRole("link", { name: "Анкета", exact: true })
|
||||
.click();
|
||||
expect((await failedRead).status()).toBe(401);
|
||||
await expect(page.getByText("Анкета недоступна", { exact: true })).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: "Сохранить анкету" })).toHaveCount(0);
|
||||
|
||||
Reference in new issue
Block a user