refactor: enforce frontend view model boundaries
Frontend verify / commits (pull_request) Successful in 28s
Frontend verify / security (pull_request) Successful in 10s
Frontend verify / verify (pull_request) Successful in 8m19s

This commit is contained in:
2026-09-28 18:48:23 +03:00
parent 5b69003516
commit ca0ad4f824
287 changed files with 8558 additions and 4538 deletions
@@ -20,9 +20,11 @@ describe("useBrokerageEvents", () => {
server.use(
http.get("*/api/v1/brokerage-accounts/:accountId/events", requested),
);
const { result } = renderHook(() => useBrokerageEvents(undefined), {
wrapper: createQueryWrapper().wrapper,
});
await waitFor(() => expect(result.current.fetchStatus).toBe("idle"));
expect(requested).not.toHaveBeenCalled();
});
@@ -35,7 +37,8 @@ describe("useBrokerageEvents", () => {
server.use(
http.get("*/api/v1/brokerage-accounts/account-1/events", () =>
HttpResponse.json(
resource((/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
resource(
{
accountId: "account-1",
calculatedAt: "2026-08-14T00:00:00Z",
@@ -52,8 +55,9 @@ describe("useBrokerageEvents", () => {
type: "dividend",
},
],
}
/* eslint-enable unicorn/no-null */)),
},
/* eslint-enable unicorn/no-null */
),
),
),
);
@@ -63,20 +67,20 @@ describe("useBrokerageEvents", () => {
});
await waitFor(() => expect(result.current.isSuccess).toBe(true));
/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
expect(result.current.data?.events).toEqual([
(/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
{
date: "2026-09-01",
dateKind: "registry",
displayName: "Сбер",
figi: "figi-1",
instrumentUid: null,
logoName: "sber3.png",
projectedAmount: { currency: "RUB", value: "12.34" },
ticker: "SBER",
type: "dividend",
}
/* eslint-enable unicorn/no-null */),
{
date: "2026-09-01",
dateKind: "registry",
displayName: "Сбер",
figi: "figi-1",
instrumentUid: null,
logoName: "sber3.png",
projectedAmount: { currency: "RUB", value: "12.34" },
ticker: "SBER",
type: "dividend",
},
/* eslint-enable unicorn/no-null */
]);
});
});
@@ -3,6 +3,7 @@ import { apiQueryClient, type paths, useResourceQuery } from "@/shared/api";
type BrokerageEvent = NonNullable<
EventsEndpoint["responses"][200]["content"]["application/json"]["data"]
>["events"][number];
type EventsEndpoint
= paths["/api/v1/brokerage-accounts/{accountId}/events"]["get"];
@@ -17,13 +17,19 @@ const BrokerageEventCard: FC<BrokerageEventCardProps> = (props) => {
const metadata = [
date,
event.dateKind === "registry" ? t("events.dateKind.registry") : /* eslint-disable-line unicorn/no-null -- Preserve the nullable domain value consumed by this view model. */ null,
event.dateKind === "registry"
? t("events.dateKind.registry")
: null, // eslint-disable-line unicorn/no-null -- Preserve the nullable domain value consumed by this view model.
event.isin,
event.account?.name,
]
.filter(Boolean)
.join(" · ");
const projectedAmount = event.projectedAmount
? formatMoney(event.projectedAmount)
: t("events.noAmount");
return (
<EntryCard
imageSrc={instrumentLogoUrl(event.logoName)}
@@ -33,11 +39,7 @@ const BrokerageEventCard: FC<BrokerageEventCardProps> = (props) => {
metadata={metadata}
title={[t(`events.type.${event.type}`), event.displayName].join(" · ")}
tone="neutral"
value={
event.projectedAmount
? formatMoney(event.projectedAmount)
: t("events.noAmount")
}
value={projectedAmount}
valueLabel={t("events.projectedAmount")}
/>
);
@@ -6,20 +6,21 @@ import type { BrokerageEvent } from "../../api/useBrokerageEvents";
import { BrokerageEventsPreview } from "./BrokerageEventsPreview";
const syntheticEvent = (/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
{
date: "2026-10-15",
dateKind: "event",
displayName: "Учебные облигации",
figi: null,
instrumentUid: null,
isin: "RU000A0JX0J2",
logoName: null,
projectedAmount: { currency: "RUB", value: "850.50" },
ticker: "DEMO",
type: "coupon",
}
/* eslint-enable unicorn/no-null */) satisfies BrokerageEvent;
/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
const syntheticEvent
= {
date: "2026-10-15",
dateKind: "event",
displayName: "Учебные облигации",
figi: null,
instrumentUid: null,
isin: "RU000A0JX0J2",
logoName: null,
projectedAmount: { currency: "RUB", value: "850.50" },
ticker: "DEMO",
type: "coupon",
} satisfies /* eslint-enable unicorn/no-null */ BrokerageEvent;
const eventsPath = "/accounts/storybook-account/events";
@@ -120,8 +121,10 @@ export const Empty: Story = {
},
};
export const MissingAmount: Story = (/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
{
/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
export const MissingAmount: Story
= {
args: {
events: {
items: [{ ...syntheticEvent, projectedAmount: null }],
@@ -134,22 +137,24 @@ export const MissingAmount: Story = (/* eslint-disable unicorn/no-null -- Fixtur
docs: {
description: {
story:
"Событие остаётся видимым при неизвестной ожидаемой сумме. Отсутствие оценки не подменяется нулевой выплатой.",
"Событие остаётся видимым при неизвестной ожидаемой сумме. Отсутствие оценки не подменяется нулевой выплатой.",
},
},
},
}
/* eslint-enable unicorn/no-null */);
};
/* eslint-enable unicorn/no-null */
export const LongEvent: Story = (/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
{
/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
export const LongEvent: Story
= {
args: {
events: {
items: [
{
...syntheticEvent,
displayName:
"Учебные облигации компании с очень длинным названием инструмента",
"Учебные облигации компании с очень длинным названием инструмента",
projectedAmount: null,
type: "offer",
},
@@ -159,5 +164,5 @@ export const LongEvent: Story = (/* eslint-disable unicorn/no-null -- Fixture pr
},
},
name: "Длинное название на узком экране",
}
/* eslint-enable unicorn/no-null */);
};
/* eslint-enable unicorn/no-null */
@@ -24,7 +24,9 @@ type BrokerageEventsPreviewState
state: "loaded" | "partial";
to: string;
}
| { state: "empty" | "error" | "loading"; to: string };
| { state: "empty"
| "error"
| "loading"; to: string; };
const BrokerageEventsPreview: FC<BrokerageEventsPreviewProps> = (props) => {
const { events } = props;
@@ -32,51 +34,60 @@ const BrokerageEventsPreview: FC<BrokerageEventsPreviewProps> = (props) => {
return (
<Stack gap="sm">
{(events.state === "loaded") && ((
{events.state === "loaded" && (
<>
{!!(events.lastSuccessfulAt) && ((
{!!events.lastSuccessfulAt && (
<Text c="dimmed" size="xs">
{t("investment.sourceTime", {
date: formatSnapshotTime(events.lastSuccessfulAt),
})}
</Text>
))}
{!!(events.stale) && (<Text size="xs">{t("investment.stale")}</Text>)}
{!!(events.refreshError) && ((
)}
{!!events.stale && <Text size="xs">{t("investment.stale")}</Text>}
{!!events.refreshError && (
<Text role="status">{t("accounts.refreshError")}</Text>
))}
)}
</>
))}
{(events.state === "loading") && ((
)}
{events.state === "loading" && (
<LoadingSkeleton label={t("events.recentLoading")}>
{["first", "second", "third"].map(placeholder => (
<Skeleton height={48} key={placeholder} radius="sm" />
))}
</LoadingSkeleton>
))}
{(events.state === "error") && ((
)}
{events.state === "error" && (
<Alert color="red">{t("events.recentError")}</Alert>
))}
{(events.state === "empty") && ((
)}
{events.state === "empty" && (
<Text c="dimmed">{t("events.recentEmpty")}</Text>
))}
{(events.state === "partial") && ((
)}
{events.state === "partial" && (
<Text role="status">{t("investment.partial")}</Text>
))}
{(events.state === "loaded" || events.state === "partial") && (events.items.map(event => (
<BrokerageEventCard
event={event}
key={JSON.stringify([
event.account?.id,
event.type,
event.date,
event.instrumentUid,
event.figi,
event.ticker,
event.logoName,
])}
/>
)))}
)}
{(events.state === "loaded" || events.state === "partial")
&& events.items.map(event => (
<BrokerageEventCard
event={event}
key={JSON.stringify([
event.account?.id,
event.type,
event.date,
event.instrumentUid,
event.figi,
event.ticker,
event.logoName,
])}
/>
))}
<Button component={Link} to={events.to} variant="subtle">
{t("events.open")}
</Button>