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:
Maurice
2026-11-03 22:43:05 +01:00
parent a37a9c0fa8
commit 4585988dfd
12 changed files with 109 additions and 101 deletions
@@ -681,7 +681,7 @@ describe('MCostSheet', () => {
})))
})
it('FE-MOB-COSTSH-036: editing a booked bill previews the rate the save keeps (#2525)', () => {
it('FE-MOB-COSTSH-036: editing a bill in the display currency has nothing to preview (#2965)', () => {
// A euro trip read in dollars, the bill entered in dollars at 1.17 to the euro.
// Same currency as the list, so the sheet said nothing, while the list showed the
// booked euros at today's rate beside the 801.76 typed here.
@@ -695,12 +695,9 @@ describe('MCostSheet', () => {
})
renderSheet({ base: 'USD', editing })
const hint = screen.getByText(/live rate/).parentElement as HTMLElement
expect(within(hint).getByText('$801.76')).toBeInTheDocument()
expect(within(hint).getByText(/^685,26\s€$/)).toBeInTheDocument()
expect(within(hint).getByText('$791.55')).toBeInTheDocument()
// Each share next to what it counts as, the figure the row's "you lent" is made of.
expect(screen.getByText(/Split 2 ways · \$400\.88 → \$395\.77 each/)).toBeInTheDocument()
// The list reads the dollars typed, so the sheet has no conversion to show.
expect(screen.queryByText(/live rate/)).toBeNull()
expect(screen.getByText(/Split 2 ways · \$400\.88 each/)).toBeInTheDocument()
})
it('FE-MOB-COSTSH-037: a bill booked at today\'s rate has nothing to preview (#2525)', () => {
@@ -764,7 +764,7 @@ describe('MCostsTab', () => {
expect(update).toHaveBeenCalledTimes(1)
})
it('FE-MOB-COSTT-045: a bill whose rate moved shows what was entered and what it was booked at (#2525)', async () => {
it('FE-MOB-COSTT-045: a bill whose rate moved still reads as the dollars typed (#2965)', async () => {
// A euro trip read in dollars, the bill entered in dollars at a frozen 1.17 to the
// euro while today the euro buys 1.1551. It is 685.26 EUR of trip money, $791.55
// today, and that is what settle-up offers too; the row now says where the
@@ -793,17 +793,16 @@ describe('MCostsTab', () => {
await renderTab(planner({ trip: { ...TRIP, currency: 'EUR' } as Trip, budgetItems: [hotel] }))
const card = cardOf('Aparthotel Silver')
expect(within(card).getByText(/^\$801\.76 → 685,26\s€$/)).toBeInTheDocument()
expect(within(card).getByText('$791.55')).toBeInTheDocument()
// Each share is half of the booked euros, the figure the balances net.
expect(within(card).getAllByText('$395.77')).toHaveLength(2)
expect(within(card).queryByText('$400.88')).toBeNull()
expect(up(screen.getByText('costs.totalSpend'), 1).textContent).toContain('$791.55')
expect(screen.getByText('costs.spent:$791.55')).toBeInTheDocument()
expect(within(card).queryByText(/^\$801\.76 → /)).toBeNull()
expect(within(card).getByText('$801.76')).toBeInTheDocument()
// Each share is half of the dollars typed, the figure the balances net (#2965).
expect(within(card).getAllByText('$400.88')).toHaveLength(2)
expect(up(screen.getByText('costs.totalSpend'), 1).textContent).toContain('$801.76')
expect(screen.getByText('costs.spent:$801.76')).toBeInTheDocument()
expect(screen.getAllByText('costs.payment')).toHaveLength(2)
const paid = up(screen.getByText('Ada → costs.you'), 2)
expect(within(paid).getByText(/^\$400\.88 → 342,63\s€$/)).toBeInTheDocument()
expect(within(paid).getByText('$400.88')).toBeInTheDocument()
expect(within(up(screen.getByText('Bob → costs.you'), 2)).getByText('$30.00')).toBeInTheDocument()
expect(screen.queryByText('$34.65')).toBeNull()
})
@@ -325,17 +325,14 @@ describe('costsModel: a bill entered in the display currency (#2525)', () => {
payers: [payer(1, 801.76)], members: [member(1), member(2)],
});
it('FE-MOB-CMOD-038: a bill booked at a rate that has moved since counts as its euros at today\'s rate', () => {
// 685.26 EUR, which the balances net and settle-up offers; the row, the payer's
// figure and the share read the same, or a payback of the row's half reopens the trip.
expect(baseTotal(hotel(), usdCtx)).toBeCloseTo(791.55, 2);
expect(myPaidOf(hotel(), usdCtx)).toBeCloseTo(791.55, 2);
expect(myShareOf(hotel(), usdCtx)).toBeCloseTo(395.77, 2);
// Under it, what was entered and the euros it was booked at, no third step.
const line = lineOf(801.76, hotel(), usdCtx, baseTotal(hotel(), usdCtx))!;
expect(line.entered).toEqual({ amount: 801.76, currency: 'USD' });
expect(line.into.currency).toBe('EUR');
expect(line.into.amount).toBeCloseTo(685.26, 2);
it('FE-MOB-CMOD-038: a bill booked at a rate that has moved since still counts as the dollars typed (#2965)', () => {
// The balances net it as typed too, so the row, the payer's figure and the share
// read the dollars entered, and paying back half of them squares the trip.
expect(baseTotal(hotel(), usdCtx)).toBe(801.76);
expect(myPaidOf(hotel(), usdCtx)).toBe(801.76);
expect(myShareOf(hotel(), usdCtx)).toBe(400.88);
// Nothing to explain under it.
expect(lineOf(801.76, hotel(), usdCtx, baseTotal(hotel(), usdCtx))).toBeNull();
});
it('FE-MOB-CMOD-039: booked at today\'s rate, the bill reads exactly as typed and needs no line', () => {
@@ -380,7 +377,7 @@ describe('costsModel: a bill entered in the display currency (#2525)', () => {
].map((e, i) => ({ ...e, name: e.name || 'Hotel', expense_date: e.expense_date || '2026-07-19', id: i + 1 }));
const inUsd = buildCostsCsv(items, { base: 'USD', ctx: usdCtx, locale: 'en-US', tripTitle: 'Trip', t }).content.split('\r\n');
expect(inUsd[0]).toBe('Date;Name;Category;Amount;Currency;Amount (EUR);Amount (USD);Note');
expect(inUsd[1]).toMatch(/;801\.76;USD;685\.26;791\.55;$/);
expect(inUsd[1]).toMatch(/;801\.76;USD;685\.26;801\.76;$/);
// Never booked, so counted at today's rate, as the server counts it.
expect(inUsd[2]).toMatch(/;115\.51;USD;100\.00;115\.51;$/);
const inEur = buildCostsCsv(items, { base: 'EUR', ctx: { ...usdCtx, displayCurrency: 'EUR' }, locale: 'en-US', tripTitle: 'Trip', t }).content.split('\r\n');