mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 03:50:30 +00:00
fix(costs): keep convertBooked at five parameters and update the tests to as-typed display rows
The display-currency check is its own helper (inDisplayCurrency), used by the Costs model and the shared trip page. The tests that pinned #2525's reading of a display-currency bill through the trip currency now pin the as-typed reading, which the balances use too; read in the trip currency, such a bill and its repayment may stay a euro cent apart.
This commit is contained in:
@@ -664,10 +664,10 @@ describe('SharedTripPage', () => {
|
||||
await waitFor(() => expect(screen.getAllByText('12,345.67 USD')).toHaveLength(4));
|
||||
});
|
||||
|
||||
it('reads a bill in the display currency through the trip currency too, beside what was entered', async () => {
|
||||
// The owner reads in USD on a CHF trip. The USD bill was booked at 685.26 CHF,
|
||||
// which today is 780.86 USD, the figure Costs and its balances use; the CHF one
|
||||
// converts at today's rate (100 CHF = 113.95 USD).
|
||||
it('reads a bill in the display currency as typed, as Costs does (#2965)', async () => {
|
||||
// The owner reads in USD on a CHF trip. The USD bill reads as the 801.76 USD
|
||||
// typed, as Costs and its balances count it; the CHF one converts at today's
|
||||
// rate (100 CHF = 113.95 USD).
|
||||
server.use(
|
||||
http.get('https://api.frankfurter.dev/v2/rates', () => HttpResponse.json([{ quote: 'CHF', rate: 1 / 1.1395 }])),
|
||||
http.get('/api/shared/:token', ({ params }) => {
|
||||
@@ -692,9 +692,9 @@ describe('SharedTripPage', () => {
|
||||
fireEvent.click(screen.getByRole('button', { name: /costs/i }));
|
||||
|
||||
await waitFor(() => expect(screen.getAllByText('113.95 USD')).toHaveLength(3));
|
||||
expect(screen.getAllByText('780.86 USD')).toHaveLength(3);
|
||||
expect(screen.getByText('894.81 USD')).toBeInTheDocument();
|
||||
expect(screen.getByText('801.76 USD')).toBeInTheDocument();
|
||||
expect(screen.getAllByText('801.76 USD').length).toBeGreaterThan(0);
|
||||
expect(screen.queryByText('780.86 USD')).toBeNull();
|
||||
expect(screen.getByText('915.71 USD')).toBeInTheDocument();
|
||||
expect(screen.getByText('100.00 CHF')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ import { catMeta } from '../../components/Budget/costsCategories'
|
||||
import { fs, NEUTRAL_TINT } from '../../components/shared/DialogShell'
|
||||
import { CountPill } from '../../components/Planner/bookings/bookingParts'
|
||||
import { TripMemberAvatar } from '../../components/Trips/TripMemberAvatar'
|
||||
import { convertBooked, convertedLine } from '../../hooks/useExchangeRates'
|
||||
import { convertBooked, convertedLine, inDisplayCurrency } from '../../hooks/useExchangeRates'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import { avatarSrc } from '../../utils/avatarSrc'
|
||||
import { currencyDecimals } from '../../utils/formatters'
|
||||
@@ -92,7 +92,11 @@ export function SharedCostsView({ items, base, tripCurrency, convert }: CostsPro
|
||||
const { t, locale } = useTranslation()
|
||||
if (items.length === 0) return <EmptySection icon={<Wallet size={22} />} text={t('shared.emptyCosts')} />
|
||||
const amountOf = (i: Expense) => Number.parseFloat(String(i.total_price ?? '')) || 0
|
||||
const valueOf = (i: Expense) => convertBooked(amountOf(i), i.currency, i.exchange_rate, tripCurrency, convert, base)
|
||||
// A bill in the owner's display currency reads as typed, as in Costs (#2965).
|
||||
const valueOf = (i: Expense) =>
|
||||
inDisplayCurrency(i.currency, tripCurrency, base)
|
||||
? amountOf(i)
|
||||
: convertBooked(amountOf(i), i.currency, i.exchange_rate, tripCurrency, convert)
|
||||
// In the reader's own number format with the currency's code: a public page has
|
||||
// no idea where its reader is, and "$" alone does not say which dollar.
|
||||
// Whole cents: a converted amount otherwise printed a third decimal.
|
||||
|
||||
Reference in New Issue
Block a user