fix(frontend): sprint 5 post-code-review — dropdown close-on-outside + empty-state dropdown

- useEffect pointerdown + Escape listeners when dropdown open (NIT 1)
- empty state now renders NewSimulationDropdown instead of plain Link (NIT 2)
- 3 new Vitest: close-on-outside, close-on-Escape, empty-state has dropdown

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Knacky
2026-05-28 07:02:34 +02:00
parent 20783118ee
commit 33a0ca30bb
2 changed files with 60 additions and 10 deletions

View File

@@ -142,6 +142,44 @@ describe('SimulationList — admin/redteam', () => {
});
});
it('closes dropdown on click outside', async () => {
mock.onGet('/engagements/42/simulations').reply(200, SIMULATIONS);
const user = userEvent.setup();
renderWithProviders(<SimulationList engagementId={42} />);
await waitFor(() => {
expect(screen.getByText('Lateral movement test')).toBeInTheDocument();
});
await user.click(screen.getByTestId('new-simulation-dropdown-toggle'));
expect(screen.getByTestId('from-template-btn')).toBeInTheDocument();
// Click outside the dropdown
await user.click(document.body);
expect(screen.queryByTestId('from-template-btn')).toBeNull();
});
it('closes dropdown on Escape key', async () => {
mock.onGet('/engagements/42/simulations').reply(200, SIMULATIONS);
const user = userEvent.setup();
renderWithProviders(<SimulationList engagementId={42} />);
await waitFor(() => {
expect(screen.getByText('Lateral movement test')).toBeInTheDocument();
});
await user.click(screen.getByTestId('new-simulation-dropdown-toggle'));
expect(screen.getByTestId('from-template-btn')).toBeInTheDocument();
await user.keyboard('{Escape}');
expect(screen.queryByTestId('from-template-btn')).toBeNull();
});
it('shows dropdown in empty state (not a plain link)', async () => {
mock.onGet('/engagements/42/simulations').reply(200, []);
renderWithProviders(<SimulationList engagementId={42} />);
await waitFor(() => {
expect(screen.getByTestId('empty-state')).toBeInTheDocument();
});
// Must have the split-button dropdown, not a plain link
expect(screen.getByTestId('new-simulation-btn')).toBeInTheDocument();
expect(screen.getByTestId('new-simulation-dropdown-toggle')).toBeInTheDocument();
});
it('clicking a row uses SPA navigation and does not trigger window.location change', async () => {
mock.onGet('/engagements/42/simulations').reply(200, SIMULATIONS);
const originalHref = window.location.href;