51 lines
2.6 KiB
JavaScript
51 lines
2.6 KiB
JavaScript
// Audit saved views round-trip through the URL, and CSV/JSON exports carry
|
|
// the resolved window and arrive as attachments.
|
|
const assert = require('node:assert/strict');
|
|
const { trackAudit, exportOnce } = require('./helpers/audit-helpers.cjs');
|
|
|
|
module.exports = async ({ page, go, shot, fail, settled }) => {
|
|
const { waitForUrl } = trackAudit(page);
|
|
|
|
await go('/settings/audit');
|
|
await page.getByRole('button', { name: 'Runtime', exact: true }).click();
|
|
await waitForUrl((u) => u.searchParams.get('categories') === 'runtime');
|
|
|
|
const viewName = `e2e-view-${Date.now()}`;
|
|
await page.getByRole('button', { name: 'Audit actions', exact: true }).click();
|
|
await page.getByRole('menuitem', { name: 'Save view…', exact: true }).click();
|
|
const saveDialog = page.getByRole('dialog');
|
|
await saveDialog.waitFor();
|
|
await saveDialog.getByLabel('Name', { exact: true }).fill(viewName);
|
|
await saveDialog.getByRole('button', { name: 'Save', exact: true }).click();
|
|
await settled();
|
|
await saveDialog.waitFor({ state: 'hidden', timeout: 5000 }).catch(() => {});
|
|
|
|
const savedView = page.getByRole('combobox', { name: 'Saved view', exact: true });
|
|
await savedView.waitFor();
|
|
assert.equal((await savedView.innerText()).trim(), viewName);
|
|
await shot('saved-view');
|
|
|
|
await page.getByRole('button', { name: 'Runtime', exact: true }).click();
|
|
await waitForUrl((u) => u.searchParams.get('categories') === null);
|
|
await savedView.click();
|
|
await page.getByRole('option', { name: viewName, exact: true }).click();
|
|
await waitForUrl((u) => u.searchParams.get('categories') === 'runtime');
|
|
assert.equal((await savedView.innerText()).trim(), viewName, 'applying the saved view did not restore it');
|
|
|
|
await page.getByRole('button', { name: 'Audit actions', exact: true }).click();
|
|
await page.getByRole('menuitem', { name: 'Delete view', exact: true }).click();
|
|
await savedView.waitFor({ state: 'detached', timeout: 5000 }).catch(() => {});
|
|
assert.equal(await savedView.count(), 0, 'deleting the saved view left it in the picker');
|
|
|
|
await go('/settings/audit');
|
|
await page.getByRole('button', { name: 'Export', exact: true }).click();
|
|
await page.getByRole('menuitem', { name: 'CSV', exact: true }).waitFor();
|
|
await shot('export');
|
|
await page.keyboard.press('Escape');
|
|
|
|
const csvBody = await exportOnce(page, fail, 'CSV', 'csv');
|
|
if (csvBody !== null) assert.ok(csvBody.split('\n')[0].trim().length > 0, 'CSV export is empty');
|
|
const jsonBody = await exportOnce(page, fail, 'JSON', 'json');
|
|
if (jsonBody !== null) assert.ok(jsonBody.trimStart().startsWith('['), 'JSON export is not an array');
|
|
};
|