feat(recipes): filter ingredients with quantity <= 0 before API submission

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-10 09:05:19 +02:00
parent dbc78a1883
commit 44b3f06474
7 changed files with 65 additions and 15 deletions

View File

@@ -3,30 +3,44 @@ import { render, screen } from '@testing-library/svelte';
import VarietyWarningCards from './VarietyWarningCards.svelte';
const warnings = [
{ title: 'Chicken zweimal diese Woche', explanation: 'Mo, Mi — erwäge einen Tausch.' },
{ title: 'Tomaten in 3 Gerichten', explanation: 'Mo, Di, Mi — sorge für Abwechslung.' }
{
title: 'Chicken zweimal diese Woche',
items: [
{ dayShort: 'Mo', recipeName: 'Chicken Tikka', slotId: 1 },
{ dayShort: 'Mi', recipeName: 'Chicken Curry', slotId: 3 }
]
},
{
title: 'Tomaten in 3 Gerichten',
items: [
{ dayShort: 'Mo', recipeName: 'Pasta Pomodoro', slotId: 1 },
{ dayShort: 'Di', recipeName: 'Tomatensuppe', slotId: 2 },
{ dayShort: 'Mi', recipeName: 'Pizza Margherita', slotId: 3 }
]
}
];
describe('VarietyWarningCards', () => {
it('renders one card per warning', () => {
render(VarietyWarningCards, { props: { warnings } });
render(VarietyWarningCards, { props: { warnings, weekStart: '2026-04-07' } });
const cards = screen.getAllByTestId('warning-card');
expect(cards.length).toBe(2);
});
it('renders warning titles', () => {
render(VarietyWarningCards, { props: { warnings } });
render(VarietyWarningCards, { props: { warnings, weekStart: '2026-04-07' } });
expect(screen.getByText(/Chicken zweimal/)).toBeTruthy();
expect(screen.getByText(/Tomaten in 3/)).toBeTruthy();
});
it('renders warning explanations', () => {
render(VarietyWarningCards, { props: { warnings } });
expect(screen.getByText(/erwäge einen Tausch/)).toBeTruthy();
render(VarietyWarningCards, { props: { warnings, weekStart: '2026-04-07' } });
expect(screen.getByText('Chicken Tikka')).toBeTruthy();
expect(screen.getByText('Chicken Curry')).toBeTruthy();
});
it('renders nothing when warnings is empty', () => {
render(VarietyWarningCards, { props: { warnings: [] } });
render(VarietyWarningCards, { props: { warnings: [], weekStart: '2026-04-07' } });
expect(screen.queryAllByTestId('warning-card').length).toBe(0);
});
});

View File

@@ -29,7 +29,7 @@ const editProps = {
name: 'Spaghetti Bolognese',
serves: 4,
cookTimeMin: 30,
effort: 'Medium',
effort: 'medium',
heroImageUrl: undefined as string | undefined,
ingredients: [
{ name: 'Spaghetti', quantity: 200, unit: 'g' }