From 9ecd36db0f2312c0fa1fe0032fa4cc5201e4da06 Mon Sep 17 00:00:00 2001 From: OpenCode Date: Sat, 24 Oct 2026 15:44:52 +0200 Subject: [PATCH] fix(shopping): omit units for ingredients without quantities --- docs/VERIFICATION.md | 2 +- src/lib/calculator.ts | 2 +- tests/unit/calculator.test.ts | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/VERIFICATION.md b/docs/VERIFICATION.md index 7e59fd3..1a2dc35 100644 --- a/docs/VERIFICATION.md +++ b/docs/VERIFICATION.md @@ -7,7 +7,7 @@ Stand: **24. Oktober 2026**. Die folgenden Prüfungen wurden tatsächlich ausgef | Prüfung | Ergebnis | | ---------------------- | ------------------------------------------------------------------ | | `npm run typecheck` | Erfolgreich, keine TypeScript-Fehler | -| `npm test` | **33/33 Tests bestanden**, 3 Testdateien | +| `npm test` | **34/34 Tests bestanden**, 3 Testdateien | | `npm run build` | Erfolgreicher Next.js-Produktionsbuild, keine Buildwarnungen | | `npm run test:e2e` | **17/17 Tests bestanden**, keine Retries oder übersprungenen Tests | | `npm audit --omit=dev` | **0 gemeldete Schwachstellen** zum Prüfzeitpunkt | diff --git a/src/lib/calculator.ts b/src/lib/calculator.ts index 2d6a3e3..7400a3f 100644 --- a/src/lib/calculator.ts +++ b/src/lib/calculator.ts @@ -73,7 +73,7 @@ export function mergeShopping(existing: ShoppingItem[], ingredients: Ingredient[ for (const i of ingredients) { const amount = scaledAmount(i, factor); const dimension = dimensions[i.unit]; - const unit = dimension ? (dimension[0] === 'mass' ? 'g' : 'ml') : i.unit; + const unit = amount === null ? '' : dimension ? (dimension[0] === 'mass' ? 'g' : 'ml') : i.unit; const normalized = amount === null ? null : convert(amount, i.unit, unit); const same = items.find( (x) => diff --git a/tests/unit/calculator.test.ts b/tests/unit/calculator.test.ts index 1cfbe63..1f4a818 100644 --- a/tests/unit/calculator.test.ts +++ b/tests/unit/calculator.test.ts @@ -93,4 +93,12 @@ describe('Precise scaling from immutable originals', () => { ); expect(b).toHaveLength(3); }); + it('does not display an artificial unit for unquantified shopping ingredients', () => { + const list = mergeShopping( + [], + [{ ...chicken, name: 'Salz', amount: null, note: 'nach Geschmack' }], + '4', + ); + expect(list[0]).toMatchObject({ amount: null, unit: '', note: 'nach Geschmack' }); + }); });