AuthForm disables the switch-auth Link while submit is pending so pointer click and Enter can no longer leave the auth route and lose the draft/error context. The form restores a true Link after the request settles. CardsPage/CardPage distinguish cold vs cached banking failures: - cold card/section errors expose accessible alert + retry - cached failures keep the previous data and offer a section GET retry - summary-only/history-only outages do not hide successful sections - notFound still skips the retry CTA Tests cover the pending link guard, cold/cached cards error with retry, summary failure with retry, and the prerequisite card list recovery. Closes #56, #57
74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import { MantineProvider } from "@mantine/core";
|
|
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
import { MemoryRouter } from "react-router";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { AuthForm } from "./AuthForm";
|
|
|
|
describe("AuthForm", () => {
|
|
it("does not submit registration when password confirmation differs", async () => {
|
|
const onSubmit = vi.fn();
|
|
render(
|
|
<MantineProvider>
|
|
<MemoryRouter>
|
|
<AuthForm onSubmit={onSubmit} register />
|
|
</MemoryRouter>
|
|
</MantineProvider>,
|
|
);
|
|
|
|
fireEvent.change(screen.getByLabelText("Email"), {
|
|
target: { value: "user@example.com" },
|
|
});
|
|
fireEvent.change(screen.getByLabelText("Пароль"), {
|
|
target: { value: "a secure password" },
|
|
});
|
|
fireEvent.change(screen.getByLabelText("Подтвердите пароль"), {
|
|
target: { value: "another secure password" },
|
|
});
|
|
fireEvent.click(screen.getByRole("button", { name: "Регистрация" }));
|
|
|
|
await waitFor(() => expect(onSubmit).not.toHaveBeenCalled());
|
|
expect(await screen.findByText("Пароли не совпадают")).toBeInTheDocument();
|
|
});
|
|
|
|
it.each([
|
|
["register", "Регистрация", "Уже есть аккаунт? Войти"],
|
|
["login", "Вход", "Нет аккаунта? Зарегистрироваться"],
|
|
])("blocks the switch-auth link while %s is submitting", async (_mode, submitLabel, linkLabel) => {
|
|
const { promise, resolve } = Promise.withResolvers<void>();
|
|
const onSubmit = vi.fn(() => promise);
|
|
render(
|
|
<MantineProvider>
|
|
<MemoryRouter>
|
|
<AuthForm
|
|
onSubmit={onSubmit}
|
|
register={_mode === "register"}
|
|
/>
|
|
</MemoryRouter>
|
|
</MantineProvider>,
|
|
);
|
|
|
|
fireEvent.change(screen.getByLabelText("Email"), {
|
|
target: { value: "user@example.com" },
|
|
});
|
|
fireEvent.change(screen.getByLabelText("Пароль"), {
|
|
target: { value: "a secure password" },
|
|
});
|
|
|
|
if (_mode === "register") {
|
|
fireEvent.change(screen.getByLabelText("Подтвердите пароль"), {
|
|
target: { value: "a secure password" },
|
|
});
|
|
}
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: submitLabel }));
|
|
|
|
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
|
expect(screen.queryByRole("link", { name: linkLabel })).not.toBeInTheDocument();
|
|
expect(screen.getByRole("button", { name: linkLabel })).toBeDisabled();
|
|
|
|
resolve();
|
|
await screen.findByRole("link", { name: linkLabel });
|
|
});
|
|
});
|