feat(costs): leave a category out of the totals for a look (#2819)

Seeing what a trip cost without, say, food meant adding it up by hand. A
click (or tap) on a category in the breakdown now leaves it out of the
total, your share and what you paid, dimmed in place with a line naming it
and Count all to undo. View only: nothing is saved, and what is owed, open
or settled stays whole. The desktop breakdown moves into its own component.
This commit is contained in:
Maurice
2026-11-13 10:04:57 +01:00
parent a70eea5bf2
commit 72fc61a016
40 changed files with 480 additions and 63 deletions
@@ -18,7 +18,7 @@ import { server } from '../../../helpers/msw/server'
import { fireEvent, render, screen, waitFor, within } from '../../../helpers/render'
import { setSizeClass } from '../../../helpers/sizeClass'
// FE-MOB-COSTT-001 to FE-MOB-COSTT-057
// FE-MOB-COSTT-001 to FE-MOB-COSTT-058
// The add/edit expense sheet is the shared desktop-sized form; the panel only
// owns when it opens and what happens on save, so it is stubbed here.
@@ -997,4 +997,18 @@ describe('MCostsTab', () => {
fireEvent.click(toggle)
await waitFor(() => expect(updateTrip).toHaveBeenCalledWith(7, { costs_mode: 'split' }))
})
it('FE-MOB-COSTT-058: a tapped category leaves the total and is named, and Count all brings it back (#2819)', async () => {
await renderTab()
const total = () => up(screen.getByText('costs.totalSpend'), 1)
const before = total().textContent
expect(screen.queryByText('costs.breakdown.countAll')).not.toBeInTheDocument()
fireEvent.click(screen.getAllByRole('button', { name: /^costs\.breakdown\.leaveOut:/ })[0])
expect(total().textContent).not.toBe(before)
expect(within(total()).getByText(/^costs\.breakdown\.leftOut:/)).toBeInTheDocument()
expect(screen.getByRole('button', { name: /^costs\.breakdown\.countIn:/ })).toHaveClass('opacity-45')
fireEvent.click(screen.getByText('costs.breakdown.countAll'))
expect(total().textContent).toBe(before)
expect(screen.queryByRole('button', { name: /^costs\.breakdown\.countIn:/ })).not.toBeInTheDocument()
})
})
@@ -438,7 +438,7 @@ describe('costsModel — breakdown and presentation', () => {
const bars = categoryBreakdown(items, ctx);
expect(bars.map(b => b.key)).toEqual(['accommodation', 'food']);
expect(bars[0]).toEqual({ key: 'accommodation', amount: 300, widthPct: 100 });
expect(bars[0]).toEqual({ key: 'accommodation', amount: 300, widthPct: 100, leftOut: false });
expect(bars[1].amount).toBe(200);
expect(bars[1].widthPct).toBeCloseTo(66.667, 3);
});
@@ -460,14 +460,14 @@ describe('costsModel — breakdown and presentation', () => {
// category keeps its own row at the bottom, without a bar — a negative CSS
// width would be dropped and paint a full one.
expect(bars).toEqual([
{ key: 'food', amount: 60, widthPct: 100 },
{ key: 'activities', amount: -20, widthPct: 0 },
{ key: 'food', amount: 60, widthPct: 100, leftOut: false },
{ key: 'activities', amount: -20, widthPct: 0, leftOut: false },
]);
});
it('FE-MOB-CMOD-032: an all-negative breakdown renders rows but no bars (#2176)', () => {
const bars = categoryBreakdown([expense({ category: 'food', total_price: -20 })], ctx);
expect(bars).toEqual([{ key: 'food', amount: -20, widthPct: 0 }]);
expect(bars).toEqual([{ key: 'food', amount: -20, widthPct: 0, leftOut: false }]);
});
it('FE-MOB-CMOD-021: tint turns a hex colour into rgba, with or without the leading hash', () => {