import { expect, test } from "@playwright/test"; import path from "node:path"; test("generates the 4x4 preview and blocks output when a wire is removed", async ({ page }) => { await page.goto("/"); const [download] = await Promise.all([ page.waitForEvent("download"), page.getByRole("button", { name: "プロジェクトを保存" }).click(), ]); const file = path.join(test.info().outputDir, download.suggestedFilename()); await download.saveAs(file); const source = JSON.parse(await (await import("node:fs/promises")).readFile(file, "utf8")); const keyIds: string[] = source.idx.order; source.elc.providers = [{ id: "MCU", kind: "mcu", part: "RP2040" }]; source.elc.keys = keyIds.map((key, i) => ({ key, detect: "contact", terminals: { a: `MCU.GP${Math.floor(i / 4)}`, b: `MCU.GP${4 + (i % 4)}` }, diode: "a-to-b", })); source.map.layers[0].keymap = keyIds.map((key, i) => ({ keyId: key, keycode: `KC_${i % 10}` })); const uploadProject = async (obj: unknown) => { const chooserPromise = page.waitForEvent("filechooser"); await page.getByRole("button", { name: "プロジェクトを開く" }).click(); await ( await chooserPromise ).setFiles({ name: "fixture.bkle.json", mimeType: "application/json", buffer: Buffer.from(JSON.stringify(obj)), }); }; await uploadProject(source); await page.getByRole("button", { name: "Generator" }).click(); for (let i = 0; i < 4; i++) { await page.getByTestId("row-pin-select").selectOption(`MCU.GP${i}`); await page.getByRole("button", { name: "row追加" }).click(); await page.getByTestId("col-pin-select").selectOption(`MCU.GP${i + 4}`); await page.getByRole("button", { name: "col追加" }).click(); } await page.getByTestId("generate-button").click(); await expect(page.getByTestId("mapping-count")).toHaveText("16行"); const rows = page.locator(".preview tbody tr"); await expect(rows).toHaveCount(16); await expect(rows.nth(0).locator("td").nth(2)).toHaveText("0"); await expect(rows.nth(0).locator("td").nth(3)).toHaveText("0"); await expect(rows.nth(4).locator("td").nth(2)).toHaveText("1"); await expect(rows.nth(4).locator("td").nth(3)).toHaveText("0"); await page.getByRole("button", { name: "ELC" }).click(); await page.locator(".wiring-box [data-testid=keyboard-view] .kv-key").first().click(); await page.getByRole("button", { name: "配線解除" }).click(); await page.getByRole("button", { name: "Generator" }).click(); await page.getByTestId("generate-button").click(); await expect(page.locator(".errors").getByText("unwired-key", { exact: true })).toBeVisible(); await expect(page.getByTestId("mapping-count")).toHaveCount(0); }); test("project undo invalidates a result generated from the newer project state", async ({ page }) => { await page.goto("/"); await page.getByRole("button", { name: "ELC" }).click(); await page.getByTestId("provider-id").fill("MCU"); await page.getByRole("button", { name: "MCUを追加・更新" }).click(); await page.getByRole("button", { name: "Generator" }).click(); await page.getByTestId("generate-button").click(); await expect(page.locator(".errors")).toBeVisible(); await page.getByRole("button", { name: "Undo" }).click(); await expect(page.locator(".errors")).toHaveCount(0); await expect(page.getByTestId("mapping-count")).toHaveCount(0); await page.getByRole("button", { name: "Redo" }).click(); await expect(page.locator(".errors")).toHaveCount(0); await expect(page.getByTestId("mapping-count")).toHaveCount(0); });