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
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user