feat(investments): warn and offer retry after exhausted read retries (WealthLedger/frontend#55) (#136)
This commit was merged in pull request #136.
This commit is contained in:
@@ -81,6 +81,7 @@ function setup(
|
||||
candles?: NonNullable<StockPageVm["candles"]>["candles"];
|
||||
cursorError?: string;
|
||||
failCompany?: boolean;
|
||||
failCompanyAfter?: { value: boolean };
|
||||
failStock?: boolean;
|
||||
metrics?: NonNullable<StockPageVm["company"]>["metrics"];
|
||||
noPosition?: boolean;
|
||||
@@ -133,7 +134,7 @@ function setup(
|
||||
),
|
||||
);
|
||||
if (params.section === "company")
|
||||
return options.failCompany
|
||||
return (options.failCompanyAfter?.value ?? options.failCompany)
|
||||
? HttpResponse.json({ code: "TBANK_UNAVAILABLE" }, { status: 503 })
|
||||
: HttpResponse.json(
|
||||
|
||||
@@ -396,7 +397,6 @@ describe("stock page", () => {
|
||||
screen.queryByRole("heading", { name: "Моя позиция" }),
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("heading", { name: "График цены" })).toBeVisible();
|
||||
expect(screen.queryByRole("button", { name: "Повторить" })).not.toBeInTheDocument();
|
||||
});
|
||||
it("keeps successful sections visible when company data is initially missing", async () => {
|
||||
const { requests } = setup({ failCompany: true });
|
||||
@@ -404,8 +404,39 @@ describe("stock page", () => {
|
||||
const previousRequests = requests.length;
|
||||
expect(screen.getByText("Зачисление дивидендов")).toBeVisible();
|
||||
expect(requests).toHaveLength(previousRequests);
|
||||
expect(screen.queryByRole("button", { name: "Повторить" })).not.toBeInTheDocument();
|
||||
});
|
||||
it(
|
||||
"retries only the failed company section and recovers it in place",
|
||||
{ timeout: 10_000 },
|
||||
async () => {
|
||||
const failing = { value: true };
|
||||
const { requests } = setup({ failCompanyAfter: failing });
|
||||
await screen.findByText("Зачисление дивидендов");
|
||||
|
||||
// Automatic read retries wait 1s + 2s before the failure is final.
|
||||
const retry = await screen.findByRole(
|
||||
"button",
|
||||
{ name: "Повторить" },
|
||||
{ timeout: 6000 },
|
||||
);
|
||||
|
||||
expect(screen.getByRole("heading", { name: "График цены" })).toBeVisible();
|
||||
expect(screen.getAllByRole("button", { name: "Повторить" })).toHaveLength(1);
|
||||
const before = requests.length;
|
||||
const companyBefore = requests.filter(url => url.pathname.endsWith("/company")).length;
|
||||
|
||||
failing.value = false;
|
||||
fireEvent.click(retry);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByRole("button", { name: "Повторить" }))
|
||||
.not.toBeInTheDocument());
|
||||
expect(requests.filter(url => url.pathname.endsWith("/company")))
|
||||
.toHaveLength(companyBefore + 1);
|
||||
expect(requests.length - before).toBe(1);
|
||||
expect(screen.getByText("Описание компании")).toBeVisible();
|
||||
},
|
||||
);
|
||||
it("sends instrument-filtered continuation, restores it on returning to the filter and changes chart period", async () => {
|
||||
const { requests } = setup();
|
||||
await screen.findByText("Зачисление дивидендов");
|
||||
|
||||
Reference in New Issue
Block a user