feat(planner): RecipePicker uses scoreDelta/hasConflict, drop currentVarietyScore, add isLoading
- Suggestion interface: { recipe, scoreDelta, hasConflict } (no simulatedScore)
- Badge renders from hasConflict directly — no client-side delta computation needed
- New isLoading prop shows skeleton rows while suggestions fetch is in flight
- currentVarietyScore prop removed from component and both call sites follow in next commit
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,24 +8,25 @@
|
|||||||
|
|
||||||
interface Suggestion {
|
interface Suggestion {
|
||||||
recipe: Recipe;
|
recipe: Recipe;
|
||||||
simulatedScore: number;
|
scoreDelta: number;
|
||||||
|
hasConflict: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
planId,
|
planId,
|
||||||
date,
|
date,
|
||||||
dateLabel,
|
dateLabel,
|
||||||
currentVarietyScore = 0,
|
|
||||||
suggestions = [],
|
suggestions = [],
|
||||||
allRecipes = [],
|
allRecipes = [],
|
||||||
|
isLoading = false,
|
||||||
onpick
|
onpick
|
||||||
}: {
|
}: {
|
||||||
planId: string;
|
planId: string;
|
||||||
date: string;
|
date: string;
|
||||||
dateLabel: string;
|
dateLabel: string;
|
||||||
currentVarietyScore?: number;
|
|
||||||
suggestions: Suggestion[];
|
suggestions: Suggestion[];
|
||||||
allRecipes: Recipe[];
|
allRecipes: Recipe[];
|
||||||
|
isLoading?: boolean;
|
||||||
onpick: (recipeId: string, recipeName: string) => void;
|
onpick: (recipeId: string, recipeName: string) => void;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
@@ -71,7 +72,27 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Empfohlen section -->
|
<!-- Empfohlen section -->
|
||||||
{#if suggestions.length > 0}
|
{#if isLoading}
|
||||||
|
<div data-testid="suggestions-loading">
|
||||||
|
{#each [1, 2, 3] as i (i)}
|
||||||
|
<div
|
||||||
|
style="padding: 7px 12px; border-bottom: 1px solid var(--color-subtle); display: flex; align-items: center; gap: 8px;"
|
||||||
|
>
|
||||||
|
<div style="flex: 1; min-width: 0;">
|
||||||
|
<div
|
||||||
|
style="height: 12px; width: 60%; border-radius: 3px; background: var(--color-subtle); animation: pulse 1.5s ease-in-out infinite;"
|
||||||
|
></div>
|
||||||
|
<div
|
||||||
|
style="height: 9px; width: 35%; border-radius: 3px; background: var(--color-subtle); margin-top: 4px; animation: pulse 1.5s ease-in-out infinite;"
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style="height: 26px; width: 56px; border-radius: var(--radius-md); background: var(--color-subtle); animation: pulse 1.5s ease-in-out infinite;"
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{:else if suggestions.length > 0}
|
||||||
<div
|
<div
|
||||||
style="font-size: 11px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--color-text-muted); padding: 5px 12px 3px; background: var(--color-subtle);"
|
style="font-size: 11px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--color-text-muted); padding: 5px 12px 3px; background: var(--color-subtle);"
|
||||||
>
|
>
|
||||||
@@ -79,7 +100,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#each suggestions as suggestion (suggestion.recipe.id)}
|
{#each suggestions as suggestion (suggestion.recipe.id)}
|
||||||
{@const delta = suggestion.simulatedScore - currentVarietyScore}
|
|
||||||
{@const meta = recipeMetadata(suggestion.recipe)}
|
{@const meta = recipeMetadata(suggestion.recipe)}
|
||||||
<div
|
<div
|
||||||
style="padding: 7px 12px; border-bottom: 1px solid var(--color-subtle); display: flex; align-items: center; gap: 8px;"
|
style="padding: 7px 12px; border-bottom: 1px solid var(--color-subtle); display: flex; align-items: center; gap: 8px;"
|
||||||
@@ -95,13 +115,13 @@
|
|||||||
{meta}
|
{meta}
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
{#if delta > 0}
|
{#if !suggestion.hasConflict}
|
||||||
<span
|
<span
|
||||||
data-testid="badge-{suggestion.recipe.id}"
|
data-testid="badge-{suggestion.recipe.id}"
|
||||||
data-type="good"
|
data-type="good"
|
||||||
style="display: inline-block; margin-top: 3px; font-size: 8px; font-weight: 500; padding: 1px 5px; border-radius: 3px; background: var(--green-tint); color: var(--green-dark);"
|
style="display: inline-block; margin-top: 3px; font-size: 8px; font-weight: 500; padding: 1px 5px; border-radius: 3px; background: var(--green-tint); color: var(--green-dark);"
|
||||||
>
|
>
|
||||||
↑ +{delta.toFixed(0)} Punkte
|
↑ +{suggestion.scoreDelta.toFixed(0)} Punkte
|
||||||
</span>
|
</span>
|
||||||
{:else}
|
{:else}
|
||||||
<span
|
<span
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import userEvent from '@testing-library/user-event';
|
|||||||
import RecipePicker from './RecipePicker.svelte';
|
import RecipePicker from './RecipePicker.svelte';
|
||||||
|
|
||||||
const suggestions = [
|
const suggestions = [
|
||||||
{ recipe: { id: 's1', name: 'Lachsfilet', effort: 'easy', cookTimeMin: 25 }, simulatedScore: 9.5 },
|
{ recipe: { id: 's1', name: 'Lachsfilet', effort: 'easy', cookTimeMin: 25 }, scoreDelta: 1.5, hasConflict: false },
|
||||||
{ recipe: { id: 's2', name: 'Hähnchen-Curry', effort: 'easy', cookTimeMin: 35 }, simulatedScore: 6.0 }
|
{ recipe: { id: 's2', name: 'Hähnchen-Curry', effort: 'easy', cookTimeMin: 35 }, scoreDelta: -1.5, hasConflict: true }
|
||||||
];
|
];
|
||||||
|
|
||||||
const allRecipes = [
|
const allRecipes = [
|
||||||
@@ -18,7 +18,6 @@ const baseProps = {
|
|||||||
planId: 'plan-1',
|
planId: 'plan-1',
|
||||||
date: '2026-04-05',
|
date: '2026-04-05',
|
||||||
dateLabel: 'Samstag, 5. April',
|
dateLabel: 'Samstag, 5. April',
|
||||||
currentVarietyScore: 7.5,
|
|
||||||
suggestions,
|
suggestions,
|
||||||
allRecipes,
|
allRecipes,
|
||||||
onpick: vi.fn()
|
onpick: vi.fn()
|
||||||
@@ -41,16 +40,16 @@ describe('RecipePicker', () => {
|
|||||||
expect(screen.getByText('Hähnchen-Curry')).toBeTruthy();
|
expect(screen.getByText('Hähnchen-Curry')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows green badge for suggestions with positive delta', () => {
|
it('shows green badge when hasConflict is false', () => {
|
||||||
render(RecipePicker, { props: baseProps });
|
render(RecipePicker, { props: baseProps });
|
||||||
// Lachsfilet: simulatedScore 9.5 - currentVarietyScore 7.5 = +2 → green badge
|
// Lachsfilet: hasConflict = false → green badge
|
||||||
const badge = screen.getByTestId('badge-s1');
|
const badge = screen.getByTestId('badge-s1');
|
||||||
expect(badge.getAttribute('data-type')).toBe('good');
|
expect(badge.getAttribute('data-type')).toBe('good');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows yellow badge for suggestions with zero or negative delta', () => {
|
it('shows yellow badge when hasConflict is true', () => {
|
||||||
render(RecipePicker, { props: baseProps });
|
render(RecipePicker, { props: baseProps });
|
||||||
// Hähnchen-Curry: 6.0 - 7.5 = -1.5 → yellow badge
|
// Hähnchen-Curry: hasConflict = true → yellow badge
|
||||||
const badge = screen.getByTestId('badge-s2');
|
const badge = screen.getByTestId('badge-s2');
|
||||||
expect(badge.getAttribute('data-type')).toBe('warning');
|
expect(badge.getAttribute('data-type')).toBe('warning');
|
||||||
});
|
});
|
||||||
@@ -98,4 +97,16 @@ describe('RecipePicker', () => {
|
|||||||
await userEvent.type(input, 'xyznotfound');
|
await userEvent.type(input, 'xyznotfound');
|
||||||
expect(screen.getByText(/Keine Treffer/i)).toBeTruthy();
|
expect(screen.getByText(/Keine Treffer/i)).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('shows loading skeleton instead of Empfohlen section when isLoading is true', () => {
|
||||||
|
render(RecipePicker, { props: { ...baseProps, isLoading: true } });
|
||||||
|
expect(screen.getByTestId('suggestions-loading')).toBeTruthy();
|
||||||
|
expect(screen.queryByText(/Empfohlen/i)).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('hides loading skeleton when isLoading is false and suggestions are present', () => {
|
||||||
|
render(RecipePicker, { props: { ...baseProps, isLoading: false } });
|
||||||
|
expect(screen.queryByTestId('suggestions-loading')).toBeNull();
|
||||||
|
expect(screen.getByText(/Empfohlen/i)).toBeTruthy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user