feat(planner): add onremove prop and Entfernen button to MealActionSheet

Button only renders when onremove callback is provided, keeping the
component usable in read-only contexts without the destructive action.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-09 12:25:22 +02:00
parent cb921b3c0f
commit f55d938b32
2 changed files with 30 additions and 3 deletions

View File

@@ -17,9 +17,10 @@
slot: Slot; slot: Slot;
onswap: () => void; onswap: () => void;
oncancel: () => void; oncancel: () => void;
onremove?: () => void;
} }
let { open, slot, onswap, oncancel }: Props = $props(); let { open, slot, onswap, oncancel, onremove }: Props = $props();
const meta = $derived.by(() => { const meta = $derived.by(() => {
const parts: string[] = []; const parts: string[] = [];
@@ -82,6 +83,16 @@
↻ Gericht tauschen ↻ Gericht tauschen
</button> </button>
{#if onremove}
<button
type="button"
style="width:100%;background:var(--color-error, #d9534f);border:1px solid var(--color-error, #d9534f);color:#fff;font-family:var(--font-sans);font-size:13px;font-weight:500;border-radius:var(--radius-lg);padding:12px;text-align:center;cursor:pointer"
onclick={onremove}
>
✕ Gericht entfernen
</button>
{/if}
{#if slot.recipe} {#if slot.recipe}
<a <a
href="/recipes/{slot.recipe.id}/cook" href="/recipes/{slot.recipe.id}/cook"

View File

@@ -13,7 +13,8 @@ const baseProps = {
open: true, open: true,
slot, slot,
onswap: vi.fn(), onswap: vi.fn(),
oncancel: vi.fn() oncancel: vi.fn(),
onremove: vi.fn()
}; };
describe('MealActionSheet', () => { describe('MealActionSheet', () => {
@@ -28,14 +29,29 @@ describe('MealActionSheet', () => {
expect(screen.getByText(/easy/i)).toBeTruthy(); expect(screen.getByText(/easy/i)).toBeTruthy();
}); });
it('renders all 4 action buttons', () => { it('renders all 5 action buttons', () => {
render(MealActionSheet, { props: baseProps }); render(MealActionSheet, { props: baseProps });
expect(screen.getByRole('button', { name: /Gericht tauschen/i })).toBeTruthy(); expect(screen.getByRole('button', { name: /Gericht tauschen/i })).toBeTruthy();
expect(screen.getByRole('link', { name: /Jetzt kochen/i })).toBeTruthy(); expect(screen.getByRole('link', { name: /Jetzt kochen/i })).toBeTruthy();
expect(screen.getByRole('link', { name: /Rezept ansehen/i })).toBeTruthy(); expect(screen.getByRole('link', { name: /Rezept ansehen/i })).toBeTruthy();
expect(screen.getByRole('button', { name: /Entfernen/i })).toBeTruthy();
expect(screen.getByRole('button', { name: /Abbrechen/i })).toBeTruthy(); expect(screen.getByRole('button', { name: /Abbrechen/i })).toBeTruthy();
}); });
it('clicking Entfernen calls onremove', async () => {
const onremove = vi.fn();
const user = userEvent.setup();
render(MealActionSheet, { props: { ...baseProps, onremove } });
await user.click(screen.getByRole('button', { name: /Entfernen/i }));
expect(onremove).toHaveBeenCalledOnce();
});
it('does not render Entfernen button when onremove is not provided', () => {
const { onremove: _, ...propsWithoutRemove } = baseProps;
render(MealActionSheet, { props: propsWithoutRemove });
expect(screen.queryByRole('button', { name: /Entfernen/i })).toBeNull();
});
it('Jetzt kochen links to the cook route', () => { it('Jetzt kochen links to the cook route', () => {
render(MealActionSheet, { props: baseProps }); render(MealActionSheet, { props: baseProps });
const link = screen.getByRole('link', { name: /Jetzt kochen/i }); const link = screen.getByRole('link', { name: /Jetzt kochen/i });