fix(client): lint, theme and size ratchets of the quick-win round, and the tests that followed the features

New warnings fixed at their source (refs written in effects, typed tile
options, no stray imports, smaller functions and components), the payer and
split heads hold their switch instead of letting it overhang, the baselines
lowered where the round removed warnings, and the tests updated to the
solo trip, the shares view and the revisit status.
This commit is contained in:
Maurice
2026-11-13 12:40:17 +01:00
parent 75aeba29ed
commit c2ba78253d
33 changed files with 278 additions and 194 deletions
@@ -99,3 +99,26 @@ export function CostsCategoryBreakdown({
</div>
);
}
/**
* What the totals leave out, beside the total (#2819), and the way back: a click
* counts every category again. The table view has no breakdown to undo it in.
*/
export function LeftOutChip({
label,
onCountAll,
className,
}: {
label: string;
onCountAll: () => void;
className: string;
}) {
const { t } = useTranslation();
return (
<Tooltip label={t('costs.breakdown.countAll')} placement="top">
<button type="button" onClick={onCountAll} className={`${className} text-warning hover:underline`}>
{label}
</button>
</Tooltip>
);
}
@@ -1780,20 +1780,15 @@ describe('CostsPanel — remaining paths', () => {
expect(screen.getAllByText('XBT').length).toBeGreaterThanOrEqual(2)
})
it('FE-W5COSTS-049: a solo trip defaults the payment counterpart to myself', async () => {
const user = userEvent.setup()
it('FE-W5COSTS-049: a solo trip offers no payment, there is nobody to pay (#2689)', async () => {
server.use(
http.get('/api/trips/1/budget', () => HttpResponse.json({ items: [] })),
http.get('/api/trips/1/budget/settlement', () => HttpResponse.json({ balances: [], flows: [], settlements: [] })),
)
render(<CostsPanel tripId={1} tripMembers={[{ id: 1, username: 'alice', avatar_url: null }]} />)
await user.click(await screen.findByRole('button', { name: 'Add payment' }))
await user.type(await screen.findByPlaceholderText('0,00'), '10')
// From and To both resolve to me, so the transfer stays unsavable.
const submits = screen.getAllByRole('button', { name: 'Add payment' })
expect(submits[submits.length - 1]).toBeDisabled()
expect(await screen.findByRole('button', { name: 'Add expense' })).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Add payment' })).not.toBeInTheDocument()
})
it('FE-W5COSTS-050: the expense modal shows uploaded avatars and rejects over-precise input', async () => {
+5 -10
View File
@@ -1,5 +1,5 @@
import { Fragment, useState, useMemo, useCallback, useId, type ReactNode } from 'react'
import { ArrowDown, ArrowUp, BarChart3, Plus, Search, ArrowRight, ArrowLeftRight, Check, RotateCcw, Pencil, Trash2, AlertCircle, Download, StickyNote, ChevronDown, Receipt, ScanLine, Users } from 'lucide-react'
import { ArrowDown, ArrowUp, BarChart3, Plus, Search, ArrowRight, ArrowLeftRight, Check, RotateCcw, Pencil, Trash2, AlertCircle, Download, ChevronDown, Receipt, ScanLine, Users } from 'lucide-react'
import { useTripStore } from '../../store/tripStore'
import { useCanDo } from '../../store/permissionsStore'
import { useToast } from '../shared/Toast'
@@ -31,7 +31,7 @@ import { useExpenseDeleteConfirm } from './useExpenseDeleteConfirm'
import { FlowPills } from './FlowPills'
import { CostsSplitChips } from './CostsSplitChips'
import { CostsModeCard } from './CostsModeCard'
import { CostsCategoryBreakdown } from './CostsCategoryBreakdown'
import { CostsCategoryBreakdown, LeftOutChip } from './CostsCategoryBreakdown'
import { CostsCurrencyPicker } from './CostsCurrencyPicker'
import type { BudgetParticipantFinal, ReceiptLine } from '@trek/shared'
import type { BudgetItem, BudgetItemReceipt } from '../../types'
@@ -243,12 +243,7 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps
<span className={CHIP}>{t('costs.yourShare')}<b className="text-content">{fmt0(totals.myShare)}</b></span>
<span className={CHIP}>{t('costs.youPaid')}<b className="text-content">{fmt0(totals.myPaid)}</b></span>
</> : <span className={CHIP}>{t('costs.expensesCount', { count: countedCount })}</span>}
{/* Also the way back where the breakdown is not on show (the table view). */}
{leftOutLabel && (
<Tooltip label={t('costs.breakdown.countAll')} placement="top">
<button type="button" onClick={countAllCats} className={`${CHIP} text-warning hover:underline`}>{leftOutLabel}</button>
</Tooltip>
)}</>} />
{leftOutLabel && <LeftOutChip label={leftOutLabel} onCountAll={countAllCats} className={CHIP} />}</>} />
)
// Spend by category; a click leaves one out of the totals for a look without it (#2819).
@@ -1063,7 +1058,7 @@ export function ExpenseModal({ tripId, base, people, me, editing, prefill, onClo
const payerSection = (
<DialogSection
label={t('costs.whoPaid')}
className={GROUP}
className={GROUP} tallAction
action={(
<Segmented<'one' | 'several'>
label={t('costs.whoPaid')}
@@ -1137,7 +1132,7 @@ export function ExpenseModal({ tripId, base, people, me, editing, prefill, onClo
const splitSection = (
<DialogSection
label={t('costs.split') || 'Split'}
className={GROUP}
className={GROUP} tallAction
action={(
<Segmented<'equally' | 'custom' | 'ticket'>
label={t('costs.split') || 'Split'}
@@ -105,7 +105,7 @@ export function SettlementModal({
<DialogFooter>
<FooterSpacer />
<DialogButton onClick={onClose}>{t('common.cancel')}</DialogButton>
<DialogButton variant="primary" onClick={save} disabled={!valid || saving}>
<DialogButton variant="primary" onClick={() => void save()} disabled={!valid || saving}>
{editing ? t('common.save') : t('costs.addPayment')}
</DialogButton>
</DialogFooter>
@@ -1,14 +1,16 @@
// FE-BUDGET-COSTSMODE-001 to FE-BUDGET-COSTSMODE-003
import { act, renderHook } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { buildTrip } from '../../../tests/helpers/factories';
import { resetAllStores } from '../../../tests/helpers/store';
import { useTripStore, type TripStoreState } from '../../store/tripStore';
import { useCostsMode } from './useCostsMode';
const toast = vi.hoisted(() => ({ error: vi.fn(), success: vi.fn(), info: vi.fn(), warning: vi.fn() }));
vi.mock('../shared/Toast', () => ({ useToast: () => toast }));
let updateTrip: ReturnType<typeof vi.fn>;
let addToast: ReturnType<typeof vi.fn>;
const trip = (costsMode?: 'split' | 'totals') => buildTrip({ id: 7, ...(costsMode ? { costs_mode: costsMode } : {}) });
@@ -16,12 +18,7 @@ beforeEach(() => {
resetAllStores();
updateTrip = vi.fn(async () => buildTrip({ id: 7 }));
useTripStore.setState({ updateTrip } as unknown as Partial<TripStoreState>);
addToast = vi.fn();
(window as unknown as { __addToast: unknown }).__addToast = addToast;
});
afterEach(() => {
delete (window as unknown as { __addToast?: unknown }).__addToast;
toast.error.mockClear();
});
describe('useCostsMode (#1714)', () => {
@@ -50,7 +47,7 @@ describe('useCostsMode (#1714)', () => {
await result.current.setSplitting(true);
});
expect(updateTrip).toHaveBeenLastCalledWith(7, { costs_mode: 'split' });
expect(addToast.mock.calls.map((c) => c[1])).toContain('error');
expect(toast.error).toHaveBeenCalled();
expect(result.current.saving).toBe(false);
});
});