feat(shopping): listShoppingList konsolidiert g/kg + ml/l
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 2m14s
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 2m14s
TS-seitige Family-Gruppierung via unitFamily() + consolidate() ersetzt
die reine SQL-Aggregation. unit_key im ShoppingListRow traegt jetzt den
Family-Key ('weight', 'volume' oder raw-unit). toggleCheck-Aufrufe und
unit_key-Assertions in den Tests entsprechend angepasst.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -123,7 +123,7 @@ describe('listShoppingList aggregation', () => {
|
||||
const rows = listShoppingList(db).rows;
|
||||
expect(rows).toHaveLength(1);
|
||||
expect(rows[0].name_key).toBe('mehl');
|
||||
expect(rows[0].unit_key).toBe('g');
|
||||
expect(rows[0].unit_key).toBe('weight');
|
||||
expect(rows[0].total_quantity).toBe(400);
|
||||
expect(rows[0].from_recipes).toContain('Carbonara');
|
||||
expect(rows[0].from_recipes).toContain('Lasagne');
|
||||
@@ -201,15 +201,15 @@ describe('toggleCheck', () => {
|
||||
|
||||
it('marks a row as checked', () => {
|
||||
const { db } = setupOneRowCart();
|
||||
toggleCheck(db, 'mehl', 'g', true);
|
||||
toggleCheck(db, 'mehl', 'weight', true);
|
||||
const rows = listShoppingList(db).rows;
|
||||
expect(rows[0].checked).toBe(1);
|
||||
});
|
||||
|
||||
it('unchecks a row when passed false', () => {
|
||||
const { db } = setupOneRowCart();
|
||||
toggleCheck(db, 'mehl', 'g', true);
|
||||
toggleCheck(db, 'mehl', 'g', false);
|
||||
toggleCheck(db, 'mehl', 'weight', true);
|
||||
toggleCheck(db, 'mehl', 'weight', false);
|
||||
expect(listShoppingList(db).rows[0].checked).toBe(0);
|
||||
});
|
||||
|
||||
@@ -225,7 +225,7 @@ describe('toggleCheck', () => {
|
||||
}));
|
||||
addRecipeToCart(db, a, null);
|
||||
addRecipeToCart(db, b, null);
|
||||
toggleCheck(db, 'mehl', 'g', true);
|
||||
toggleCheck(db, 'mehl', 'weight', true);
|
||||
// Rezept A weg, Mehl kommt noch aus B — check bleibt, mit neuer Menge
|
||||
removeRecipeFromCart(db, a);
|
||||
const rows = listShoppingList(db).rows;
|
||||
@@ -304,3 +304,116 @@ describe('clearCart', () => {
|
||||
expect(anyCheck).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('listShoppingList — Konsolidierung ueber Einheiten', () => {
|
||||
it('fasst 500 g + 1 kg Kartoffeln zu 1,5 kg zusammen', () => {
|
||||
const db = openInMemoryForTest();
|
||||
const a = insertRecipe(
|
||||
db,
|
||||
recipe({
|
||||
title: 'Kartoffelsuppe',
|
||||
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: 'Kartoffelpuffer',
|
||||
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);
|
||||
|
||||
const snap = listShoppingList(db);
|
||||
const kartoffeln = snap.rows.filter((r) => r.display_name.toLowerCase() === 'kartoffeln');
|
||||
expect(kartoffeln).toHaveLength(1);
|
||||
expect(kartoffeln[0].total_quantity).toBe(1.5);
|
||||
expect(kartoffeln[0].display_unit).toBe('kg');
|
||||
});
|
||||
|
||||
it('kombiniert ml + l korrekt (400 ml + 0,5 l → 900 ml)', () => {
|
||||
const db = openInMemoryForTest();
|
||||
const a = insertRecipe(
|
||||
db,
|
||||
recipe({
|
||||
title: 'R1',
|
||||
servings_default: 4,
|
||||
ingredients: [{ position: 1, name: 'Milch', quantity: 400, unit: 'ml', note: null, raw_text: '', section_heading: null }]
|
||||
})
|
||||
);
|
||||
const b = insertRecipe(
|
||||
db,
|
||||
recipe({
|
||||
title: 'R2',
|
||||
servings_default: 4,
|
||||
ingredients: [{ position: 1, name: 'Milch', quantity: 0.5, unit: 'l', note: null, raw_text: '', section_heading: null }]
|
||||
})
|
||||
);
|
||||
addRecipeToCart(db, a, null);
|
||||
addRecipeToCart(db, b, null);
|
||||
|
||||
const milch = listShoppingList(db).rows.filter((r) => r.display_name.toLowerCase() === 'milch');
|
||||
expect(milch).toHaveLength(1);
|
||||
expect(milch[0].total_quantity).toBe(900);
|
||||
expect(milch[0].display_unit).toBe('ml');
|
||||
});
|
||||
|
||||
it('laesst inkompatible Families getrennt (5 Stueck Eier + 500 g Eier = 2 Zeilen)', () => {
|
||||
const db = openInMemoryForTest();
|
||||
const a = insertRecipe(
|
||||
db,
|
||||
recipe({
|
||||
title: 'R1',
|
||||
servings_default: 4,
|
||||
ingredients: [{ position: 1, name: 'Eier', quantity: 5, unit: 'Stück', note: null, raw_text: '', section_heading: null }]
|
||||
})
|
||||
);
|
||||
const b = insertRecipe(
|
||||
db,
|
||||
recipe({
|
||||
title: 'R2',
|
||||
servings_default: 4,
|
||||
ingredients: [{ position: 1, name: 'Eier', quantity: 500, unit: 'g', note: null, raw_text: '', section_heading: null }]
|
||||
})
|
||||
);
|
||||
addRecipeToCart(db, a, null);
|
||||
addRecipeToCart(db, b, null);
|
||||
|
||||
const eier = listShoppingList(db).rows.filter((r) => r.display_name.toLowerCase() === 'eier');
|
||||
expect(eier).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('summiert gleiche Unit-Family ohne Konversion (2 Bund + 1 Bund → 3 Bund)', () => {
|
||||
const db = openInMemoryForTest();
|
||||
const a = insertRecipe(
|
||||
db,
|
||||
recipe({
|
||||
title: 'R1',
|
||||
servings_default: 4,
|
||||
ingredients: [{ position: 1, name: 'Petersilie', quantity: 2, unit: 'Bund', note: null, raw_text: '', section_heading: null }]
|
||||
})
|
||||
);
|
||||
const b = insertRecipe(
|
||||
db,
|
||||
recipe({
|
||||
title: 'R2',
|
||||
servings_default: 4,
|
||||
ingredients: [{ position: 1, name: 'Petersilie', quantity: 1, unit: 'Bund', note: null, raw_text: '', section_heading: null }]
|
||||
})
|
||||
);
|
||||
addRecipeToCart(db, a, null);
|
||||
addRecipeToCart(db, b, null);
|
||||
|
||||
const petersilie = listShoppingList(db).rows.filter((r) => r.display_name.toLowerCase() === 'petersilie');
|
||||
expect(petersilie).toHaveLength(1);
|
||||
expect(petersilie[0].total_quantity).toBe(3);
|
||||
expect(petersilie[0].display_unit?.toLowerCase()).toBe('bund');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user