feat(shopping): clearCheckedItems auf Family-Key umgestellt
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 2m15s

Fix A: checked-Status in clearCheckedItems per JS-Lookup mit unitFamily()
statt SQL-EXISTS gegen raw unit_key berechnen.
Fix B: Orphan-Cleanup activeSet nutzt jetzt unitFamily(raw-unit) als Key,
sodass Checks mit family-key ('weight', 'volume') korrekt gematcht werden.
Neue Integrationstests bestaetigen Round-Trip und Orphan-Bereinigung.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-22 17:08:28 +02:00
parent b2337a5c2a
commit c177c1dc5f
2 changed files with 89 additions and 13 deletions

View File

@@ -305,6 +305,68 @@ describe('clearCart', () => {
});
});
describe('toggleCheck — stabil ueber Unit-Family', () => {
it('haekchen bleibt erhalten wenn Gesamtmenge von kg auf g faellt', () => {
const db = openInMemoryForTest();
const a = insertRecipe(
db,
recipe({
title: 'R1',
servings_default: 4,
ingredients: [{ position: 1, name: 'Kartoffeln', quantity: 500, unit: 'g', note: null, raw_text: '', section_heading: null }]
})
);
const b = insertRecipe(
db,
recipe({
title: 'R2',
servings_default: 4,
ingredients: [{ position: 1, name: 'Kartoffeln', quantity: 1, unit: 'kg', note: null, raw_text: '', section_heading: null }]
})
);
addRecipeToCart(db, a, null);
addRecipeToCart(db, b, null);
// Abhaken der konsolidierten 1,5-kg-Zeile via family-key
const before = listShoppingList(db).rows[0];
toggleCheck(db, before.name_key, before.unit_key, true);
expect(listShoppingList(db).rows[0].checked).toBe(1);
// Ein Rezept rausnehmen → nur noch 500 g, display wechselt auf g
removeRecipeFromCart(db, b);
const after = listShoppingList(db).rows[0];
expect(after.display_unit).toBe('g');
expect(after.total_quantity).toBe(500);
// Haekchen bleibt: unit_key ist weiterhin 'weight'
expect(after.checked).toBe(1);
});
it('clearCheckedItems respektiert family-key beim Orphan-Cleanup', () => {
const db = openInMemoryForTest();
const a = insertRecipe(
db,
recipe({
title: 'R1',
servings_default: 4,
ingredients: [
{ position: 1, name: 'Kartoffeln', quantity: 500, unit: 'g', note: null, raw_text: '', section_heading: null },
{ position: 2, name: 'Salz', quantity: 1, unit: 'Prise', note: null, raw_text: '', section_heading: null }
]
})
);
addRecipeToCart(db, a, null);
const rows = listShoppingList(db).rows;
// Alle abhaken
for (const r of rows) toggleCheck(db, r.name_key, r.unit_key, true);
clearCheckedItems(db);
// Das Rezept sollte raus sein
expect(listShoppingList(db).recipes).toHaveLength(0);
// Check-Tabelle sollte leer sein (keine Orphans)
const remaining = (db.prepare('SELECT COUNT(*) AS c FROM shopping_cart_check').get() as { c: number }).c;
expect(remaining).toBe(0);
});
});
describe('listShoppingList — Konsolidierung ueber Einheiten', () => {
it('fasst 500 g + 1 kg Kartoffeln zu 1,5 kg zusammen', () => {
const db = openInMemoryForTest();