Files
eleith 94c1aa95b9
ci/woodpecker/pr/config Pipeline was successful
ci/woodpecker/pr/hledger Pipeline was successful
ci/woodpecker/pr/jobs Pipeline was successful
ci/woodpecker/pr/snapshots Pipeline was successful
ci/woodpecker/pr/web Pipeline was successful
ci/woodpecker/pr/worker Pipeline was successful
feat(web): add period-aware financial pages and branded navigation
2026-11-06 15:24:37 -08:00

58 lines
2.1 KiB
TypeScript

import { expect, type Page } from '@playwright/test';
const preparationStamp = (page: Page) =>
page.getByLabel('Financial reports prepared at', { exact: true });
/** Explicit user action, including for external fictional-fixture smoke tests. */
export async function prepareReports(page: Page): Promise<string> {
await page.goto('/settings');
await expect(page.getByRole('heading', { name: 'Settings', exact: true })).toBeVisible();
const stamp = preparationStamp(page);
const previous = (await stamp.count()) ? await stamp.getAttribute('datetime') : null;
await Promise.all([
page.waitForResponse(
(response) =>
new URL(response.url()).pathname === '/settings' &&
response.request().method() === 'POST' &&
response.request().isNavigationRequest() &&
response.request().resourceType() === 'document'
),
page.getByRole('button', { name: 'Prepare reports', exact: true }).click()
]);
// Only the test reloads. Neither the form nor the report page polls an API.
const status = page.getByLabel('Preparation status', { exact: true });
await expect
.poll(
async () => {
await page.reload();
const current = (await stamp.count()) ? await stamp.getAttribute('datetime') : null;
return (
current !== null &&
current !== previous &&
(await status.innerText()).includes('No preparation is currently running.')
);
},
{ timeout: 25_000, intervals: [100, 250, 500] }
)
.toBe(true);
const preparedAt = (await stamp.getAttribute('datetime'))!;
await page.goto('/');
return preparedAt;
}
// Financial cases explicitly prepare only when there is no saved report.
export async function prepared(page: Page) {
await page.goto('/');
const table = page
.getByRole('region', { name: 'Income and spending', exact: true })
.getByRole('table');
if (!(await table.count())) await prepareReports(page);
await expect(table).toBeVisible();
}
export async function readPreparationTimestamp(page: Page): Promise<string> {
const stamp = preparationStamp(page);
await expect(stamp).toHaveAttribute('datetime', /.+/);
return (await stamp.getAttribute('datetime'))!;
}