From 94f8bb876df8d33b43334950ed6fb6dfd785dbce Mon Sep 17 00:00:00 2001 From: Sergey Krylov Date: Sat, 27 Jun 2026 13:35:48 +0300 Subject: [PATCH] fix(frontend): correct events amount sign for actual-negative rows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Spec review of Task 9 caught that the events amount prefix used '+' unconditionally for any actual source, producing '+-87,00 ₽' on negative actual amounts. Mirror the income card sign handling: '+' for positive, Unicode '−' (U+2212) for negative, '~' for forecast (regardless of sign). Extract a small eventAmountDisplay helper and tighten the corresponding test assertion to require exact equality instead of substring match, so this regression class is caught next time. --- .../ui/BrokerDashboard.test.tsx | 2 +- .../ui/BrokerDashboardEventsCard.tsx | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboard.test.tsx b/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboard.test.tsx index b60b003..37d5cf0 100644 --- a/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboard.test.tsx +++ b/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboard.test.tsx @@ -362,7 +362,7 @@ describe('BrokerDashboard', () => { const [amount] = screen.getAllByTestId('dashboard-events-amount') expect(amount.getAttribute('data-tone')).toBe('negative') - expect(amount.textContent).toContain('-87,00') + expect(amount.textContent).toBe('−87,00 ₽') }) it('renders events and income amounts with the ₽ symbol and no "RUB" code', () => { diff --git a/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboardEventsCard.tsx b/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboardEventsCard.tsx index 13a3e71..d859667 100644 --- a/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboardEventsCard.tsx +++ b/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboardEventsCard.tsx @@ -98,6 +98,19 @@ function eventMoneyTone(event: BrokerEventItem): MoneyTone { return moneyTone(eventAmountValue(event), event.source) } +function eventAmountDisplay(event: BrokerEventItem): string { + const amount = eventAmountValue(event) + if (amount === null || amount === undefined) return '—' + const abs = formatDashboardCurrency({ + currency: event.currency ?? 'RUB', + value: Math.abs(amount), + }) + if (event.source === 'forecast') return `~${abs}` + if (amount > 0) return `+${abs}` + if (amount < 0) return `−${abs}` + return abs +} + export function BrokerDashboardEventsCard({ accountId, data, @@ -195,14 +208,7 @@ export function BrokerDashboardEventsCard({ ticker: event.ticker, name: event.name, }) - const amount = eventAmountValue(event) - const formattedAmount = - amount === null || amount === undefined - ? '—' - : `${event.source === 'actual' ? '+' : '~'}${formatDashboardCurrency({ - currency: event.currency ?? 'RUB', - value: amount, - })}` + const formattedAmount = eventAmountDisplay(event) return (