fix(frontend): correct events amount sign for actual-negative rows
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.
This commit is contained in:
parent
3bad694dce
commit
94f8bb876d
@ -362,7 +362,7 @@ describe('BrokerDashboard', () => {
|
|||||||
|
|
||||||
const [amount] = screen.getAllByTestId('dashboard-events-amount')
|
const [amount] = screen.getAllByTestId('dashboard-events-amount')
|
||||||
expect(amount.getAttribute('data-tone')).toBe('negative')
|
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', () => {
|
it('renders events and income amounts with the ₽ symbol and no "RUB" code', () => {
|
||||||
|
|||||||
@ -98,6 +98,19 @@ function eventMoneyTone(event: BrokerEventItem): MoneyTone {
|
|||||||
return moneyTone(eventAmountValue(event), event.source)
|
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({
|
export function BrokerDashboardEventsCard({
|
||||||
accountId,
|
accountId,
|
||||||
data,
|
data,
|
||||||
@ -195,14 +208,7 @@ export function BrokerDashboardEventsCard({
|
|||||||
ticker: event.ticker,
|
ticker: event.ticker,
|
||||||
name: event.name,
|
name: event.name,
|
||||||
})
|
})
|
||||||
const amount = eventAmountValue(event)
|
const formattedAmount = eventAmountDisplay(event)
|
||||||
const formattedAmount =
|
|
||||||
amount === null || amount === undefined
|
|
||||||
? '—'
|
|
||||||
: `${event.source === 'actual' ? '+' : '~'}${formatDashboardCurrency({
|
|
||||||
currency: event.currency ?? 'RUB',
|
|
||||||
value: amount,
|
|
||||||
})}`
|
|
||||||
return (
|
return (
|
||||||
<Box component="tr" key={event.id} data-testid="dashboard-events-row">
|
<Box component="tr" key={event.id} data-testid="dashboard-events-row">
|
||||||
<Box component="td" sx={TD_SX_LEFT}>
|
<Box component="td" sx={TD_SX_LEFT}>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user