fix(secrets-ui): align fields, confirmation lifecycle and list recovery
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
async (page) => {
|
||||
const context = await page.context().browser().newContext({ viewport: { width: 1440, height: 1000 } });
|
||||
const results = [];
|
||||
try {
|
||||
for (const origin of ['http://127.0.0.1:53202', 'http://127.0.0.1:53233']) {
|
||||
const p = await context.newPage(); p.setDefaultTimeout(7000);
|
||||
const row = { origin, checks: [], failures: [], errors: [] };
|
||||
p.on('pageerror', e => row.errors.push(e.message));
|
||||
const check = (name, pass) => { row.checks.push({ name, pass: !!pass }); if (!pass) row.failures.push(name); };
|
||||
const faults = async data => { const r = await p.request.post(origin + '/fixture/faults', { data }); if (r.status() !== 204) throw Error('Fixture fault response ' + r.status()); };
|
||||
const counts = async () => (await p.request.get(origin + '/fixture/counts')).json();
|
||||
const focused = async id => {
|
||||
try { await p.waitForFunction(id => document.activeElement?.id === id, id, { timeout: 2000 }); return true; } catch { return false; }
|
||||
};
|
||||
try {
|
||||
await p.goto(origin + '/admin/secrets');
|
||||
await p.locator('[data-fixture-ready=true]').waitFor();
|
||||
const initialCounts = await counts();
|
||||
await p.getByTestId('add-secret').click();
|
||||
const name = p.getByTestId('secret-name'); await name.waitFor();
|
||||
await p.locator('label').filter({ hasText: /^Name$/ }).click();
|
||||
check('Label activates Name', await name.evaluate(n => n === document.activeElement));
|
||||
await name.fill('../invalid'); await p.getByTestId('secret-value').fill('synthetic input');
|
||||
await p.getByTestId('editor-submit').click();
|
||||
await name.locator('xpath=..').locator('.field-error').waitFor();
|
||||
check('Invalid field receives focus', await focused(await name.getAttribute('id')));
|
||||
check('Invalid name has existing hint/error associations', await name.evaluate(n => n.getAttribute('aria-invalid') === 'true' && n.getAttribute('aria-describedby').split(' ').every(id => document.getElementById(id))));
|
||||
row.errorInk = await name.locator('xpath=..').locator('.field-error').evaluate(n => getComputedStyle(n).color);
|
||||
await p.getByTestId('editor-cancel').click(); await name.waitFor({ state: 'hidden' });
|
||||
const trigger = p.locator('.delete-secret').first(); const triggerId = await trigger.getAttribute('id'); const triggerName = await trigger.getAttribute('data-secret-name');
|
||||
await trigger.click(); await p.locator('dialog:modal').waitFor();
|
||||
check('Initial Cancel focus', await focused(await p.getByTestId('cancel-delete').getAttribute('id')));
|
||||
await p.keyboard.press('Tab'); check('Forward Tab wraps', await p.getByTestId('confirm-delete').evaluate(n => n === document.activeElement));
|
||||
await p.keyboard.press('Shift+Tab'); check('Reverse Tab wraps', await p.getByTestId('cancel-delete').evaluate(n => n === document.activeElement));
|
||||
await p.getByTestId('add-secret').evaluate(n => n.focus());
|
||||
check('Native background isolation', await p.locator('dialog').evaluate(n => n.contains(document.activeElement)));
|
||||
await p.keyboard.press('Escape'); await p.locator('dialog').waitFor({ state: 'hidden' });
|
||||
check('Cancel restores trigger focus', await focused(triggerId));
|
||||
check('Cancel does not delete', (await counts()).deletes === initialCounts.deletes);
|
||||
await faults({ write: true }); await p.locator('.delete-secret').first().click();
|
||||
await p.getByTestId('confirm-delete').click(); await p.getByTestId('delete-error').waitFor();
|
||||
check('Failed deletion retains exact-target dialog', await p.locator('dialog:modal').count() === 1 && (await p.locator('dialog h3').innerText()).includes(triggerName));
|
||||
await p.keyboard.press('Escape'); await p.locator('dialog').waitFor({ state: 'hidden' });
|
||||
await faults({ delayMs: 800 });
|
||||
const nextId = await p.locator('.delete-secret').nth(1).getAttribute('id');
|
||||
await p.locator('.delete-secret').first().click(); await p.getByTestId('confirm-delete').click();
|
||||
await p.waitForFunction(() => document.querySelector('dialog')?.getAttribute('aria-busy') === 'true');
|
||||
await p.keyboard.press('Escape');
|
||||
check('Busy Escape stays open', await p.locator('dialog:modal').count() === 1);
|
||||
check('Busy Cancel disabled', await p.getByTestId('cancel-delete').isDisabled());
|
||||
check('Busy parent target switching disabled', await p.getByTestId('add-secret').isDisabled());
|
||||
await p.locator('dialog').waitFor({ state: 'hidden' });
|
||||
check('Removed trigger focuses adjacent row', await focused(nextId));
|
||||
check('Scroll lock restored', await p.evaluate(() => document.body.style.overflow !== 'hidden'));
|
||||
await faults({}); await p.locator('.rotate-secret').first().click();
|
||||
await p.getByTestId('secret-value').fill('synthetic replacement'); await faults({ list: true });
|
||||
await p.getByTestId('editor-submit').click(); await p.getByTestId('list-error').waitFor();
|
||||
check('Committed save is distinct from refresh failure', (await p.getByTestId('list-error').innerText()).includes('Change saved; list refresh failed'));
|
||||
const before = await counts(); await faults({}); await p.getByTestId('list-retry').click();
|
||||
await p.getByTestId('list-error').waitFor({ state: 'hidden' }); const after = await counts();
|
||||
check('Retry reads metadata only', before.upserts === initialCounts.upserts + 1 && after.upserts === before.upserts && after.deletes === initialCounts.deletes + 1 && after.lists > before.lists);
|
||||
await p.goto(origin + '/admin/secrets?role=manage'); await p.locator('[data-fixture-ready=true]').waitFor();
|
||||
check('Manage-only principal cannot reveal', await p.getByTestId('reveal-button').count() === 0);
|
||||
check('Denied principal rejected at route', (await p.request.get(origin + '/admin/secrets?role=denied')).status() === 403);
|
||||
check('No page errors', row.errors.length === 0);
|
||||
} catch (e) { row.failures.push(String(e)); }
|
||||
results.push(row); await p.close();
|
||||
}
|
||||
} finally { await context.close(); }
|
||||
return results;
|
||||
}
|
||||
Reference in New Issue
Block a user