pcbjam/tests/e2e/collapse-relayout.spec.ts
2026-07-06 09:17:10 +02:00

86 lines
4 KiB
TypeScript

// collapse-relayout — regression test for the pcbnew "Layer Display Options" bug.
//
// The Layers notebook page holds a proportion-1 scrolled layer list above a
// collapsible "Layer Display Options" pane. Toggling the pane runs KiCad's
// `Freeze(); page->Fit(); outerSizer->Layout(); Thaw();` idiom, which in the
// WASM DOM port permanently collapses the layer list (it stays at height 0,
// rows clip-pathed away, until reload). See wxNotebook::WasmRelayoutSelectedPage
// / wxWindowWasm::DoSetSize in the wxwidgets wasm port.
//
// A plain wxScrolledWindow is not in the JS element registry (its Create() runs
// during base construction and is skipped as a base type), so the app reports
// the layer-list height directly from C++ via console.log; the test asserts on
// those. It is RED before the wasm-layer fix and GREEN after.
import { test, expect, tryLoadApp } from './utils/fixtures';
import { clickByLabel, findByType, waitForRegistry } from './utils/element-tracker';
const APP = '/standalone/collapse-relayout/collapse-relayout_test.html';
const HEADER_LABEL = 'Layer Display Options';
// Parse "[COLLAPSE_RELAYOUT] <tag> = N" from the console logs (-1 if absent).
function reportedHeight(logs: string[], tag: string): number {
const line = logs.find(l => l.includes(tag));
const m = line?.match(/=\s*(\d+)/);
return m ? parseInt(m[1], 10) : -1;
}
// Expand the collapsible pane: click its header (wxGenericCollapsibleHeaderCtrl
// registers with the pane's label). Fall back to clicking the top of the pane.
async function expandPane(page: import('@playwright/test').Page): Promise<boolean> {
if (await clickByLabel(page, HEADER_LABEL)) return true;
const panes = await findByType(page, 'wxGenericCollapsiblePane');
if (panes.length) {
await page.mouse.click(panes[0].screenX + 15, panes[0].screenY + 10);
return true;
}
return false;
}
test.describe('collapse-relayout (Layer Display Options bug)', () => {
test('app loads with a populated layer list', async ({ page, testLogger }) => {
await page.goto(APP);
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForRegistry(page);
await page.waitForTimeout(300);
await page.screenshot({ path: 'test-results/collapse-relayout-01-loaded.png', fullPage: true });
expect(testLogger.consoleLogs.some(l => l.includes('[COLLAPSE_RELAYOUT] app started')),
'app-started log should be present').toBe(true);
const initial = reportedHeight(testLogger.consoleLogs, 'initial layerlist height');
console.log('initial layerlist height =', initial);
expect(initial, 'layer list should start with a real height').toBeGreaterThan(100);
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
});
test('layer list survives expanding "Layer Display Options"', async ({ page, testLogger }) => {
await page.goto(APP);
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForRegistry(page);
await page.waitForTimeout(300);
const initial = reportedHeight(testLogger.consoleLogs, 'initial layerlist height');
expect(initial, 'layer list should start with a real height').toBeGreaterThan(100);
const clicked = await expandPane(page);
expect(clicked, `"${HEADER_LABEL}" pane header should be found and clicked`).toBe(true);
await page.waitForTimeout(400);
await page.screenshot({ path: 'test-results/collapse-relayout-02-expanded.png', fullPage: true });
// The handler only logs on a real toggle — its presence proves the click
// reached the pane, and N is the list height measured right after relayout.
const afterToggle = reportedHeight(testLogger.consoleLogs, 'layerlist height after toggle');
console.log('layerlist height after toggle =', afterToggle);
expect(afterToggle, 'pane toggle handler should have run').toBeGreaterThan(-1);
// Core assertion: the list must NOT have collapsed to ~0.
expect(afterToggle, 'layer list height after expanding the pane').toBeGreaterThan(50);
});
});