feat(planner): J4 swap flow — action sheet + easiest-first suggestions #45
@@ -11,6 +11,7 @@
|
||||
replacingMeta,
|
||||
recipes,
|
||||
currentWeekRecipeIds,
|
||||
excludeRecipeId,
|
||||
isLoading = false,
|
||||
onpick,
|
||||
oncancel
|
||||
@@ -19,11 +20,16 @@
|
||||
replacingMeta?: string;
|
||||
recipes: Recipe[];
|
||||
currentWeekRecipeIds: Set<string>;
|
||||
excludeRecipeId?: string;
|
||||
isLoading?: boolean;
|
||||
onpick: (recipeId: string, recipeName: string) => void;
|
||||
oncancel?: () => void;
|
||||
} = $props();
|
||||
|
||||
let visibleRecipes = $derived(
|
||||
excludeRecipeId ? recipes.filter((r) => r.id !== excludeRecipeId) : recipes
|
||||
);
|
||||
|
||||
function recipeMeta(recipe: Recipe): string {
|
||||
return [
|
||||
recipe.cookTimeMin != null ? `${recipe.cookTimeMin} min` : null,
|
||||
@@ -60,7 +66,7 @@
|
||||
</p>
|
||||
|
||||
<!-- Recipe list -->
|
||||
{#if recipes.length === 0}
|
||||
{#if visibleRecipes.length === 0}
|
||||
<p
|
||||
data-testid="swap-empty-state"
|
||||
style="text-align: center; color: var(--color-text-muted); font-family: var(--font-sans); margin: 0;"
|
||||
@@ -68,7 +74,7 @@
|
||||
Keine Rezepte verfügbar.
|
||||
</p>
|
||||
{:else}
|
||||
{#each recipes as recipe (recipe.id)}
|
||||
{#each visibleRecipes as recipe (recipe.id)}
|
||||
{@const meta = recipeMeta(recipe)}
|
||||
{@const alreadyPlanned = currentWeekRecipeIds.has(recipe.id)}
|
||||
<div
|
||||
|
||||
@@ -74,6 +74,20 @@ describe('SwapSuggestionList', () => {
|
||||
expect(screen.getByTestId('swap-empty-state')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('excludes the recipe being replaced when excludeRecipeId is provided', () => {
|
||||
render(SwapSuggestionList, { props: { ...baseProps, excludeRecipeId: 'r2' } });
|
||||
expect(screen.queryByText('Chicken stir-fry')).toBeNull();
|
||||
expect(screen.getByText('Quick carbonara')).toBeTruthy();
|
||||
expect(screen.getByText('Mushroom risotto')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('shows all recipes when excludeRecipeId is not provided', () => {
|
||||
render(SwapSuggestionList, { props: baseProps });
|
||||
expect(screen.getByText('Quick carbonara')).toBeTruthy();
|
||||
expect(screen.getByText('Chicken stir-fry')).toBeTruthy();
|
||||
expect(screen.getByText('Mushroom risotto')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('disables all Wählen buttons when isLoading is true', () => {
|
||||
render(SwapSuggestionList, { props: { ...baseProps, isLoading: true } });
|
||||
const buttons = screen.getAllByRole('button', { name: /Wählen/i });
|
||||
|
||||
@@ -309,6 +309,7 @@
|
||||
replacingMeta={replacingMeta || undefined}
|
||||
recipes={sortedRecipes}
|
||||
{currentWeekRecipeIds}
|
||||
excludeRecipeId={selectedSlot.recipe?.id}
|
||||
isLoading={swapLoading}
|
||||
onpick={handleSwapPick}
|
||||
oncancel={() => (swapSheetOpen = false)}
|
||||
@@ -549,6 +550,7 @@
|
||||
replacingMeta={replacingMeta || undefined}
|
||||
recipes={sortedRecipes}
|
||||
{currentWeekRecipeIds}
|
||||
excludeRecipeId={pickerSlot.recipe.id}
|
||||
onpick={handleRecipePick}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user