test(tag-input): add regression guard for allowCreation=false + Enter on suggestion

Confirms that Enter on a suggestion item adds the tag even when allowCreation is
false — the activeIndex guard in handleKeydown runs before the allowCreation check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-17 12:14:35 +02:00
parent 6b7829d5c8
commit b01761d800

View File

@@ -255,6 +255,18 @@ describe('TagInput autocomplete', () => {
await waitForFetch();
await expect.element(page.getByRole('listbox')).toBeInTheDocument();
});
it('selects a suggestion via Enter when allowCreation=false', async () => {
mockFetchWithTags(['Familie']);
render(TagInput, { tags: [], allowCreation: false });
const input = page.getByRole('textbox');
await input.fill('Fa');
await waitForFetch();
await userEvent.keyboard('{ArrowDown}'); // index 0 → Familie
await userEvent.keyboard('{Enter}');
await expect.element(page.getByText('Familie')).toBeInTheDocument();
await expect.element(input).toHaveValue('');
});
});
// ─── Tree-aware ordering ──────────────────────────────────────────────────────