155 lines
6.5 KiB
TypeScript
155 lines
6.5 KiB
TypeScript
import { expect, test } from '@playwright/test';
|
|
import { prepareReports, readPreparationTimestamp } from './overview-fixture';
|
|
import { historyRowCount } from './history-fixture';
|
|
|
|
test.use({ javaScriptEnabled: false });
|
|
|
|
test('explicitly prepares reports and reads Overview, Net worth and Settings without JavaScript', async ({
|
|
page
|
|
}) => {
|
|
await page.setViewportSize({ width: 390, height: 844 });
|
|
const posts: string[] = [];
|
|
page.on('request', (request) => {
|
|
if (request.method() === 'POST') posts.push(new URL(request.url()).pathname);
|
|
});
|
|
|
|
const preparedAt = await prepareReports(page);
|
|
const income = page.getByRole('region', { name: 'Income and spending', exact: true });
|
|
await expect(income.locator('tbody tr')).toHaveCount(6);
|
|
await expect(income.locator('tbody tr').nth(4).getByRole('cell')).toHaveText([
|
|
'Income',
|
|
'1000.00',
|
|
'USD'
|
|
]);
|
|
await expect(income.locator('tbody tr').nth(5).getByRole('cell')).toHaveText([
|
|
'Spending',
|
|
'100.00',
|
|
'USD'
|
|
]);
|
|
const categories = page.getByRole('region', { name: 'Spending by category', exact: true });
|
|
const categoryRows = categories
|
|
.getByRole('table', { name: 'Spending by account', exact: true })
|
|
.locator('tbody tr');
|
|
const clothing = categoryRows.filter({
|
|
has: page.getByRole('rowheader', { name: 'expenses:clothing', exact: true })
|
|
});
|
|
const transactions = page
|
|
.getByText('Transactions', { exact: true })
|
|
.locator('..')
|
|
.getByRole('definition');
|
|
const primary = page.getByRole('navigation', { name: 'Primary', exact: true });
|
|
await expect(primary.getByRole('link', { name: 'Overview', exact: true })).toHaveAttribute(
|
|
'aria-current',
|
|
'page'
|
|
);
|
|
await expect(transactions).toHaveText((10 + historyRowCount).toLocaleString('en-US'));
|
|
await expect(
|
|
categories.getByText('Chart loads with JavaScript; exact amounts below.', { exact: true })
|
|
).toBeVisible();
|
|
await expect(categories.getByRole('img')).toHaveCount(0);
|
|
// The complete native table remains usable without a client-only chart selector.
|
|
await expect(categoryRows).toHaveCount(7);
|
|
await expect(categoryRows.first().getByRole('cell')).toHaveText(['2.00', 'USD']);
|
|
await expect(clothing.getByRole('cell')).toHaveText(['4.00', 'USD']);
|
|
await expect(page.getByRole('region', { name: 'Net worth trend', exact: true })).toHaveCount(0);
|
|
await expect(page.getByRole('region', { name: 'Journal summary', exact: true })).toHaveCount(0);
|
|
|
|
await page.getByRole('combobox', { name: 'Overview period', exact: true }).selectOption('1');
|
|
await page.getByRole('button', { name: 'Apply period', exact: true }).click();
|
|
await expect(page).toHaveURL(/\/\?months=1$/);
|
|
await expect(income.locator('tbody tr')).toHaveCount(2);
|
|
await expect(income.locator('tbody tr').getByRole('rowheader')).toHaveText([
|
|
'2026-04',
|
|
'2026-04'
|
|
]);
|
|
await expect(income.locator('tbody tr').getByRole('cell')).toHaveText([
|
|
'Income',
|
|
'1000.00',
|
|
'USD',
|
|
'Spending',
|
|
'100.00',
|
|
'USD'
|
|
]);
|
|
await expect(categoryRows).toHaveCount(7);
|
|
await expect(clothing.getByRole('cell')).toHaveText(['4.00', 'USD']);
|
|
await expect(transactions).toHaveText((10 + historyRowCount).toLocaleString('en-US'));
|
|
|
|
await page.reload();
|
|
await expect(page.getByRole('combobox', { name: 'Overview period', exact: true })).toHaveValue(
|
|
'1'
|
|
);
|
|
await expect(income.getByRole('table')).toContainText('1000.00');
|
|
await expect(income.locator('tbody tr')).toHaveCount(2);
|
|
await expect(categoryRows).toHaveCount(7);
|
|
await expect(clothing.getByRole('cell')).toHaveText(['4.00', 'USD']);
|
|
await expect(transactions).toHaveText((10 + historyRowCount).toLocaleString('en-US'));
|
|
|
|
// The server-rendered Accounts disclosure remains real navigation without hydration.
|
|
const disclosure = page
|
|
.locator('details')
|
|
.filter({ has: page.locator('summary', { hasText: /^Accounts$/ }) });
|
|
await disclosure
|
|
.locator('summary')
|
|
.filter({ hasText: /^Accounts$/ })
|
|
.click();
|
|
const balanceDate = disclosure.getByText(/^Balances as of/);
|
|
await expect(balanceDate).toBeVisible();
|
|
await expect(balanceDate.locator('time')).toHaveAttribute('datetime', '2026-04-16');
|
|
await disclosure.getByRole('link', { name: /^Net worth/ }).click();
|
|
await expect(page).toHaveURL(/\/reports\/networth$/);
|
|
const period = page.getByRole('combobox', { name: 'Net worth period', exact: true });
|
|
const netWorth = page.getByRole('table', { name: 'Net worth by valuation date', exact: true });
|
|
await expect(period).toHaveValue('3');
|
|
await expect(netWorth.locator('tbody tr')).toHaveCount(3);
|
|
await period.selectOption('1');
|
|
await page.getByRole('button', { name: 'Apply period', exact: true }).click();
|
|
await expect(page).toHaveURL(/\/reports\/networth\?months=1$/);
|
|
await expect(period).toHaveValue('1');
|
|
await expect(netWorth.locator('tbody tr')).toHaveCount(1);
|
|
await expect(netWorth.locator('tbody tr').getByRole('rowheader')).toHaveText('2026-04-16');
|
|
await expect(netWorth.locator('tbody tr').getByRole('cell')).toHaveText([
|
|
'11825.00',
|
|
'USD',
|
|
'No unconverted units'
|
|
]);
|
|
// Real SSR query navigation must retain the footer's current-page semantics.
|
|
await disclosure
|
|
.locator('summary')
|
|
.filter({ hasText: /^Accounts$/ })
|
|
.click();
|
|
await expect(disclosure.getByRole('link', { name: /^Net worth/ })).toHaveAttribute(
|
|
'aria-current',
|
|
'page'
|
|
);
|
|
|
|
await page
|
|
.getByRole('navigation', { name: 'Primary', exact: true })
|
|
.getByRole('link', { name: 'Settings', exact: true })
|
|
.click();
|
|
await expect(primary.getByRole('link', { name: 'Settings', exact: true })).toHaveAttribute(
|
|
'aria-current',
|
|
'page'
|
|
);
|
|
const journal = page.getByRole('region', { name: 'Journal summary', exact: true });
|
|
const span = journal.getByText('Full date span', { exact: true }).locator('..');
|
|
await expect(span.locator('time').first()).toHaveAttribute('datetime', '2026-01-15');
|
|
await expect(span.locator('time').last()).toHaveAttribute('datetime', '2026-04-16');
|
|
await expect(
|
|
journal.getByText('Total transactions', { exact: true }).locator('..').getByRole('definition')
|
|
).toHaveText((11 + historyRowCount).toLocaleString('en-US'));
|
|
await expect(
|
|
journal.getByText('hledger version', { exact: true }).locator('..').getByRole('definition')
|
|
).toHaveText('1.99.5');
|
|
await expect(
|
|
journal.getByText('Report currency', { exact: true }).locator('..').getByRole('definition')
|
|
).toHaveText('USD');
|
|
await expect(journal.getByLabel('Saved journal validation', { exact: true })).toContainText(
|
|
'Passed'
|
|
);
|
|
await expect(
|
|
journal.getByLabel('Journal validation completed at', { exact: true })
|
|
).toHaveAttribute('datetime', /.+/);
|
|
expect(await readPreparationTimestamp(page)).toBe(preparedAt);
|
|
expect(posts).toEqual(['/settings']);
|
|
});
|