Prepare long Investment activity once in browser tests #87
@@ -183,8 +183,10 @@ test('phone activity keeps the selected stock focused while retaining cash conte
|
||||
await details.getByRole('button', { name: 'Close activity details', exact: true }).click();
|
||||
});
|
||||
|
||||
test('entry cash balance stays on the original final action across continuously loaded batches', async ({
|
||||
page
|
||||
test('one long investment entry stays readable across the 50-row boundary with and without JavaScript', async ({
|
||||
browser,
|
||||
page,
|
||||
storageState
|
||||
}) => {
|
||||
const deployment = process.env.HLEDGER_TEST_DEPLOYMENT;
|
||||
test.skip(
|
||||
@@ -199,104 +201,73 @@ test('entry cash balance stays on the original final action across continuously
|
||||
await openInvestment(page, 'retirement');
|
||||
const firstPage = new URL(page.url());
|
||||
firstPage.search = 'order=asc&page=1';
|
||||
await page.goto(firstPage.href);
|
||||
const activity = page.getByRole('region', { name: 'Investment activity', exact: true });
|
||||
const rows = activity
|
||||
.getByRole('row')
|
||||
.filter({ has: page.locator('button[data-investment-details]') });
|
||||
const rowAt = (rowPosition: number) =>
|
||||
activity
|
||||
.getByRole('row')
|
||||
.filter({ has: page.locator(`[data-row-position="${rowPosition}"]`) });
|
||||
const first = rowAt(0);
|
||||
const second = rowAt(1);
|
||||
await expect(first.getByRole('button', { name: /^Open investment activity:/ })).toBeEnabled();
|
||||
const firstKey = await first.locator('[data-column="date"]').getAttribute('data-activity-key');
|
||||
if (!firstKey) throw new Error('Missing native activity identity.');
|
||||
await expect(first.locator('[data-column="security"]')).toHaveText('BATCH', {
|
||||
useInnerText: true
|
||||
await test.step('Enhanced navigation loads the next batch without leaving the register', async () => {
|
||||
await page.goto(firstPage.href);
|
||||
const activity = page.getByRole('region', { name: 'Investment activity', exact: true });
|
||||
const cell = (position: number, column: string) =>
|
||||
activity.locator(`[data-row-position="${position}"][data-column="${column}"]`);
|
||||
const first = cell(0, 'date');
|
||||
await expect(first.getByRole('button')).toBeEnabled();
|
||||
const firstKey = await first.getAttribute('data-activity-key');
|
||||
const entryIndex = /^(\d+):0$/.exec(firstKey ?? '')?.[1];
|
||||
if (!entryIndex) throw new Error('Missing first posting of the batch purchase.');
|
||||
|
||||
const secondPosting = cell(1, 'date').getByRole('button');
|
||||
await secondPosting.click();
|
||||
const details = page.getByRole('dialog', { name: 'Activity details', exact: true });
|
||||
const notes = details.getByRole('textbox', { name: 'Notes', exact: true });
|
||||
await expect(notes).toHaveValue(/\bbatch buy 02\b/);
|
||||
await expect(notes).not.toHaveValue(/\bbatch buy (?!02\b)\d{2}\b/);
|
||||
await expect(details).toContainText('Entry activity 2 of 55');
|
||||
await details.getByRole('button', { name: 'Close activity details', exact: true }).click();
|
||||
await expect(secondPosting).toBeFocused();
|
||||
|
||||
const pagination = page.getByRole('navigation', { name: 'Pagination', exact: true });
|
||||
await pagination.getByRole('link', { name: 'Next', exact: true }).click();
|
||||
await expect(cell(50, 'date')).toHaveAttribute('data-activity-key', `${entryIndex}:50`);
|
||||
await expect(cell(50, 'cash-balance')).toHaveText('');
|
||||
await expect(cell(54, 'date')).toHaveAttribute('data-activity-key', `${entryIndex}:54`);
|
||||
await expect(cell(54, 'cash-balance')).toHaveText('Not reported');
|
||||
await expect(page).toHaveURL(firstPage.href);
|
||||
await pagination.getByRole('link', { name: 'Previous', exact: true }).click();
|
||||
await expect(first).toBeInViewport();
|
||||
});
|
||||
await expect(first.locator('[data-column="price"]')).toHaveText('$1.00');
|
||||
await expect(second.locator('[data-column="price"]')).toHaveText('$2.00');
|
||||
await expect(first.locator('[data-column="cash-balance"]')).toHaveText('');
|
||||
await expect(second.locator('[data-column="cash-balance"]')).toHaveText('');
|
||||
await expect(second.locator('[data-column="cash-impact"]')).toHaveText('—');
|
||||
const table = activity.getByRole('table', {
|
||||
name: 'Investment account activities',
|
||||
exact: true
|
||||
|
||||
await test.step('Without JavaScript, Next opens another saved page of the same entry', async () => {
|
||||
const savedPage = await browser.newPage({
|
||||
javaScriptEnabled: false,
|
||||
storageState,
|
||||
timezoneId: 'UTC'
|
||||
});
|
||||
try {
|
||||
await savedPage.goto(firstPage.href);
|
||||
const activity = savedPage.getByRole('region', {
|
||||
name: 'Investment activity',
|
||||
exact: true
|
||||
});
|
||||
const rows = activity.locator('tr[data-activity-key]');
|
||||
await expect(rows).toHaveCount(50);
|
||||
const firstKey = await rows.first().getAttribute('data-activity-key');
|
||||
const entryIndex = /^(\d+):0$/.exec(firstKey ?? '')?.[1];
|
||||
if (!entryIndex) throw new Error('Missing first posting of the batch purchase.');
|
||||
await expect(rows.last()).toHaveAttribute('data-activity-key', `${entryIndex}:49`);
|
||||
await expect(rows.last().locator('[data-column="cash-balance"]')).toHaveText('');
|
||||
|
||||
await savedPage
|
||||
.getByRole('navigation', { name: 'Pagination', exact: true })
|
||||
.getByRole('link', { name: 'Next', exact: true })
|
||||
.click();
|
||||
await expect(savedPage).toHaveURL(/page=2$/);
|
||||
await expect(rows.first()).toHaveAttribute('data-activity-key', `${entryIndex}:50`);
|
||||
await expect(rows.first().locator('[data-column="cash-balance"]')).toHaveText('');
|
||||
const finalPosting = activity.locator(`tr[data-activity-key="${entryIndex}:54"]`);
|
||||
await expect(finalPosting.locator('[data-column="cash-balance"]')).toHaveText(
|
||||
'Not reported'
|
||||
);
|
||||
} finally {
|
||||
await savedPage.close();
|
||||
}
|
||||
});
|
||||
await table.evaluate((element) => {
|
||||
element.scrollTop = element.clientHeight / 2;
|
||||
});
|
||||
await expect(activity.locator('[data-row-position="0"][data-column="date"]')).toHaveCount(0);
|
||||
const laterSibling = rowAt(12);
|
||||
await expect(laterSibling.locator('[data-column="date"]')).toHaveAttribute(
|
||||
'data-activity-key',
|
||||
`${firstKey.split(':')[0]}:12`
|
||||
);
|
||||
await expect(laterSibling.locator('[data-column="price"]')).toHaveText('$13.00');
|
||||
await expect(laterSibling.locator('[data-column="cash-impact"]')).toHaveText('—');
|
||||
await expect(laterSibling.locator('[data-column="cash-balance"]')).toHaveText('');
|
||||
await table.evaluate((element) => {
|
||||
element.scrollTop = 0;
|
||||
});
|
||||
await expect(first.locator('[data-column="cash-impact"]')).toContainText('USD');
|
||||
const opener = second.getByRole('button', { name: /^Open investment activity:/ });
|
||||
await opener.click();
|
||||
const details = page.getByRole('dialog', { name: 'Activity details', exact: true });
|
||||
await expect(details.getByRole('region', { name: 'Activity', exact: true })).toContainText(
|
||||
'$2 USD'
|
||||
);
|
||||
const notes = details.getByRole('textbox', { name: 'Notes', exact: true });
|
||||
await expect(notes).toHaveValue(/batch buy 02/);
|
||||
await expect(notes).not.toHaveValue(/batch buy 01|batch buy 03/);
|
||||
await expect(
|
||||
details.getByRole('group', { name: 'Activity summary', exact: true })
|
||||
).toContainText('Entry activity 2 of 55');
|
||||
await details.getByRole('button', { name: 'Close activity details', exact: true }).click();
|
||||
await expect(opener).toBeFocused();
|
||||
const pagination = page.getByRole('navigation', { name: 'Pagination', exact: true });
|
||||
await pagination.getByRole('link', { name: 'Next', exact: true }).click();
|
||||
await expect(page).toHaveURL(firstPage.href);
|
||||
const entryIndex = firstKey.split(':')[0];
|
||||
const earlierBatch = rowAt(50);
|
||||
const finalBatch = rowAt(54);
|
||||
await expect(finalBatch.locator('[data-column="date"]')).toHaveAttribute(
|
||||
'data-activity-key',
|
||||
`${entryIndex}:54`
|
||||
);
|
||||
await expect(earlierBatch.locator('[data-column="price"]')).toHaveText('$51.00');
|
||||
await expect(finalBatch.locator('[data-column="price"]')).toHaveText('$55.00');
|
||||
await expect(earlierBatch.locator('[data-column="cash-balance"]')).toHaveText('');
|
||||
await expect(finalBatch.locator('[data-column="cash-balance"]')).toHaveText('Not reported');
|
||||
const deposit = rows.filter({
|
||||
has: page.locator('[data-column="action"]', { hasText: 'Deposit' })
|
||||
});
|
||||
await expect(deposit.locator('[data-column="cash-balance"]')).toHaveText('$100.00');
|
||||
const soloBuy = rows
|
||||
.filter({ has: page.locator('[data-column="security"]', { hasText: 'SOLO' }) })
|
||||
.filter({ has: page.locator('[data-column="action"]', { hasText: 'Buy' }) });
|
||||
await expect(soloBuy).toHaveCount(1);
|
||||
await expect(soloBuy.locator('[data-column="cash-impact"]')).toHaveText('-$100.00');
|
||||
await expect(soloBuy.locator('[data-column="cash-balance"]')).not.toHaveText('');
|
||||
const soloKey = await soloBuy.locator('[data-column="date"]').getAttribute('data-activity-key');
|
||||
if (!soloKey) throw new Error('Missing single-stock activity identity.');
|
||||
await expect(
|
||||
activity.locator(`[data-column="date"][data-activity-key^="${soloKey.split(':')[0]}:"]`)
|
||||
).toHaveCount(1);
|
||||
await soloBuy.getByRole('button', { name: /^Open investment activity:/ }).click();
|
||||
await expect(
|
||||
details.getByRole('group', { name: 'Activity summary', exact: true })
|
||||
).toContainText('-$100.00 USD');
|
||||
await expect(details).not.toContainText('Entry activity');
|
||||
await details.getByRole('button', { name: 'Close activity details', exact: true }).click();
|
||||
await pagination.getByRole('link', { name: 'Previous', exact: true }).click();
|
||||
await expect(first.locator('[data-column="date"]')).toHaveAttribute(
|
||||
'data-activity-key',
|
||||
firstKey
|
||||
);
|
||||
await expect(first.locator('[data-column="price"]')).toHaveText('$1.00');
|
||||
await expect(second.locator('[data-column="cash-impact"]')).toHaveText('—');
|
||||
} finally {
|
||||
await cleanup();
|
||||
await prepareReports(page);
|
||||
@@ -305,53 +276,6 @@ test('entry cash balance stays on the original final action across continuously
|
||||
|
||||
test.describe('without JavaScript', () => {
|
||||
test.use({ javaScriptEnabled: false });
|
||||
test('ordinary fifty-activity pages keep native identity and the original entry-final balance', async ({
|
||||
page
|
||||
}) => {
|
||||
const deployment = process.env.HLEDGER_TEST_DEPLOYMENT;
|
||||
test.skip(
|
||||
Boolean(process.env.PLAYWRIGHT_BASE_URL) || !deployment,
|
||||
'Requires the exclusively owned direct browser fixture.'
|
||||
);
|
||||
if (!deployment) throw new Error('Missing owned browser deployment.');
|
||||
const cleanup = await addInvestmentPostingsFixture(deployment);
|
||||
try {
|
||||
await prepareReports(page);
|
||||
await openInvestment(page, 'retirement');
|
||||
const destination = new URL(page.url());
|
||||
destination.search = 'order=asc&page=1';
|
||||
await page.goto(destination.href);
|
||||
const activity = page.getByRole('region', { name: 'Investment activity', exact: true });
|
||||
const rows = activity.locator('tr[data-activity-key]');
|
||||
await expect(rows).toHaveCount(50);
|
||||
const keys = await rows.evaluateAll((elements) =>
|
||||
elements.map((element) => element.getAttribute('data-activity-key')!)
|
||||
);
|
||||
expect(new Set(keys).size).toBe(50);
|
||||
expect(new Set(keys.map((key) => key.split(':')[0])).size).toBe(1);
|
||||
await expect(rows.last().locator('[data-column="price"]')).toHaveText('$50.00');
|
||||
expect(
|
||||
(await rows.locator('[data-column="cash-balance"]').allTextContents()).map((text) =>
|
||||
text.trim()
|
||||
)
|
||||
).toEqual(Array(50).fill(''));
|
||||
await page
|
||||
.getByRole('navigation', { name: 'Pagination', exact: true })
|
||||
.getByRole('link', { name: 'Next', exact: true })
|
||||
.click();
|
||||
await expect(page).toHaveURL(/page=2$/);
|
||||
const entryIndex = keys[0].split(':')[0];
|
||||
await expect(
|
||||
activity.locator(`tr[data-activity-key="${entryIndex}:50"] [data-column="cash-balance"]`)
|
||||
).toHaveText('');
|
||||
await expect(
|
||||
activity.locator(`tr[data-activity-key="${entryIndex}:54"] [data-column="cash-balance"]`)
|
||||
).toHaveText('Not reported');
|
||||
} finally {
|
||||
await cleanup();
|
||||
await prepareReports(page);
|
||||
}
|
||||
});
|
||||
test('investment posting activity, date navigation and focus remain readable in saved HTML', async ({
|
||||
page
|
||||
}) => {
|
||||
|
||||
Reference in new issue
Block a user