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
@@ -1,9 +1,11 @@
import type { CostCategory } from '@trek/shared';
import { describe, expect, it } from 'vitest';
import { buildBudgetItem } from '../../../tests/helpers/factories';
import type { BudgetItem } from '../../types';
import {
buildCostsCsv,
categoryBreakdown,
computeTotals,
currencyOptions,
filterBudgetItems,
@@ -18,7 +20,7 @@ import {
type CostsSettlement,
} from './costsModel';
// FE-BUDGET-COSTSMODEL-001 to FE-BUDGET-COSTSMODEL-014
// FE-BUDGET-COSTSMODEL-001 to FE-BUDGET-COSTSMODEL-015
// The pieces both ledgers share since the desktop panel runs on this model too;
// the rest of the model is pinned in tests/unit/mobile/trip/costsModel.test.ts.
@@ -180,3 +182,25 @@ describe('costsModel: when Costs shows who paid and the shares (#2689, #1714)',
expect(showsSplitting('split', 3, [shared], { flows: [flow], balances: [] }, 1)).toBe(true);
});
});
describe('costsModel: categories left out of the totals (#2819)', () => {
it('FE-BUDGET-COSTSMODEL-015: they leave what was spent, paid and shared, not what is owed or open, and keep their row', () => {
const food = expense({
category: 'food',
total_price: 40,
payers: [payer(1, 40)],
members: [member(1), member(2)],
});
const hotel = expense({ category: 'accommodation', total_price: 100, payers: [], members: [member(1)] });
const flow = { from: { user_id: 2, username: 'u2' }, to: { user_id: 1, username: 'u1' }, amount: 20 };
const without = computeTotals([food, hotel], [flow], ctx, myShareOf, new Set<CostCategory>(['food']));
expect(without).toMatchObject({ totalSpend: 100, myPaid: 0, myShare: 100, owed: 20, outstanding: 100 });
expect(computeTotals([food, hotel], [flow], ctx).totalSpend).toBe(140);
const bars = categoryBreakdown([food, hotel], ctx, new Set<CostCategory>(['accommodation']));
expect(bars.map((b) => [b.key, b.leftOut, b.widthPct])).toEqual([
['accommodation', true, 0],
['food', false, 100],
]);
});
});