e2e/pcb.spec.ts
Rama main · réplica de lectura del repositorio original.
import { openFileDetails, openProject, openProjectSection, navigateWorkspace } from "./workspace-controls";
import { expect, test } from "@playwright/test";
import { readFile } from "node:fs/promises";
import AxeBuilder from "@axe-core/playwright";
test("PCB viewer imports a native board, preserves the file, and remains usable on desktop and phone", async ({ page }) => {
await page.setViewportSize({ width: 1440, height: 1000 });
await page.goto("/"); await page.getByLabel("Workspace password").fill("demo-password-please-change"); await page.getByRole("button", { name: "Sign in", exact: true }).click();
await openProject(page, "Synthetic H2D desk lamp"); await page.getByRole("tab", { name: /^Files/u }).click();
const bytes = await readFile("packages/artifacts/testfiles/synthetic-board.kicad_pcb");
await page.getByLabel("Choose files to upload").setInputFiles({ name: "synthetic-board.kicad_pcb", mimeType: "application/x-kicad-pcb", buffer: bytes });
await page.getByRole("button", { name: "Add 1 file", exact: true }).click(); await expect(page.getByRole("button", { name: "Details for synthetic-board.kicad_pcb", exact: true })).toBeVisible();
await page.getByRole("button", { name: "Dismiss notification", exact: true }).click();
await openProjectSection(page, "PCB");
await page.getByLabel("Board source").selectOption({ label: "synthetic-board.kicad_pcb · r01" });
await page.getByRole("button", { name: "Open PCB", exact: true }).click();
await expect(page.locator(".pcb-workspace canvas")).toBeVisible(); await expect(page.locator(".assembly-dimensions")).toContainText("36.0 × 24.0"); await expect(page.getByText(/5 drill openings/)).toBeVisible();
await page.getByRole("button", { name: "Bottom", exact: true }).click(); await expect(page.getByRole("button", { name: "Bottom", exact: true })).toHaveAttribute("aria-pressed", "true");
await page.getByLabel("Board", { exact: true }).uncheck(); await page.getByLabel("Component outlines", { exact: true }).uncheck(); await page.getByLabel("Copper", { exact: true }).uncheck();
await expect(page.getByLabel("Show Back copper tracks", { exact: true })).not.toBeChecked(); await page.getByRole("button", { name: "Show all", exact: true }).click();
await page.getByRole("button", { name: "3D", exact: true }).click(); await page.getByLabel("Find a component or part").fill("R1"); await page.getByRole("button", { name: "R1 · footprint outline", exact: true }).click();
await expect(page.getByRole("heading", { name: "R1", exact: true })).toBeVisible(); await expect(page.getByText("1k", { exact: true })).toBeVisible();
await expect(page.getByRole("button", { name: /Save/ })).toHaveCount(0);
const canvas = page.locator(".pcb-workspace canvas"), box = (await canvas.boundingBox())!;
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2); await page.mouse.wheel(0, -120);
await page.getByRole("button", { name: "3D", exact: true }).focus();
await page.screenshot({ path: "test-results/pcb-desktop.png", fullPage: true });
expect((await new AxeBuilder({ page }).include(".pcb-workspace").withTags(["wcag2a", "wcag2aa", "wcag21aa"]).analyze()).violations).toEqual([]);
await navigateWorkspace(page, "Settings"); await page.getByRole("radio", { name: "Dark", exact: true }).check();
await page.goBack();
await page.getByLabel("Board source").selectOption({ label: "synthetic-board.kicad_pcb · r01" });
await page.getByRole("button", { name: "Open PCB", exact: true }).click();
await page.getByRole("button", { name: "Top", exact: true }).click(); await page.screenshot({ path: "test-results/pcb-dark-top.png", fullPage: true });
await page.setViewportSize({ width: 390, height: 844 }); await expect(canvas).toBeVisible(); await expect.poll(() => page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(390);
expect((await new AxeBuilder({ page }).include(".pcb-workspace").withTags(["wcag2a", "wcag2aa", "wcag21aa"]).analyze()).violations).toEqual([]);
await page.screenshot({ path: "test-results/pcb-mobile.png", fullPage: true });
await page.getByRole("button", { name: "Files & downloads", exact: true }).click();
const details = await openFileDetails(page, "synthetic-board.kicad_pcb");
const pending = page.waitForEvent("download"); await details.getByRole("button", { name: "Download file", exact: true }).click();
const stream = await (await pending).createReadStream(), chunks: Buffer[] = []; for await (const c of stream) chunks.push(Buffer.from(c)); expect(Buffer.concat(chunks)).toEqual(bytes);
});