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 { 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(); const progress = page.getByRole("region", { name: "Профиль, анкета и тест", exact: true }); const answers = page.getByRole("region", { name: "Ответы кандидата", exact: true }); await expect(progress).toBeVisible(); await expect(answers).toBeVisible(); const desktopProgress = await progress.boundingBox(); const desktopAnswers = await answers.boundingBox(); if (!desktopProgress || !desktopAnswers) throw new Error("Candidate sections must be visible"); expect(desktopProgress.x + desktopProgress.width).toBeLessThanOrEqual(desktopAnswers.x); await page.screenshot({ path: testInfo.outputPath("questionnaire-catalog-desktop.png"), fullPage: true, }); await page.setViewportSize({ width: 390, height: 844 }); await expect(specialization).toBeVisible(); const mobileProgress = await progress.boundingBox(); const mobileAnswers = await answers.boundingBox(); if (!mobileProgress || !mobileAnswers) throw new Error("Candidate sections must be visible"); expect(mobileProgress.y + mobileProgress.height).toBeLessThanOrEqual(mobileAnswers.y); await page.screenshot({ path: testInfo.outputPath("questionnaire-catalog-mobile.png"), fullPage: true, }); });