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:
@@ -17,6 +17,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router";
|
||||
|
||||
import {
|
||||
BankFeedback,
|
||||
bankOperationAppearance,
|
||||
} from "@/entities/bank-card";
|
||||
|
||||
@@ -108,6 +109,17 @@ const CardHistory: FC<CardHistoryProps> = (props) => {
|
||||
return <Text>{t("bank.noOperations")}</Text>;
|
||||
}
|
||||
|
||||
if (vm.history.error) {
|
||||
return (
|
||||
<BankFeedback
|
||||
cached={Boolean(vm.rows)}
|
||||
error={vm.history.error}
|
||||
loadingError={!vm.rows}
|
||||
retry={vm.history.refetch}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (vm.history.loading) {
|
||||
return (
|
||||
<LoadingSkeleton label={t("bank.loadingHistory")}>
|
||||
|
||||
@@ -316,12 +316,47 @@ describe("CardPage", () => {
|
||||
setup({ summaryError: true });
|
||||
await screen.findByRole("heading", { name: "Повседневная" });
|
||||
expect(
|
||||
screen.queryByRole("alert"),
|
||||
).not.toBeInTheDocument();
|
||||
await screen.findByText("Перевод на «Запасная»"),
|
||||
).toBeInTheDocument();
|
||||
expect(await screen.findByRole("alert", {}, { timeout: 5000 })).toHaveTextContent(
|
||||
"Не удалось загрузить данные карт.",
|
||||
);
|
||||
expect(screen.queryByText("0 ₽")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("recovers summary with retry while keeping card and journal", async () => {
|
||||
const { summaryRequests } = setup({ summaryError: true });
|
||||
await screen.findByRole("heading", { name: "Повседневная" });
|
||||
expect(
|
||||
await screen.findByText("Перевод на «Запасная»"),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.queryByText("0 ₽")).not.toBeInTheDocument();
|
||||
|
||||
const retry = await screen.findByRole(
|
||||
"button",
|
||||
{ name: "Повторить" },
|
||||
{ timeout: 5000 },
|
||||
);
|
||||
|
||||
const requestsBefore = summaryRequests.length;
|
||||
server.use(
|
||||
http.get("*/api/v1/bank-cards/summary", ({ request }) => {
|
||||
summaryRequests.push(new URL(request.url).search);
|
||||
|
||||
return HttpResponse.json({
|
||||
cardId: "a",
|
||||
categories: [],
|
||||
expenses: money("0"),
|
||||
net: money("-50"),
|
||||
refunds: money("50"),
|
||||
});
|
||||
}),
|
||||
);
|
||||
fireEvent.click(retry);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByRole("alert")).not.toBeInTheDocument(),
|
||||
);
|
||||
expect(summaryRequests).toHaveLength(requestsBefore + 1);
|
||||
});
|
||||
it("keeps cached card and history after refetch failure", async () => {
|
||||
const { client } = setup();
|
||||
@@ -331,9 +366,8 @@ describe("CardPage", () => {
|
||||
http.get("*/api/v1/bank-cards/a/operations", () => HttpResponse.error()),
|
||||
);
|
||||
await client.invalidateQueries();
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
||||
});
|
||||
const alerts = await screen.findAllByRole("alert", {}, { timeout: 5000 });
|
||||
expect(alerts.length).toBeGreaterThanOrEqual(1);
|
||||
expect(
|
||||
screen.getByRole("heading", { name: "Повседневная" }),
|
||||
).toBeInTheDocument();
|
||||
@@ -401,11 +435,11 @@ describe("CardPage", () => {
|
||||
]);
|
||||
});
|
||||
it("recovers the prerequisite card list while preserving the visible balance and journal", async () => {
|
||||
setup({ cardsError: true });
|
||||
const { client } = setup({ cardsError: true });
|
||||
await screen.findByText("Перевод на «Запасная»");
|
||||
expect(
|
||||
screen.queryByRole("alert"),
|
||||
).not.toBeInTheDocument();
|
||||
await screen.findByRole("alert", {}, { timeout: 5000 }),
|
||||
).toHaveTextContent("Не удалось загрузить данные карт.");
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Добавить операцию" }),
|
||||
).toBeDisabled();
|
||||
@@ -414,6 +448,7 @@ describe("CardPage", () => {
|
||||
HttpResponse.json([card, { ...card, id: "b", name: "Запасная" }]),
|
||||
),
|
||||
);
|
||||
await client.invalidateQueries();
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Добавить операцию" }),
|
||||
|
||||
@@ -75,6 +75,11 @@ const CardPageView: FC<CardPageViewProps> = (props) => {
|
||||
{t("bank.back")}
|
||||
</Button>
|
||||
|
||||
{!vm.notFound && (
|
||||
<Button onClick={vm.cardRetry} variant="default">
|
||||
{t("bank.retry")}
|
||||
</Button>
|
||||
)}
|
||||
</Group>
|
||||
)}
|
||||
error
|
||||
@@ -128,18 +133,27 @@ const CardPageView: FC<CardPageViewProps> = (props) => {
|
||||
)}
|
||||
|
||||
{card.archivedAt && <Text>{t("bank.archiveHint")}</Text>}
|
||||
|
||||
{vm.cardError && vm.card && (
|
||||
<BankFeedback
|
||||
cached
|
||||
error={vm.cardError}
|
||||
retry={vm.cardRetry}
|
||||
/>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
{vm.cardsFeedback && (
|
||||
<BankFeedback
|
||||
{...vm.cardsFeedback}
|
||||
loadingError
|
||||
retry={vm.cardsRetry}
|
||||
/>
|
||||
)}
|
||||
|
||||
<BankPeriodPicker onChange={vm.setPeriod} period={vm.period} />
|
||||
|
||||
<BankSummaryView {...vm.summary} />
|
||||
<BankSummaryView {...vm.summary} retry={vm.summary.refetch} />
|
||||
|
||||
<Group align="end" justify="space-between">
|
||||
<Group gap="xs">
|
||||
@@ -183,8 +197,6 @@ const CardPageView: FC<CardPageViewProps> = (props) => {
|
||||
<CardHistory history={vm.history} period={vm.period} rows={vm.rows} />
|
||||
</Stack>
|
||||
|
||||
{vm.history.error && !vm.rows && <Text role="alert">{t("bank.error")}</Text>}
|
||||
|
||||
{vm.history.page !== undefined && vm.pageSize !== "all" && (
|
||||
<Group
|
||||
aria-label={t("bank.pagination")}
|
||||
|
||||
@@ -97,13 +97,16 @@ function useCardPageVm() {
|
||||
archivePending: updateCard.isPending,
|
||||
canAddOperation: !card.data?.archivedAt && Boolean(cards.data),
|
||||
card: card.data,
|
||||
cardError: card.error,
|
||||
cardLoading: card.isLoading,
|
||||
cardRefreshError: card.isError,
|
||||
cardRefreshing: card.isFetching,
|
||||
cardRetry: () => card.refetch(),
|
||||
cards: cards.data,
|
||||
cardsFeedback: cards.isError
|
||||
? { cached: Boolean(cards.data), error: cards.error }
|
||||
: undefined,
|
||||
cardsRetry: () => cards.refetch(),
|
||||
closeDeletion: () => setDeleting(null),
|
||||
closeEditing: () => setEditingCard(false),
|
||||
closeOperation: () => setOperation(null),
|
||||
@@ -112,9 +115,10 @@ function useCardPageVm() {
|
||||
editingCard,
|
||||
history: {
|
||||
changingPage: history.isPlaceholderData,
|
||||
error: history.isError,
|
||||
error: history.error,
|
||||
loading: history.isLoading,
|
||||
page: history.data?.page,
|
||||
refetch: () => history.refetch(),
|
||||
},
|
||||
notFound: isApiErrorCode(
|
||||
apiErrorCode(card.error),
|
||||
@@ -139,9 +143,10 @@ function useCardPageVm() {
|
||||
},
|
||||
summary: {
|
||||
data: summary.data,
|
||||
error: summary.isError,
|
||||
error: summary.error,
|
||||
fetching: summary.isFetching,
|
||||
loading: summary.isLoading,
|
||||
refetch: () => summary.refetch(),
|
||||
},
|
||||
toggleArchive: () => {
|
||||
if (!card.data) return;
|
||||
|
||||
Reference in New Issue
Block a user