feat(ui): improve the records table, view state and record dialog
Test / test (push) Successful in 26m44s
Build and publish image / image (push) Successful in 27m27s

Sortable record columns, filters and sort kept in the URL on the zones,
zone and audit pages, a Show action that filters the records table to a
problem's owner, Save and add another, a highlight of the saved row, an
Audit history link on the zone page, and dialogs that keep typed input
on a backdrop click.
This commit is contained in:
bryanpedini committed 2026-11-22 17:36:46 +01:00
1 parent a67183b646
commit 440f78ce9e
9 files changed
+419 -36

No files matched your search

+81 -1
View File
@@ -4,7 +4,7 @@
import { test, expect } from '../harness/fixtures';
import type { RecordInput } from '../harness/ui';
import { up } from '../harness/api';
import { addAddress, checkZone, createZone } from '../harness/personas';
import { addAddress, address, checkZone, createZone } from '../harness/personas';
test.use({ group: 'stupid' });
@@ -70,3 +70,83 @@ test('operator mistakes preserve DNS, user records and delegations', async ({ wo
expect((await api.get(zonePath)).status).toBe(404);
expect(await world.db.records(zone)).toEqual([]);
});
test('records page keeps its view in the URL and protects typed input', async ({ world }) => {
const admin = await world.bootstrapAdmin();
const api = await world.apiAs(admin);
const ui = await world.uiAs(admin);
const zone = world.zoneName();
const zonePath = await createZone(api, zone);
await addAddress(api, zonePath, 'zeta', '192.0.2.40');
await addAddress(api, zonePath, 'alpha', '192.0.2.41');
await addAddress(api, zonePath, 'www', '192.0.2.42');
await addAddress(api, zonePath, 'www2', '192.0.2.44');
const mixed = await api.post(`${zonePath}/records`, address('www', '192.0.2.43', 600));
expect(mixed.status, mixed.text).toBe(201);
await ui.openZone(zone);
const page = ui.page;
const names = async () => (await ui.rows()).map((row) => row.name);
const nameHeader = page.locator('#records-table th[data-sort=name]');
await nameHeader.getByRole('button').click();
await expect(nameHeader).toHaveAttribute('aria-sort', 'ascending');
expect(await names()).toEqual(['@', '@', 'alpha', 'www', 'www', 'www2', 'zeta']);
await nameHeader.getByRole('button').click();
await expect(nameHeader).toHaveAttribute('aria-sort', 'descending');
expect(await names()).toEqual(['zeta', 'www2', 'www', 'www', 'alpha', '@', '@']);
await page.locator('#filter-text').fill('alpha');
await expect(page).toHaveURL(/[?&]q=alpha(&|$)/);
await expect(page).toHaveURL(/[?&]sort=-name(&|$)/);
await page.reload();
await ui.settle();
await expect(page.locator('#filter-text')).toHaveValue('alpha');
await expect(nameHeader).toHaveAttribute('aria-sort', 'descending');
expect(await names()).toEqual(['alpha']);
await page.getByRole('button', { name: 'Show www A in the records table' }).first().click();
await expect(page.locator('#filter-text')).toHaveValue(`www.${zone}`);
await expect(page.locator('#filter-type')).toHaveValue('A');
await expect(page.locator('#filter-text')).toBeFocused();
expect(await names()).toEqual(['www', 'www']);
await expect(page).toHaveURL(/[?&]name=www\./);
await page.locator('#filter-text').fill('');
await page.locator('#filter-type').selectOption('');
const dialog = page.locator('#record-dialog');
await page.click('#record-add');
await page.fill('#rec-name', 'unsaved');
await page.mouse.click(4, 4);
await expect(dialog, 'a backdrop click keeps an edited form open').toBeVisible();
await page.keyboard.press('Escape');
await expect(dialog).toBeHidden();
await page.click('#record-add');
await page.mouse.click(4, 4);
await expect(dialog, 'a backdrop click closes an untouched form').toBeHidden();
await page.click('#record-add');
await page.fill('#rec-name', 'multi');
await page.fill('#rec-f-ip', '192.0.2.50');
const first = page.waitForResponse((res) => res.url().endsWith(`/api/v1${zonePath}/records`) && res.request().method() === 'POST');
await page.click('#rec-submit-another');
expect((await first).status()).toBe(201);
await expect(dialog).toBeVisible();
await expect(page.locator('#rec-name')).toHaveValue('multi');
await expect(page.locator('#rec-f-ip')).toHaveValue('');
await expect(page.locator('#rec-f-ip')).toBeFocused();
await expect(page.locator('#rec-status')).toContainText('Record added.');
await page.fill('#rec-f-ip', '192.0.2.51');
const second = page.waitForResponse((res) => res.url().endsWith(`/api/v1${zonePath}/records`) && res.request().method() === 'POST');
await page.click('#rec-submit');
expect((await second).status()).toBe(201);
await expect(dialog).toBeHidden();
await expect(page.locator('#records-body tr.row-flash')).toHaveCount(1);
await expect(page.locator('#records-body tr.row-flash th')).toHaveText('multi');
await ui.settle();
expect((await world.db.records(zone)).filter((row) => row.name === 'multi').length).toBe(2);
await page.click('#audit-link');
await ui.settle();
await expect(page.locator('#af-zone')).toHaveValue(zone);
await expect(page.locator('#af-kind')).toHaveValue('change');
await expect(page.locator('#audit-body tr:not(.detail-row)').first()).toContainText(zone);
});