feat: show persisted investment data and sync state
Consume the provided resource-envelope API snapshot. Preserve financial snapshots during refresh, observe synchronization without importing, and fence late responses across account and connection changes.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { resource } from "@/test/resource";
|
||||
import "dayjs/locale/ru";
|
||||
import { MantineProvider } from "@mantine/core";
|
||||
import { DatesProvider } from "@mantine/dates";
|
||||
@@ -154,7 +155,7 @@ describe("AccountIncomePage", () => {
|
||||
"*/api/v1/brokerage-accounts/:accountId/income-analytics",
|
||||
({ request }) => {
|
||||
requested.push(new URL(request.url).search);
|
||||
return HttpResponse.json(analytics);
|
||||
return HttpResponse.json(resource(analytics));
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -236,7 +237,7 @@ describe("AccountIncomePage", () => {
|
||||
};
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts/account-1/income-analytics", () =>
|
||||
HttpResponse.json(response),
|
||||
HttpResponse.json(resource(response)),
|
||||
),
|
||||
);
|
||||
renderPage();
|
||||
@@ -284,7 +285,7 @@ describe("AccountIncomePage", () => {
|
||||
])("shows a local error for %s", async (_name, response) => {
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts/account-1/income-analytics", () =>
|
||||
HttpResponse.json(response),
|
||||
HttpResponse.json(resource(response)),
|
||||
),
|
||||
);
|
||||
renderPage();
|
||||
@@ -299,13 +300,15 @@ describe("AccountIncomePage", () => {
|
||||
it("accepts an empty analytics response", async () => {
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts/account-1/income-analytics", () =>
|
||||
HttpResponse.json({
|
||||
...analytics,
|
||||
totalsByCurrency: [],
|
||||
buckets: [],
|
||||
instruments: [],
|
||||
entries: [],
|
||||
}),
|
||||
HttpResponse.json(
|
||||
resource({
|
||||
...analytics,
|
||||
totalsByCurrency: [],
|
||||
buckets: [],
|
||||
instruments: [],
|
||||
entries: [],
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
renderPage();
|
||||
@@ -347,7 +350,7 @@ describe("AccountIncomePage", () => {
|
||||
};
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts/account-1/income-analytics", () =>
|
||||
HttpResponse.json(response),
|
||||
HttpResponse.json(resource(response)),
|
||||
),
|
||||
);
|
||||
renderPage();
|
||||
@@ -369,13 +372,15 @@ describe("AccountIncomePage", () => {
|
||||
const eventsRequest = vi.fn(() => new HttpResponse(null, { status: 503 }));
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts/account-1/income-analytics", () =>
|
||||
HttpResponse.json({
|
||||
...analytics,
|
||||
yearComparison: {
|
||||
period: { from: "2025-08-01", to: "2025-08-27" },
|
||||
totalsByCurrency: [comparison("RUB")],
|
||||
},
|
||||
}),
|
||||
HttpResponse.json(
|
||||
resource({
|
||||
...analytics,
|
||||
yearComparison: {
|
||||
period: { from: "2025-08-01", to: "2025-08-27" },
|
||||
totalsByCurrency: [comparison("RUB")],
|
||||
},
|
||||
}),
|
||||
),
|
||||
),
|
||||
http.get("*/api/v1/brokerage-accounts/account-1/events", eventsRequest),
|
||||
);
|
||||
@@ -392,13 +397,16 @@ describe("AccountIncomePage", () => {
|
||||
expect(screen.queryByText("Динамика")).not.toBeInTheDocument();
|
||||
expect(eventsRequest).not.toHaveBeenCalled();
|
||||
expect(screen.getByRole("region", { name: "Выплаты" })).toBeInTheDocument();
|
||||
const selected = screen.getByRole("region", {
|
||||
const year = screen.getByRole("region", { name: "Годом ранее" });
|
||||
const selected = within(year).getByRole("region", {
|
||||
name: "01.08.2026 – 27.08.2026",
|
||||
});
|
||||
expect(
|
||||
screen.getByRole("region", { name: "01.08.2025 – 27.08.2025" }),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.queryByText(/Предыдущий период/)).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("heading", { name: "Предыдущий период" }),
|
||||
).toBeVisible();
|
||||
expect(screen.queryByText("Выбранный период")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("Сравниваемый период")).not.toBeInTheDocument();
|
||||
expect(
|
||||
@@ -409,7 +417,7 @@ describe("AccountIncomePage", () => {
|
||||
for (const amount of ["10 ₽", "2 ₽", "12 ₽"]) {
|
||||
expect(within(selected).getByText(amount)).toBeInTheDocument();
|
||||
}
|
||||
const difference = screen.getByRole("region", { name: "Разница" });
|
||||
const difference = within(year).getByRole("region", { name: "Разница" });
|
||||
for (const amount of ["+9 ₽", "+2 ₽", "+11 ₽"]) {
|
||||
expect(within(difference).getByText(amount)).toBeInTheDocument();
|
||||
}
|
||||
@@ -425,7 +433,18 @@ describe("AccountIncomePage", () => {
|
||||
it("shows the unavailable year state without falling back to the previous period", async () => {
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts/account-1/income-analytics", () =>
|
||||
HttpResponse.json(analytics),
|
||||
HttpResponse.json(
|
||||
resource(analytics, {
|
||||
dependencies: [
|
||||
resource(analytics).meta,
|
||||
resource(analytics).meta,
|
||||
{
|
||||
...resource(null).meta,
|
||||
unavailableReason: "CALENDAR_OR_ACCOUNT_HISTORY",
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
renderPage();
|
||||
@@ -433,9 +452,11 @@ describe("AccountIncomePage", () => {
|
||||
await screen.findByText("Сравнение с годом ранее недоступно."),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByRole("region", { name: "Разница" }),
|
||||
screen.queryByRole("region", { name: "Годом ранее" }),
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.queryByText(/Предыдущий период/)).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("region", { name: "Предыдущий период" }),
|
||||
).toBeVisible();
|
||||
});
|
||||
|
||||
it("shows a recoverable realized error", async () => {
|
||||
@@ -537,13 +558,15 @@ function respondWithRequestedPeriod(requests: string[]) {
|
||||
({ request }) => {
|
||||
const url = new URL(request.url);
|
||||
requests.push(url.search);
|
||||
return HttpResponse.json({
|
||||
...analytics,
|
||||
period: {
|
||||
from: url.searchParams.get("from"),
|
||||
to: url.searchParams.get("to"),
|
||||
},
|
||||
});
|
||||
return HttpResponse.json(
|
||||
resource({
|
||||
...analytics,
|
||||
period: {
|
||||
from: url.searchParams.get("from"),
|
||||
to: url.searchParams.get("to"),
|
||||
},
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -669,7 +692,32 @@ describe("income period and snapshot boundary", () => {
|
||||
await screen.findByText(/Показан последний загруженный результат/),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByRole("region", { name: "Выплаты" })).toBeVisible();
|
||||
respondWithRequestedPeriod([]);
|
||||
server.use(
|
||||
http.post("*/api/v1/tbank-sync", () =>
|
||||
HttpResponse.json(
|
||||
{
|
||||
id: "income",
|
||||
scope: { screen: "income", accountId: "account-1" },
|
||||
now: "2026-09-25T00:00:00Z",
|
||||
},
|
||||
{ status: 202 },
|
||||
),
|
||||
),
|
||||
http.get("*/api/v1/tbank-sync/:id", () =>
|
||||
HttpResponse.json({
|
||||
id: "income",
|
||||
scope: null,
|
||||
now: "2026-09-25T00:00:00Z",
|
||||
state: "succeeded",
|
||||
errorCode: null,
|
||||
progress: { total: 1, completed: 1, discovering: false },
|
||||
resources: [resource(null, { stateVersion: "2" }).meta],
|
||||
}),
|
||||
),
|
||||
http.get("*/api/v1/brokerage-accounts/account-1/income-analytics", () =>
|
||||
HttpResponse.json(resource(analytics, { stateVersion: "2" })),
|
||||
),
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Повторить" }));
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
@@ -694,10 +742,12 @@ describe("income period and snapshot boundary", () => {
|
||||
"*/api/v1/brokerage-accounts/account-1/income-analytics",
|
||||
async () => {
|
||||
await pending;
|
||||
return HttpResponse.json({
|
||||
...analytics,
|
||||
period: { from: "2026-08-02", to: "2026-08-27" },
|
||||
});
|
||||
return HttpResponse.json(
|
||||
resource({
|
||||
...analytics,
|
||||
period: { from: "2026-08-02", to: "2026-08-27" },
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -778,3 +828,64 @@ describe("income period and snapshot boundary", () => {
|
||||
expect(screen.getAllByText("Купон")).toHaveLength(6);
|
||||
});
|
||||
});
|
||||
|
||||
it("shows selected income before comparison coverage without inventing a zero baseline", async () => {
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts/account-1/income-analytics", () =>
|
||||
HttpResponse.json(
|
||||
resource({ ...analytics, previous: null, yearComparison: null }),
|
||||
),
|
||||
),
|
||||
);
|
||||
renderPage();
|
||||
expect(await screen.findByRole("region", { name: "Выплаты" })).toBeVisible();
|
||||
expect(
|
||||
screen.queryByRole("region", { name: "Год назад" }),
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.getAllByText("12 ₽").length).toBeGreaterThan(0);
|
||||
expect(
|
||||
screen.getAllByText("Период сравнения ещё не загружен полностью."),
|
||||
).toHaveLength(2);
|
||||
expect(
|
||||
screen.queryByText("Сравнение с годом ранее недоступно."),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByRole("region", { name: "Разница" }),
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.getByLabelText("Период")).toBeVisible();
|
||||
});
|
||||
|
||||
it("keeps complete previous comparison while year source failed without inventing its amounts", async () => {
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts/account-1/income-analytics", () =>
|
||||
HttpResponse.json(
|
||||
resource(analytics, {
|
||||
dependencies: [
|
||||
resource(analytics).meta,
|
||||
resource(analytics).meta,
|
||||
{
|
||||
...resource(null).meta,
|
||||
sync: {
|
||||
id: null,
|
||||
state: "failed",
|
||||
errorCode: "TBANK_UNAVAILABLE",
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
renderPage();
|
||||
expect(
|
||||
await screen.findByRole("region", { name: "Предыдущий период" }),
|
||||
).toBeVisible();
|
||||
expect(
|
||||
screen.getByText(
|
||||
"Не удалось загрузить период сравнения. Повторите обновление.",
|
||||
),
|
||||
).toBeVisible();
|
||||
expect(
|
||||
screen.queryByRole("region", { name: "Годом ранее" }),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user