2026-06-11 12:22:34 +02:00
|
|
|
import { test, expect, type Page } from '@playwright/test';
|
2026-07-07 10:50:24 +02:00
|
|
|
import { clickMenuBarItem, clickMenuItemByText, stableShot } from '../e2e/utils/element-tracker';
|
2026-06-11 12:22:34 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tool-switch e2e: eeschema Tools → "Switch to PCB Editor" (and the reverse)
|
|
|
|
|
* must navigate the browser to the other tool's URL.
|
|
|
|
|
*
|
|
|
|
|
* Native KiCad spawns a process for this via ExecuteFile (common/gestfich.cpp);
|
|
|
|
|
* the WASM build delegates to window.kicadWebOpenTool (WasmTool.tsx), which
|
|
|
|
|
* maps the MEMFS file path to the project-relative file and calls
|
2026-07-16 13:56:27 +02:00
|
|
|
* location.assign(/:scope/projects/:name/<file>) — the tool is inferred from
|
|
|
|
|
* the file extension. Each direction is a full page navigation followed by a
|
|
|
|
|
* fresh wasm boot — hence the generous timeouts.
|
2026-06-11 12:22:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
async function waitForToolReady(page: Page, titleRe: RegExp): Promise<void> {
|
|
|
|
|
await expect(page.locator('#canvas')).toBeVisible({ timeout: 120000 });
|
|
|
|
|
await expect
|
|
|
|
|
.poll(() => page.title(), {
|
|
|
|
|
message: `editor never reached title ${titleRe}`,
|
|
|
|
|
timeout: 120000,
|
|
|
|
|
intervals: [1000],
|
|
|
|
|
})
|
|
|
|
|
.toMatch(titleRe);
|
|
|
|
|
// The menu helpers drive the rendered-element registry.
|
|
|
|
|
await page.waitForFunction(
|
|
|
|
|
() =>
|
|
|
|
|
!!(window as unknown as { wxElementRegistry?: { findAllRendered?: unknown } })
|
|
|
|
|
.wxElementRegistry,
|
|
|
|
|
null,
|
|
|
|
|
{ timeout: 30000 }
|
|
|
|
|
);
|
2026-07-16 13:56:27 +02:00
|
|
|
// The boot and eager-library overlays (WasmTool, `absolute inset-0 z-30`)
|
|
|
|
|
// cover the whole editor including the menubar — synthetic menu clicks land
|
|
|
|
|
// on them until they clear (eeschema hydrates the full symbol set post-boot).
|
|
|
|
|
await expect(page.locator("div.absolute.inset-0.z-30")).toHaveCount(0, {
|
|
|
|
|
timeout: 180000,
|
|
|
|
|
});
|
2026-06-11 12:22:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function switchTool(
|
|
|
|
|
page: Page,
|
|
|
|
|
menuLabel: string,
|
|
|
|
|
expectedUrl: RegExp,
|
|
|
|
|
expectedTitle: RegExp
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
expect(await clickMenuBarItem(page, 'Tools'), 'Tools menubar item clickable').toBe(true);
|
2026-07-07 10:50:24 +02:00
|
|
|
await clickMenuItemByText(page, menuLabel);
|
2026-06-11 12:22:34 +02:00
|
|
|
|
|
|
|
|
await page.waitForURL(expectedUrl, { timeout: 30000 });
|
|
|
|
|
await waitForToolReady(page, expectedTitle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test.describe('web app — tool switching', () => {
|
|
|
|
|
test('eeschema → Switch to PCB Editor navigates to pcbnew', async ({ page }) => {
|
|
|
|
|
test.setTimeout(420000); // two full wasm boots
|
|
|
|
|
|
2026-07-06 16:10:52 +02:00
|
|
|
await page.goto('/default/projects/demo/demo.kicad_sch');
|
2026-06-11 12:22:34 +02:00
|
|
|
await waitForToolReady(page, /demo — Schematic Editor/i);
|
|
|
|
|
|
|
|
|
|
await switchTool(
|
|
|
|
|
page,
|
|
|
|
|
'Switch to PCB Editor',
|
2026-07-16 13:56:27 +02:00
|
|
|
/\/default\/projects\/demo\/demo\.kicad_pcb/,
|
2026-06-11 12:22:34 +02:00
|
|
|
/demo — PCB Editor/i
|
|
|
|
|
);
|
|
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
await stableShot(page, 'web-switch-sch-to-pcb.png');
|
2026-06-11 12:22:34 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('pcbnew → Switch to Schematic Editor navigates to eeschema', async ({ page }) => {
|
|
|
|
|
test.setTimeout(420000);
|
|
|
|
|
|
2026-07-06 16:10:52 +02:00
|
|
|
await page.goto('/default/projects/demo/demo.kicad_pcb');
|
2026-06-11 12:22:34 +02:00
|
|
|
await waitForToolReady(page, /demo — PCB Editor/i);
|
|
|
|
|
|
|
|
|
|
await switchTool(
|
|
|
|
|
page,
|
|
|
|
|
'Switch to Schematic Editor',
|
2026-07-16 13:56:27 +02:00
|
|
|
/\/default\/projects\/demo\/demo\.kicad_sch/,
|
2026-06-11 12:22:34 +02:00
|
|
|
/demo — Schematic Editor/i
|
|
|
|
|
);
|
|
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
await stableShot(page, 'web-switch-pcb-to-sch.png');
|
2026-06-11 12:22:34 +02:00
|
|
|
});
|
|
|
|
|
});
|