fix(auth,bank): guard switch-auth nav and surface banking retry
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
This commit is contained in:
@@ -47,8 +47,9 @@ function renderCards(isFail = false, hasCategoryFailure = false) {
|
||||
),
|
||||
);
|
||||
|
||||
return render(
|
||||
<QueryClientProvider client={createTestQueryClient()}>
|
||||
const client = createTestQueryClient();
|
||||
render(
|
||||
<QueryClientProvider client={client}>
|
||||
<MantineProvider env="test">
|
||||
<MemoryRouter initialEntries={["/cards?month=2026-09"]}>
|
||||
<CardsPage />
|
||||
@@ -56,6 +57,8 @@ function renderCards(isFail = false, hasCategoryFailure = false) {
|
||||
</MantineProvider>
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
describe("CardsPage", () => {
|
||||
@@ -232,4 +235,76 @@ describe("CardsPage", () => {
|
||||
});
|
||||
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows a cold cards error with retry", async () => {
|
||||
renderCards(true);
|
||||
|
||||
expect(
|
||||
await screen.findByRole("alert", {}, { timeout: 5000 }),
|
||||
).toHaveTextContent("Не удалось загрузить данные карт.");
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Повторить" }),
|
||||
).toBeInTheDocument();
|
||||
|
||||
server.use(
|
||||
http.get("*/api/v1/bank-cards", () =>
|
||||
HttpResponse.json([
|
||||
{
|
||||
archivedAt: null,
|
||||
balance: money("10000"),
|
||||
bankName: null,
|
||||
id: "a",
|
||||
lastFour: null,
|
||||
name: "Повседневная",
|
||||
openingBalance: money("10000"),
|
||||
openingDate: "2026-01-01",
|
||||
version: 1,
|
||||
},
|
||||
]),
|
||||
),
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Повторить" }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByRole("alert")).not.toBeInTheDocument(),
|
||||
);
|
||||
expect(
|
||||
screen.getByRole("link", { name: /Повседневная/ }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows a cached cards error while keeping the grid", async () => {
|
||||
const view = renderCards();
|
||||
|
||||
await screen.findByRole("heading", { name: "Добавьте первую карту" });
|
||||
server.use(
|
||||
http.get("*/api/v1/bank-cards", () =>
|
||||
HttpResponse.json([
|
||||
{
|
||||
archivedAt: null,
|
||||
balance: money("10000"),
|
||||
bankName: null,
|
||||
id: "a",
|
||||
lastFour: null,
|
||||
name: "Повседневная",
|
||||
openingBalance: money("10000"),
|
||||
openingDate: "2026-01-01",
|
||||
version: 1,
|
||||
},
|
||||
]),
|
||||
),
|
||||
);
|
||||
await view.invalidateQueries();
|
||||
await screen.findByRole("link", { name: /Повседневная/ });
|
||||
|
||||
server.use(http.get("*/api/v1/bank-cards", () => HttpResponse.error()));
|
||||
await view.invalidateQueries();
|
||||
|
||||
expect(
|
||||
await screen.findByRole("alert", {}, { timeout: 5000 }),
|
||||
).toHaveTextContent("Не удалось обновить данные. Показаны последние полученные.");
|
||||
expect(
|
||||
screen.getByRole("link", { name: /Повседневная/ }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user