test(e2e): fill coverage gaps — +N suffix + focus-trap cycle
Add two tests omitted from the initial sprint 4 run: - us21: SimulationList MITRE column shows "TA0007 +2" for 1 tactic + 2 techniques - us20: MitreMatrixModal Tab wraps to first focusable, Shift+Tab wraps to last Suite: 158 passed, 0 failed (1 expected test.fail for AC-21.6 slug defect). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -176,4 +176,60 @@ test.describe('US-20 — MITRE matrix fits modal', () => {
|
||||
|
||||
await deleteSimulation(redteamToken, sim.id);
|
||||
});
|
||||
|
||||
// NIT code-reviewer + AC-15.5 regression: Tab focus-trap cycle in MitreMatrixModal
|
||||
test('AC-15.5 regression — MitreMatrixModal Tab key cycles focus, Shift+Tab reverses', async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
const sim = await createSimulation(redteamToken, engagementId, 'AC-15.5 focus trap');
|
||||
|
||||
await seedTokenInStorage(context, redteamToken);
|
||||
await page.goto(`/engagements/${engagementId}/simulations/${sim.id}/edit`);
|
||||
|
||||
await page.getByLabel(/open mitre matrix/i).click();
|
||||
const dialog = page.getByRole('dialog');
|
||||
await expect(dialog).toBeVisible({ timeout: 10_000 });
|
||||
|
||||
// Collect all focusable elements in the dialog
|
||||
const focusableCount = await dialog.evaluate((el) => {
|
||||
const focusables = el.querySelectorAll(
|
||||
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
||||
);
|
||||
return focusables.length;
|
||||
});
|
||||
expect(focusableCount).toBeGreaterThan(1);
|
||||
|
||||
// Focus the last focusable element
|
||||
await dialog.evaluate((el) => {
|
||||
const focusables = Array.from(el.querySelectorAll<HTMLElement>(
|
||||
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
||||
));
|
||||
focusables[focusables.length - 1].focus();
|
||||
});
|
||||
|
||||
// Tab from last → should wrap to first (focus trap)
|
||||
await page.keyboard.press('Tab');
|
||||
const activeAfterTab = await dialog.evaluate((el) => {
|
||||
const focusables = Array.from(el.querySelectorAll<HTMLElement>(
|
||||
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
||||
));
|
||||
return focusables.indexOf(document.activeElement as HTMLElement);
|
||||
});
|
||||
// After Tab from last, focus should be on first (index 0)
|
||||
expect(activeAfterTab).toBe(0);
|
||||
|
||||
// Shift+Tab from first → should wrap to last
|
||||
await page.keyboard.press('Shift+Tab');
|
||||
const activeAfterShiftTab = await dialog.evaluate((el) => {
|
||||
const focusables = Array.from(el.querySelectorAll<HTMLElement>(
|
||||
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
||||
));
|
||||
return focusables.indexOf(document.activeElement as HTMLElement);
|
||||
});
|
||||
// After Shift+Tab from first, focus should be on last
|
||||
expect(activeAfterShiftTab).toBe(focusableCount - 1);
|
||||
|
||||
await deleteSimulation(redteamToken, sim.id);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user