mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
fix(costs): amounts follow their currency's decimals and format, and payments count on the local day
Several small things in the costs views, on desktop and phone alike: - The outstanding card no longer says "You're all settled up" while a payment is still open in Settle up. - The custom split shows its suggested shares as a faint placeholder in the currency's own form (30000 for won, not 30000.00), so it no longer reads like an amount already typed. - Amount fields take only the decimals the currency has: won and yen take none, KWD and the other three-decimal currencies three. A switch of currency cuts what was already typed. 1000.555 won was saved as typed, listed as 1,001 and reopened as 1001. - The expense sheet on the phone prints shares and sums with the same formatter as the list, with grouping and the currency's decimals. - A payment recorded with Settle or Settle all is dated on the viewer's own day, and one without a date of its own is grouped by its UTC record time read on the local calendar. In Seoul before 09:00 it landed on the day before. - "1 expenses need a payer" now uses the plural forms of each language. Refs #2604
This commit is contained in:
@@ -21,7 +21,7 @@ vi.mock('./receiptUploads', () => ({
|
||||
),
|
||||
}));
|
||||
|
||||
// FE-BUDGET-EXPFORM-001 to FE-BUDGET-EXPFORM-021
|
||||
// FE-BUDGET-EXPFORM-001 to FE-BUDGET-EXPFORM-023
|
||||
|
||||
const PEOPLE: TripMember[] = [
|
||||
{ id: 1, username: 'alice', avatar_url: null },
|
||||
@@ -268,13 +268,13 @@ describe('useExpenseForm: what it adds up', () => {
|
||||
expect(result.current.valid).toBe(true);
|
||||
});
|
||||
|
||||
it('FE-BUDGET-EXPFORM-008: amounts are refused beyond the currency decimals and ticket prices cannot be negative', () => {
|
||||
it('FE-BUDGET-EXPFORM-008: amounts are cut to the currency decimals, text is refused and ticket prices cannot be negative', () => {
|
||||
const { result } = setup();
|
||||
act(() => {
|
||||
result.current.handleCustomAmountChange(1, '1.234');
|
||||
result.current.handleCustomAmountChange(2, 'abc');
|
||||
});
|
||||
expect(result.current.customAmounts).toEqual({});
|
||||
expect(result.current.customAmounts).toEqual({ 1: '1.23' });
|
||||
act(() => result.current.handleCustomAmountChange(1, '-2'));
|
||||
expect(result.current.customAmounts).toEqual({ 1: '-2' });
|
||||
act(() => result.current.handleCustomAmountChange(1, ''));
|
||||
@@ -566,4 +566,37 @@ describe('useExpenseForm: saving', () => {
|
||||
total_price: 12,
|
||||
});
|
||||
});
|
||||
|
||||
it('FE-BUDGET-EXPFORM-022: amounts take only the decimals the currency has, typed or switched to (#2604)', async () => {
|
||||
const { result } = setup({ prefill: { currency: 'KRW' } });
|
||||
act(() => {
|
||||
result.current.setName('Dinner');
|
||||
result.current.onTotalChange('1000.555');
|
||||
});
|
||||
// The point stays, so a digit typed after it is not taken as one more whole won.
|
||||
expect(result.current.total).toBe('1000.');
|
||||
act(() => result.current.onTotalChange('1000.5'));
|
||||
expect(result.current.total).toBe('1000.');
|
||||
act(() => {
|
||||
result.current.setSplitMode('custom');
|
||||
result.current.handleCustomAmountChange(1, '600,5');
|
||||
result.current.enableMultiPayer();
|
||||
});
|
||||
expect(result.current.customAmounts[1]).toBe('600.');
|
||||
act(() => result.current.onPayerAmountChange(1, '400.75'));
|
||||
expect(result.current.payerAmounts[1]).toBe('400.');
|
||||
|
||||
// Euros keep two places, and a switch to won drops the cents already typed.
|
||||
act(() => result.current.setCurrency('EUR'));
|
||||
act(() => result.current.onTotalChange('12.345'));
|
||||
expect(result.current.total).toBe('12.34');
|
||||
act(() => result.current.setCurrency('KRW'));
|
||||
expect(result.current.total).toBe('12');
|
||||
});
|
||||
|
||||
it('FE-BUDGET-EXPFORM-023: a three-decimal currency keeps its third place', () => {
|
||||
const { result } = setup({ prefill: { currency: 'KWD' } });
|
||||
act(() => result.current.onTotalChange('1.5555'));
|
||||
expect(result.current.total).toBe('1.555');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user