This commit was merged in pull request #165.
This commit is contained in:
@@ -55,23 +55,27 @@ function renderGroup(
|
||||
}
|
||||
|
||||
describe("OperationGroup", () => {
|
||||
it("shows the header, exact total and separate card rows per account", () => {
|
||||
it("shows the received coupon and positive totals in flat account rows", () => {
|
||||
renderGroup([
|
||||
operation("1", { id: "broker", name: "Брокерский" }, "0.1"),
|
||||
{ ...operation("1", { id: "broker", name: "Брокерский" }, "0.1"), description: "Выплата купонов СФО ВТБ РКС Эталон 04" },
|
||||
operation("2", { id: "iis", name: "ИИС" }, "0.2"),
|
||||
]);
|
||||
|
||||
expect(screen.getByText("Купон · BOND")).toBeInTheDocument();
|
||||
expect(screen.getByText("Выплата купонов СФО ВТБ РКС Эталон 04")).toBeInTheDocument();
|
||||
expect(screen.getByText("+0,3 ₽")).toBeInTheDocument();
|
||||
|
||||
const accounts = within(screen.getByRole("list", {
|
||||
name: /Купон · BOND, Исполнено 14\.08\.2026.*, \+0,3 ₽/,
|
||||
name: /Выплата купонов СФО ВТБ РКС Эталон 04, Исполнено 14\.08\.2026.*, \+0,3 ₽/,
|
||||
}));
|
||||
|
||||
expect(accounts.getByRole("listitem", { name: "Брокерский, +0,1 ₽" }))
|
||||
.toHaveTextContent("Купон");
|
||||
expect(accounts.getByText("+0,1 ₽")).toHaveClass(/positive/);
|
||||
expect(accounts.getByRole("listitem", { name: "ИИС, +0,2 ₽" }))
|
||||
.toHaveTextContent("Купон");
|
||||
expect(accounts.getByText("+0,2 ₽")).toHaveClass(/positive/);
|
||||
expect(accounts.getByRole("listitem", { name: "ИИС, +0,2 ₽" }))
|
||||
.not.toHaveClass("EntryGroup_accountCardRow");
|
||||
expect(accounts.queryByText(/Исполнено/)).not.toBeInTheDocument();
|
||||
expect(accounts.queryByRole("link")).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -83,8 +87,10 @@ describe("OperationGroup", () => {
|
||||
]);
|
||||
|
||||
expect(screen.getByRole("list", {
|
||||
name: /Купон · BOND, Исполнено .*Итог недоступен/,
|
||||
name: /Выплата купонов BOND, Исполнено .*Итог недоступен/,
|
||||
})).toBeInTheDocument();
|
||||
expect(screen.getByText("Итог недоступен")).toBeInTheDocument();
|
||||
expect(screen.getByText("—")).not.toHaveClass(/positive/);
|
||||
});
|
||||
|
||||
it.each(["0", "0.000"])(
|
||||
@@ -114,6 +120,7 @@ describe("OperationGroup", () => {
|
||||
operation("2", { id: "iis", name: "ИИС" }, "-100"),
|
||||
]);
|
||||
expect(screen.getByText("0 ₽")).toBeInTheDocument();
|
||||
expect(screen.getByText("−100 ₽")).toHaveClass(/negative/);
|
||||
});
|
||||
|
||||
it("renders repeated ids inside one group as separate rows", () => {
|
||||
@@ -123,7 +130,7 @@ describe("OperationGroup", () => {
|
||||
]);
|
||||
|
||||
expect(screen.getByText("+30 ₽")).toBeInTheDocument();
|
||||
const accounts = within(screen.getByRole("list", { name: /Купон/ }));
|
||||
const accounts = within(screen.getByRole("list", { name: /Выплата купонов/ }));
|
||||
expect(accounts.getAllByText("Брокерский")).toHaveLength(1);
|
||||
expect(accounts.getAllByText("ИИС")).toHaveLength(1);
|
||||
expect(accounts.getAllByRole("listitem")).toHaveLength(2);
|
||||
|
||||
@@ -9,12 +9,13 @@ import {
|
||||
sumMoney,
|
||||
totalText,
|
||||
} from "@/shared/lib";
|
||||
import { AccountCardRow, EntryGroup, EntryGroupTotal } from "@/shared/ui";
|
||||
import { AccountCardRow, AccountRow, EntryGroup, EntryGroupTotal } from "@/shared/ui";
|
||||
|
||||
import type { BrokerageOperation } from "../api/useBrokerageOperations";
|
||||
|
||||
import {
|
||||
entryLabelKey,
|
||||
isCouponPayment,
|
||||
isZeroDecimal,
|
||||
operationLabelKey,
|
||||
paymentPresentation,
|
||||
@@ -37,6 +38,8 @@ const OperationGroup: FC<OperationGroupProps> = (props) => {
|
||||
? entryLabelKey(first)
|
||||
: operationLabelKey(first.type));
|
||||
|
||||
const isCoupon = isCouponPayment(first);
|
||||
|
||||
const instrument
|
||||
= first.ticker ?? first.instrumentType ?? t("ledger.noInstrument");
|
||||
|
||||
@@ -52,9 +55,21 @@ const OperationGroup: FC<OperationGroupProps> = (props) => {
|
||||
: null;
|
||||
|
||||
const date = formatSnapshotDay(first.occurredAt);
|
||||
const title = `${typeLabel} · ${instrument}`;
|
||||
const description = first.description.trim();
|
||||
let title = `${typeLabel} · ${instrument}`;
|
||||
|
||||
if (isCoupon) {
|
||||
title = description && description.toLocaleLowerCase() !== "купон"
|
||||
? description
|
||||
: t("ledger.couponPayment", { instrument });
|
||||
}
|
||||
|
||||
const totalsText = totalText(totals, true);
|
||||
|
||||
const totalTone = isCoupon && totals?.length && totals.every(total => !isZeroDecimal(total.value) && !total.value.startsWith("-"))
|
||||
? "positive"
|
||||
: "neutral";
|
||||
|
||||
const accessibleName = [
|
||||
title,
|
||||
t("payout.executedAt", { date }),
|
||||
@@ -63,13 +78,14 @@ const OperationGroup: FC<OperationGroupProps> = (props) => {
|
||||
|
||||
return (
|
||||
<EntryGroup
|
||||
flat={isCoupon}
|
||||
header={(
|
||||
<EntryCard
|
||||
imageSrc={instrumentLogoUrl(first.logoName)}
|
||||
initial={(first.ticker?.trim()[0] ?? "?").toUpperCase()}
|
||||
metadata={t("payout.executedAt", { date })}
|
||||
title={title}
|
||||
tone="neutral"
|
||||
tone={totalTone}
|
||||
value={<EntryGroupTotal isSigned totals={totals} />}
|
||||
valueLabel={typeLabel}
|
||||
wrap
|
||||
@@ -80,14 +96,15 @@ const OperationGroup: FC<OperationGroupProps> = (props) => {
|
||||
{props.entries.map(({ key, operation }) => {
|
||||
const payment = paymentPresentation(operation);
|
||||
|
||||
return (
|
||||
<AccountCardRow
|
||||
accountName={operation.account?.name ?? "—"}
|
||||
key={key}
|
||||
value={payment.amount}
|
||||
valueLabel={t(payment.label)}
|
||||
/>
|
||||
);
|
||||
const accountRowProps = {
|
||||
accountName: operation.account?.name ?? "—",
|
||||
value: payment.amount,
|
||||
valueLabel: t(payment.label),
|
||||
};
|
||||
|
||||
return isCoupon
|
||||
? <AccountRow key={key} {...accountRowProps} tone={payment.tone} />
|
||||
: <AccountCardRow key={key} {...accountRowProps} />;
|
||||
})}
|
||||
</EntryGroup>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user