fix(frontend): sprint 3 post-review — real dedup test + Apply 0 guard + Link stopPropagation
- MitreTechniquesField test: rewrite dedup test to actually exercise picker selection path — types query, waits for option, fires pointerDown, asserts no PATCH sent (dedup guard in handleSelect now truly covered) - MitreMatrixModal: Apply button disabled only when totalSelected === 0 AND initialSelection.length === 0 (no-op case); when totalSelected === 0 but initialSelection was non-empty, shows "Clear all" and stays enabled so user can explicitly wipe the list - MitreMatrixModal tests: update disabled test to match "Clear all" label, add "Clear all" enabled + onApply([]) path test - SimulationList: stopPropagation on Name <Link> to prevent double-navigate with row onClick handler Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -110,16 +110,29 @@ describe('MitreTechniquesField', () => {
|
||||
expect(screen.getByRole('combobox')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('dedup: adding an already-present technique does not PATCH', async () => {
|
||||
it('dedup: selecting an already-present technique does not PATCH', async () => {
|
||||
mock.onGet('/mitre/techniques').reply(200, [T1059]);
|
||||
const user = userEvent.setup();
|
||||
renderWithProviders(
|
||||
<MitreTechniquesField value={[T1059]} simulationId={7} engagementId={42} />,
|
||||
);
|
||||
// open picker
|
||||
|
||||
// Open the quick-search picker
|
||||
await user.click(screen.getByRole('button', { name: /Quick search/i }));
|
||||
// Picker shows; but we can't easily select the same item without triggering real debounce in this test.
|
||||
// Instead just verify no PATCH happened yet — dedup is the key invariant.
|
||||
const combobox = screen.getByRole('combobox');
|
||||
expect(combobox).toBeInTheDocument();
|
||||
|
||||
// Type to trigger the search (debounce is 200ms but fake timers not needed — mock responds immediately)
|
||||
await user.type(combobox, 'T1059');
|
||||
|
||||
// Wait for the option to appear in the listbox
|
||||
const option = await screen.findByRole('option', { name: /T1059/i });
|
||||
expect(option).toBeInTheDocument();
|
||||
|
||||
// Select it via pointerDown (mirrors the component's onPointerDown handler)
|
||||
await user.pointer({ target: option, keys: '[MouseLeft>]' });
|
||||
|
||||
// Dedup guard should have fired — no PATCH should have been sent
|
||||
expect(mock.history.patch.length).toBe(0);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user