From 1439bc760573f895608ab7cf08239959231240ca Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 20 Nov 2026 15:52:00 +0100 Subject: [PATCH] :recycle: Cut the shortcuts and inspect tab e2e specs (#13010) * :recycle: Cut shortcuts and inspect e2e specs and harden their assertions Shortcuts spec: drop the enable-custom-shortcuts mock, since no frontend, common or backend code reads the flag, and cut 18 tests to 6. A header comment records where the removed rules went: named steps here and the 77 unit tests of settings_shortcuts_test.cljs. The six keep only what a browser proves: the file input and diff modal, the alert for a file with nothing to apply, the download of a bound and an empty entry, the RPC write with reload, the conflict that disables the previous binding, and both reset flows. Fix the shortcuts review findings: the invalid-file step dismisses the timeout-free toast before the next import and covers both removed payloads in one import. The conflict test records a default-bound and a custom-bound key on one page load, then resets and imports a key a default binding holds, so the diff modal's apply path runs with a default in the way, and checks the alert, the disabled row and the exported payload; the export test resets and imports the file it just downloaded. Inspect tab spec: cut 27 tests to 8 with 25 named steps, from 622.9 to 181.5 worker-seconds and 162.5 to 46.7 seconds of wall time. Layout, shadow and blur, fill, stroke, typography and clipboard cases run as steps in one page load per group; the two cases that mutate the shape with Design-tab controls keep their own. Replace 500 ms sleeps with waits on rendered state, make layer expansion idempotent, match layer names exactly, poll row counts and await every matcher. Drop the false comment about name capitalisation, the three unused shapeToLayerName entries and the skip the "Layer info" assertion now covers. Move layerRow and selectLayer into WorkspacePage with the helpers the next PR in the stack needs: layerRow matches an anchored name on the layer-row test id, because a selected row's hide and lock button titles join its accessible name, and selectLayer waits for aria-checked instead of the shape name. waitForSelectedShapeName takes options. The inspect spec drops its escapeRegExp, getLayerRow and inline selection. Rename the fixture token to radius-md so the radius assertion is not satisfied by the row label. Closes #13009 AI-assisted-by: deepseek-v4.1-flash * :bug: Pass the translation flag in the sync text undo test The merge of staging into develop brought back the required :translation key of an undo entry, and the test added in ef0333eafe calls append-undo without it. check-undo-entry throws, the exception escapes the promise and the whole frontend run exits before printing the summary. The entry stands for the commit of a component sync, which is not a translation, so it carries :translation false, the value the production watcher derives from the commit. AI-assisted-by: deepseek-v4.1-flash --- .serena/memories/frontend/testing.md | 2 + .../data/workspace/get-file-inspect-tab.json | 6 +- frontend/playwright/ui/pages/WorkspacePage.js | 25 +- .../playwright/ui/specs/inspect-tab.spec.js | 1078 +++++++---------- .../playwright/ui/specs/shortcuts.spec.js | 429 +++---- .../data/workspace_sync_text_wasm_test.cljs | 3 +- 6 files changed, 625 insertions(+), 918 deletions(-) diff --git a/.serena/memories/frontend/testing.md b/.serena/memories/frontend/testing.md index 4f2f5a257c..b4215a6fdf 100644 --- a/.serena/memories/frontend/testing.md +++ b/.serena/memories/frontend/testing.md @@ -72,6 +72,8 @@ Integration tests fake backend behavior by intercepting network/websocket traffi Locator priority should follow user-facing semantics: `getByRole`, `getByLabel`, `getByPlaceholder`, `getByText`, then semantic alternatives such as alt/title, with `getByTestId` as the last resort. Name tests from the user's perspective and prefer positive, single-purpose assertions. +Layer rows are the exception: a selected row's hide and lock button titles join its accessible name, so role-plus-name matching breaks on selected rows. Use `WorkspacePage.layerRow`, which anchors on the `layer-row` test id's text, and `selectLayer`, which waits for `aria-checked`. + ## CI (E2E) `.github/workflows/tests-e2e.yml` runs the integration specs, the composable component suite, and the mocked Plugin API suite from one workflow that builds the frontend bundle once per SHA. Before adding a job that needs the bundle, read `mem:frontend/e2e-ci-workflow` (build-once contract, cache key, stable check names). diff --git a/frontend/playwright/data/workspace/get-file-inspect-tab.json b/frontend/playwright/data/workspace/get-file-inspect-tab.json index 5b11da7500..a007d054dd 100644 --- a/frontend/playwright/data/workspace/get-file-inspect-tab.json +++ b/frontend/playwright/data/workspace/get-file-inspect-tab.json @@ -3224,7 +3224,7 @@ "~:r1": 0, "~:id": "~u6ce76eb4-b183-804e-8007-04b6eb5e1080", "~:parent-id": "~u6ce76eb4-b183-804e-8007-04b6f725fae8", - "~:applied-tokens": { "~:r2": "radius", "~:r3": "radius" }, + "~:applied-tokens": { "~:r2": "radius-md", "~:r3": "radius-md" }, "~:frame-id": "~u6ce76eb4-b183-804e-8007-04b6f725fae8", "~:strokes": [], "~:x": 1758, @@ -5932,11 +5932,11 @@ } ], [ - "radius", + "radius-md", { "~#penpot/token": { "~:id": "~u6ce76eb4-b183-804e-8007-04b769351486", - "~:name": "radius", + "~:name": "radius-md", "~:type": "~:border-radius", "~:value": "20px", "~:description": "", diff --git a/frontend/playwright/ui/pages/WorkspacePage.js b/frontend/playwright/ui/pages/WorkspacePage.js index dd5f66fb04..4037d6dd3e 100644 --- a/frontend/playwright/ui/pages/WorkspacePage.js +++ b/frontend/playwright/ui/pages/WorkspacePage.js @@ -4,6 +4,8 @@ import { MockWebSocketHelper } from "../../helpers/MockWebSocketHelper"; import { BaseWebSocketPage } from "./BaseWebSocketPage"; import { Transit } from "../../helpers/Transit"; +const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + export class WorkspacePage extends BaseWebSocketPage { static TextEditor = class TextEditor { constructor(workspacePage) { @@ -564,6 +566,25 @@ export class WorkspacePage extends BaseWebSocketPage { ).toBeVisible(); } + // Layer rows print the name verbatim, so an anchored text match tells + // "shape - text" from "shape - text - token - composite". It assumes the + // row shows only the name: the :show-ids and :show-touched debug flags + // append text to the same node. Matching by accessible name is not an + // option: a selected row shows its hide and lock buttons, whose titles + // join the name. + layerRow(name) { + return this.layers + .getByTestId("layer-row") + .filter({ hasText: new RegExp(`^${escapeRegExp(name)}$`, "i") }) + .first(); + } + + async selectLayer(name, clickOptions = {}) { + const row = this.layerRow(name); + await row.click(clickOptions); + await expect(row).toHaveAttribute("aria-checked", "true"); + } + async getSelectedShapeName() { const selectedLayer = this.layers .getByRole("checkbox", { checked: true }) @@ -572,11 +593,11 @@ export class WorkspacePage extends BaseWebSocketPage { return (await selectedLayer.innerText()).trim(); } - async waitForSelectedShapeName(expectedName) { + async waitForSelectedShapeName(expectedName, options = {}) { const selectedLayer = this.layers .getByRole("checkbox", { checked: true }) .first(); - await expect(selectedLayer).toHaveText(expectedName); + await expect(selectedLayer).toHaveText(expectedName, options); } async expectHiddenToolbarOptions() { diff --git a/frontend/playwright/ui/specs/inspect-tab.spec.js b/frontend/playwright/ui/specs/inspect-tab.spec.js index 1b1e6362c7..977c58b8e2 100644 --- a/frontend/playwright/ui/specs/inspect-tab.spec.js +++ b/frontend/playwright/ui/specs/inspect-tab.spec.js @@ -27,10 +27,9 @@ const setupFile = async (workspacePage) => { }; const shapeToLayerName = { - flex: "shape - layout - flex", - flexElement: "shape - layout - flex - element", - grid: "shape - layout - grid", - gridElement: "shape - layout - grid - element", + flex: "Shape - layout - flex", + flexElement: "Shape - layout - flex - element", + grid: "Shape - layout - grid", shadow: "shape - shadow - single", shadowMultiple: "shape - shadow - multiple", shadowComposite: "shape - shadow - composite", @@ -46,7 +45,6 @@ const shapeToLayerName = { gradient: "shape - fill - single - gradient", image: "shape - fill - single - image", multiple: "shape - fill - multiple", - style: "shape - fill - style", token: "shape - fill - token", }, stroke: { @@ -54,7 +52,6 @@ const shapeToLayerName = { gradient: "shape - stroke - single - gradient", image: "shape - stroke - single - image", multiple: "shape - stroke - multiple", - style: "shape - stroke - style", token: "shape - stroke - token", }, text: { @@ -103,6 +100,39 @@ const getPanelByTitle = async (workspacePage, title) => { return panel; }; +/** + * Waits for a style panel to render and checks how many property rows it + * shows. Polling keeps the count honest while the panel fills. + * @param {object} panel - The style panel locator + * @param {number} minimum - The minimum number of property rows + */ +const expectPanelRows = async (panel, minimum) => { + await expect(panel).toBeVisible(); + await expect + .poll(() => panel.getByTestId("property-row").count()) + .toBeGreaterThanOrEqual(minimum); +}; + +/** + * Expands a layer row when it is collapsed. The layer tree keeps its state + * across selections, so clicking an already expanded toggle would collapse + * the children the next selection needs. + * @param {WasmWorkspacePage} workspacePage - The workspace page instance + * @param {string} layerName - The name of the layer whose children to show + */ +const expandLayer = async (workspacePage, layerName) => { + const toggle = workspacePage + .layerRow(layerName) + .getByTestId("toggle-content"); + + await expect(toggle).toBeVisible(); + + if ((await toggle.getAttribute("aria-expanded")) !== "true") { + await toggle.click(); + await expect(toggle).toHaveAttribute("aria-expanded", "true"); + } +}; + /** * Selects a layer in the layers panel * @param {WasmWorkspacePage} workspacePage - The workspace page instance @@ -110,26 +140,27 @@ const getPanelByTitle = async (workspacePage, title) => { * @param {string} parentLayerName - The name of the parent layer to expand (optional) */ const selectLayer = async (workspacePage, layerName, parentLayerName) => { - await workspacePage.clickToggableLayer("Board"); + await expandLayer(workspacePage, "Board"); if (parentLayerName) { - await workspacePage.clickToggableLayer(parentLayerName); + await expandLayer(workspacePage, parentLayerName); } - await workspacePage.clickLeafLayer(layerName); - await workspacePage.page.waitForTimeout(500); + + await workspacePage.selectLayer(layerName); }; /** - * Opens the Inspect tab + * Opens the Inspect tab and waits for its panels to render * @param {WasmWorkspacePage} workspacePage - The workspace page instance */ - const openInspectTab = async (workspacePage) => { const inspectButton = workspacePage.page.getByRole("tab", { name: "Inspect", }); await inspectButton.waitFor(); await inspectButton.click(); - await workspacePage.page.waitForTimeout(500); + + const sidebar = workspacePage.page.getByTestId("right-sidebar"); + await expect(sidebar.getByRole("article").first()).toBeVisible(); }; /** @@ -148,644 +179,429 @@ const selectColorSpace = async (workspacePage, colorSpace) => { await colorSpaceOption.click(); }; -test.describe("Inspect tab - Styles", () => { - test.skip("Open Inspect tab", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); +test("Layout and size", async ({ page }) => { + const workspacePage = new WasmWorkspacePage(page); + await setupFile(workspacePage); + await test.step("Flex container", async () => { await selectLayer(workspacePage, shapeToLayerName.flex); await openInspectTab(workspacePage); - const switcherLabel = workspacePage.page.getByText("Layer info", { - exact: true, - }); - await expect(switcherLabel).toBeVisible(); - await expect(switcherLabel).toHaveText("Layer info"); - }); - test.describe("Inspect tab - Flex", () => { - test("Shape Layout Flex ", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); + await expect(page.getByText("Layer info", { exact: true })).toBeVisible(); - await selectLayer(workspacePage, shapeToLayerName.flex); - await openInspectTab(workspacePage); - - const panel = await getPanelByTitle(workspacePage, "Layout"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - }); - - test("Shape Layout Flex Element", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer( - workspacePage, - shapeToLayerName.flexElement, - shapeToLayerName.flex, - ); - await openInspectTab(workspacePage); - - const panel = await getPanelByTitle(workspacePage, "Flex Element"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - }); + const panel = await getPanelByTitle(workspacePage, "Layout"); + await expectPanelRows(panel, 1); }); - test("Shape Layout Grid", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); + await test.step("Flex element", async () => { + await selectLayer( + workspacePage, + shapeToLayerName.flexElement, + shapeToLayerName.flex, + ); + const panel = await getPanelByTitle(workspacePage, "Flex Element"); + await expectPanelRows(panel, 1); + }); + + await test.step("Grid", async () => { await selectLayer(workspacePage, shapeToLayerName.grid); + + const panel = await getPanelByTitle(workspacePage, "Layout"); + await expectPanelRows(panel, 1); + }); + + await test.step("Border radius - individual", async () => { + await selectLayer( + workspacePage, + shapeToLayerName.borderRadius.individual, + shapeToLayerName.borderRadius.main, + ); + + const panel = await getPanelByTitle(workspacePage, "Size and position"); + await expectPanelRows(panel, 2); + + const propertyRow = panel.getByTestId("property-row"); + await expect( + propertyRow.filter({ hasText: "Border start start radius" }), + ).toBeVisible(); + await expect( + propertyRow.filter({ hasText: "Border end end radius" }), + ).toBeVisible(); + }); + + await test.step("Border radius - multiple", async () => { + await selectLayer( + workspacePage, + shapeToLayerName.borderRadius.multiple, + shapeToLayerName.borderRadius.main, + ); + + const panel = await getPanelByTitle(workspacePage, "Size and position"); + await expectPanelRows(panel, 4); + + const propertyRow = panel.getByTestId("property-row"); + await expect( + propertyRow.filter({ hasText: "Border start start radius" }), + ).toBeVisible(); + await expect( + propertyRow.filter({ hasText: "Border start end radius" }), + ).toBeVisible(); + await expect( + propertyRow.filter({ hasText: "Border end end radius" }), + ).toBeVisible(); + await expect( + propertyRow.filter({ hasText: "Border end start radius" }), + ).toBeVisible(); + }); + + await test.step("Border radius - token", async () => { + await selectLayer( + workspacePage, + shapeToLayerName.borderRadius.token, + shapeToLayerName.borderRadius.main, + ); + + const panel = await getPanelByTitle(workspacePage, "Size and position"); + await expectPanelRows(panel, 4); + + const propertyRow = panel.getByTestId("property-row"); + + const borderStartEndRadius = propertyRow.filter({ + hasText: "Border start end radius", + }); + await expect(borderStartEndRadius).toBeVisible(); + await expect(borderStartEndRadius).toContainText("radius-md"); + + const borderEndStartRadius = propertyRow.filter({ + hasText: "Border end start radius", + }); + await expect(borderEndStartRadius).toBeVisible(); + await expect(borderEndStartRadius).toContainText("radius-md"); + }); +}); + +test("Shadow and blur", async ({ page }) => { + const workspacePage = new WasmWorkspacePage(page); + await setupFile(workspacePage); + + await test.step("Single shadow", async () => { + await selectLayer(workspacePage, shapeToLayerName.shadow); + await openInspectTab(workspacePage); + + const panel = await getPanelByTitle(workspacePage, "Shadow"); + await expectPanelRows(panel, 2); + }); + + await test.step("Multiple shadows", async () => { + await selectLayer(workspacePage, shapeToLayerName.shadowMultiple); + + const panel = await getPanelByTitle(workspacePage, "Shadow"); + await expectPanelRows(panel, 4); + }); + + await test.step("Blur", async () => { + await selectLayer(workspacePage, shapeToLayerName.blur); + + const panel = await getPanelByTitle(workspacePage, "Blur"); + await expectPanelRows(panel, 1); + }); +}); + +// The two blur cases below mutate the selected shape with controls that +// live in the Design tab, so they keep a page load of their own. + +test("Shape - Blur on not svg compatible shape", async ({ page }) => { + const workspacePage = new WasmWorkspacePage(page); + await setupFile(workspacePage); + + await selectLayer(workspacePage, shapeToLayerName.blur); + + await workspacePage.page.getByTestId("add-stroke").click(); + await workspacePage.page.getByTestId("stroke.alignment").click(); + await workspacePage.page.getByRole("option", { name: "Center" }).click(); + + await openInspectTab(workspacePage); + + const panel = await getPanelByTitle(workspacePage, "Blur"); + await expectPanelRows(panel, 1); +}); + +test("Shape - Background Blur on not svg compatible shape", async ({ + page, +}) => { + const workspacePage = new WasmWorkspacePage(page); + await setupFile(workspacePage); + + await selectLayer(workspacePage, shapeToLayerName.blur); + + await workspacePage.page + .getByRole("combobox", { name: "Blur type select" }) + .click(); + await workspacePage.page + .getByRole("option", { name: "Background blur" }) + .click(); + await workspacePage.page.getByTestId("add-stroke").click(); + await workspacePage.page.getByTestId("stroke.alignment").click(); + await workspacePage.page.getByRole("option", { name: "Center" }).click(); + + await openInspectTab(workspacePage); + + const panel = await getPanelByTitle(workspacePage, "Blur"); + await expectPanelRows(panel, 1); +}); + +// FIXME: flaky/random (depends on trace ?) +test.skip("Shape Shadow - Composite shadow", async ({ page }) => { + const workspacePage = new WasmWorkspacePage(page); + await setupFile(workspacePage); + + await selectLayer(workspacePage, shapeToLayerName.shadowComposite); + await openInspectTab(workspacePage); + + const panel = await getPanelByTitle(workspacePage, "Shadow"); + await expect(panel).toBeVisible(); + + const propertyRow = panel.getByTestId("property-row"); + await expect.poll(() => propertyRow.count()).toBeGreaterThanOrEqual(3); + + const compositeShadowRow = propertyRow.first(); + await compositeShadowRow.waitFor(); + + await expect(compositeShadowRow).toBeVisible(); + + const compositeShadowTerm = compositeShadowRow.locator("dt"); + + const compositeShadowDefinition = compositeShadowRow.locator("dd"); + + await expect(compositeShadowTerm).toHaveText("Shadow", { exact: true }); + await expect(compositeShadowDefinition).toContainText("shadowToken"); +}); + +test("Fill", async ({ page }) => { + const workspacePage = new WasmWorkspacePage(page); + await setupFile(workspacePage); + + await test.step("Solid", async () => { + await selectLayer(workspacePage, shapeToLayerName.fill.solid); + await openInspectTab(workspacePage); + + const panel = await getPanelByTitle(workspacePage, "Fill"); + await expectPanelRows(panel, 1); + }); + + await test.step("Gradient", async () => { + await selectLayer(workspacePage, shapeToLayerName.fill.gradient); + + const panel = await getPanelByTitle(workspacePage, "Fill"); + await expectPanelRows(panel, 1); + }); + + await test.step("Image", async () => { + await selectLayer(workspacePage, shapeToLayerName.fill.image); + + const panel = await getPanelByTitle(workspacePage, "Fill"); + await expectPanelRows(panel, 1); + + await expect( + panel.getByRole("img", { name: "Preview of the shape's fill" }), + ).toBeVisible(); + }); + + await test.step("Multiple", async () => { + await selectLayer(workspacePage, shapeToLayerName.fill.multiple); + + const panel = await getPanelByTitle(workspacePage, "Fill"); + await expectPanelRows(panel, 3); + + await expect( + panel.getByRole("img", { name: "Preview of the shape's fill" }), + ).toBeVisible(); + }); + + await test.step("Token", async () => { + await selectLayer(workspacePage, shapeToLayerName.fill.token); + + const panel = await getPanelByTitle(workspacePage, "Fill"); + await expectPanelRows(panel, 1); + + const backgroundRow = panel + .getByTestId("property-row") + .filter({ hasText: "Background" }); + await expect(backgroundRow).toContainText("primary"); + await expect(backgroundRow).toBeVisible(); + }); +}); + +test("Copy and colour space", async ({ page }) => { + const workspacePage = new WasmWorkspacePage(page); + await setupFile(workspacePage); + + await test.step("Copy one property", async () => { + await selectLayer(workspacePage, shapeToLayerName.flex); await openInspectTab(workspacePage); const panel = await getPanelByTitle(workspacePage, "Layout"); - await expect(panel).toBeVisible(); + await expectPanelRows(panel, 1); - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); + await copyPropertyFromPropertyRow(panel, "Display"); - expect(propertyRowCount).toBeGreaterThanOrEqual(1); + const shorthand = await page.evaluate(() => navigator.clipboard.readText()); + expect(shorthand).toBe("display: flex;"); }); - test.describe("Inspect tab - Shadow", () => { - test("Shape Shadow - Single shadow", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); + await test.step("Copy the shorthand", async () => { + await selectLayer(workspacePage, shapeToLayerName.shadow); - await selectLayer(workspacePage, shapeToLayerName.shadow); - await openInspectTab(workspacePage); + const panel = await getPanelByTitle(workspacePage, "Shadow"); + await expectPanelRows(panel, 2); - const panel = await getPanelByTitle(workspacePage, "Shadow"); - await expect(panel).toBeVisible(); + await copyShorthand(panel); - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(2); - }); - - test("Shape Shadow - Multiple shadow", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.shadowMultiple); - await openInspectTab(workspacePage); - - const panel = await getPanelByTitle(workspacePage, "Shadow"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(4); - }); - - // FIXME: flaky/random (depends on trace ?) - test.skip("Shape Shadow - Composite shadow", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.shadowComposite); - await openInspectTab(workspacePage); - - const panel = await getPanelByTitle(workspacePage, "Shadow"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(3); - - const compositeShadowRow = propertyRow.first(); - await compositeShadowRow.waitFor(); - - await expect(compositeShadowRow).toBeVisible(); - - const compositeShadowTerm = compositeShadowRow.locator("dt"); - - const compositeShadowDefinition = compositeShadowRow.locator("dd"); - - expect(compositeShadowTerm).toHaveText("Shadow", { exact: true }); - expect(compositeShadowDefinition).toContainText("shadowToken"); - }); + const shorthand = await page.evaluate(() => navigator.clipboard.readText()); + expect(shorthand).toBe("box-shadow: 4px 4px 4px 0px #00000033;"); }); - test("Shape - Blur", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.blur); - - await openInspectTab(workspacePage); - - const panel = await getPanelByTitle(workspacePage, "Blur"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - }); - - test("Shape - Blur on not svg compatible shape", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.blur); - - await workspacePage.page.getByTestId("add-stroke").click(); - await workspacePage.page.getByTestId("stroke.alignment").click(); - await workspacePage.page.getByRole("option", { name: "Center" }).click(); - - await openInspectTab(workspacePage); - - const panel = await getPanelByTitle(workspacePage, "Blur"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - }); - - test("Shape - Background Blur on not svg compatible shape", async ({ - page, - }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.blur); - - await workspacePage.page.getByRole('combobox', { name: 'Blur type select' }).click(); - await workspacePage.page.getByRole('option', { name: 'Background blur' }).click(); - await workspacePage.page.getByTestId("add-stroke").click(); - await workspacePage.page.getByTestId("stroke.alignment").click(); - await workspacePage.page.getByRole("option", { name: "Center" }).click(); - - await openInspectTab(workspacePage); - - const panel = await getPanelByTitle(workspacePage, "Blur"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - }); - - test.describe("Inspect tab - Border radius", () => { - test("Shape - Border radius - individual", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer( - workspacePage, - shapeToLayerName.borderRadius.individual, - shapeToLayerName.borderRadius.main, - ); - await openInspectTab(workspacePage); - - const panel = await getPanelByTitle(workspacePage, "Size and position"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(2); - - const borderStartStartRadius = propertyRow.filter({ - hasText: "Border start start radius", - }); - await expect(borderStartStartRadius).toBeVisible(); - - const borderEndEndRadius = propertyRow.filter({ - hasText: "Border end end radius", - }); - await expect(borderEndEndRadius).toBeVisible(); - }); - - test("Shape - Border radius - multiple", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer( - workspacePage, - shapeToLayerName.borderRadius.multiple, - shapeToLayerName.borderRadius.main, - ); - await openInspectTab(workspacePage); - - const panel = await getPanelByTitle(workspacePage, "Size and position"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(4); - - const borderStartStartRadius = propertyRow.filter({ - hasText: "Border start start radius", - }); - await expect(borderStartStartRadius).toBeVisible(); - - const borderStartEndRadius = propertyRow.filter({ - hasText: "Border start end radius", - }); - await expect(borderStartEndRadius).toBeVisible(); - - const borderEndEndRadius = propertyRow.filter({ - hasText: "Border end end radius", - }); - await expect(borderEndEndRadius).toBeVisible(); - - const borderEndStartRadius = propertyRow.filter({ - hasText: "Border end start radius", - }); - await expect(borderEndStartRadius).toBeVisible(); - }); - - test("Shape - Border radius - token", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer( - workspacePage, - shapeToLayerName.borderRadius.token, - shapeToLayerName.borderRadius.main, - ); - await openInspectTab(workspacePage); - - const panel = await getPanelByTitle(workspacePage, "Size and position"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(4); - - const borderStartEndRadius = propertyRow.filter({ - hasText: "Border start end radius", - }); - await expect(borderStartEndRadius).toBeVisible(); - expect(borderStartEndRadius).toContainText("radius"); - - const borderEndStartRadius = propertyRow.filter({ - hasText: "Border end start radius", - }); - expect(borderEndStartRadius).toContainText("radius"); - await expect(borderEndStartRadius).toBeVisible(); - }); - }); - - test.describe("Inspect tab - Fill", () => { - test("Shape - Fill - Solid", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.fill.solid); - await openInspectTab(workspacePage); - const panel = await getPanelByTitle(workspacePage, "Fill"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - }); - - test("Change color space and ensure fill and shorthand changes", async ({ - page, - }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.fill.solid); - await openInspectTab(workspacePage); - const panel = await getPanelByTitle(workspacePage, "Fill"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const backgroundRow = propertyRow.filter({ - hasText: "Background", - }); - await expect(backgroundRow).toBeVisible(); - - // Ensure initial value and copied value are in HEX format - expect(backgroundRow).toContainText("#0438d5 100%"); - - await copyPropertyFromPropertyRow(panel, "Background"); - - const backgroundHEX = await page.evaluate(() => - navigator.clipboard.readText(), - ); - expect(backgroundHEX).toContain("background: #0438d5FF;"); - - // Change color space to RGBA - await selectColorSpace(workspacePage, "rgba"); - - // Ensure new value and copied value are in RGBA format - expect(backgroundRow).toContainText("4, 56, 213, 1"); - - await copyPropertyFromPropertyRow(panel, "Background"); - const backgroundRGBA = await page.evaluate(() => - navigator.clipboard.readText(), - ); - expect(backgroundRGBA).toContain("background: rgba(4, 56, 213, 1);"); - }); - - test("Shape - Fill - Gradient", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.fill.gradient); - await openInspectTab(workspacePage); - const panel = await getPanelByTitle(workspacePage, "Fill"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - }); - - test("Shape - Fill - Image", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.fill.image); - await openInspectTab(workspacePage); - const panel = await getPanelByTitle(workspacePage, "Fill"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - - const imagePreview = panel.getByRole("img", { - name: "Preview of the shape's fill", - }); - await expect(imagePreview).toBeVisible(); - }); - - test("Shape - Fill - Multiple", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.fill.multiple); - await openInspectTab(workspacePage); - const panel = await getPanelByTitle(workspacePage, "Fill"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(3); - - const imagePreview = panel.getByRole("img", { - name: "Preview of the shape's fill", - }); - await expect(imagePreview).toBeVisible(); - }); - - test("Shape - Fill - Token", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.fill.token); - await openInspectTab(workspacePage); - const panel = await getPanelByTitle(workspacePage, "Fill"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - - const fillToken = propertyRow.filter({ - hasText: "Background", - }); - expect(fillToken).toContainText("primary"); - await expect(fillToken).toBeVisible(); - }); - }); - - test.describe("Inspect tab - Stroke", () => { - test("Shape - Stroke - Solid", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.stroke.solid); - await openInspectTab(workspacePage); - const panel = await getPanelByTitle(workspacePage, "Stroke"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - }); - - test("Shape - Stroke - Gradient", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.stroke.gradient); - await openInspectTab(workspacePage); - const panel = await getPanelByTitle(workspacePage, "Stroke"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - }); - - test("Shape - Stroke - Image", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.stroke.image); - await openInspectTab(workspacePage); - const panel = await getPanelByTitle(workspacePage, "Stroke"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - - const imagePreview = panel.getByRole("img", { - name: "Preview of the shape's fill", - }); - await expect(imagePreview).toBeVisible(); - }); - - test("Shape - Stroke - Multiple", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.stroke.multiple); - await openInspectTab(workspacePage); - const panel = await getPanelByTitle(workspacePage, "Stroke"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(3); - - const imagePreview = panel.getByRole("img", { - name: "Preview of the shape's fill", - }); - await expect(imagePreview).toBeVisible(); - }); - - test("Shape - Stroke - Token", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.stroke.token); - await openInspectTab(workspacePage); - const panel = await getPanelByTitle(workspacePage, "Stroke"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - - const fillToken = propertyRow.filter({ - hasText: "Border color", - }); - expect(fillToken).toContainText("primary"); - await expect(fillToken).toBeVisible(); - }); - }); - - test.describe("Inspect tab - Typography", () => { - test("Text - simple", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.text.simple); - await openInspectTab(workspacePage); - const panel = await getPanelByTitle(workspacePage, "Text"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - - const textPreview = panel.getByRole("presentation"); - await expect(textPreview).toBeVisible(); - }); - - test("Text - token", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.text.token); - await openInspectTab(workspacePage); - const panel = await getPanelByTitle(workspacePage, "Text"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - - // Test with multiple tokens - const fontFamilyToken = propertyRow.filter({ - hasText: "Font family", - }); - await expect(fontFamilyToken).toBeVisible(); - expect(fontFamilyToken).toContainText("font.sans"); - - const fontSizeToken = propertyRow.filter({ - hasText: "Font size", - }); - await expect(fontSizeToken).toBeVisible(); - expect(fontSizeToken).toContainText("medium"); - - const fontWeightToken = propertyRow.filter({ - hasText: "Font weight", - }); - await expect(fontWeightToken).toBeVisible(); - expect(fontWeightToken).toContainText("bold"); - - const textPreview = panel.getByRole("presentation"); - await expect(textPreview).toBeVisible(); - }); - test("Text - composite token", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.text.compositeToken); - await openInspectTab(workspacePage); - const panel = await getPanelByTitle(workspacePage, "Text"); - await expect(panel).toBeVisible(); - - const propertyRow = panel.getByTestId("property-row"); - const propertyRowCount = await propertyRow.count(); - - expect(propertyRowCount).toBeGreaterThanOrEqual(1); - - const compositeTypographyRow = propertyRow.filter({ - hasText: "Typography", - }); - await expect(compositeTypographyRow).toBeVisible(); - expect(compositeTypographyRow).toContainText("body"); - - const textPreview = panel.getByRole("presentation"); - await expect(textPreview).toBeVisible(); - }); - }); - - test.describe("Copy properties", () => { - test("Copy single property", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.flex); - await openInspectTab(workspacePage); - - const panel = await getPanelByTitle(workspacePage, "Layout"); - await expect(panel).toBeVisible(); - - await copyPropertyFromPropertyRow(panel, "Display"); - - const shorthand = await page.evaluate(() => - navigator.clipboard.readText(), - ); - expect(shorthand).toBe("display: flex;"); - }); - test("Copy shorthand - multiple properties", async ({ page }) => { - const workspacePage = new WasmWorkspacePage(page); - await setupFile(workspacePage); - - await selectLayer(workspacePage, shapeToLayerName.shadow); - await openInspectTab(workspacePage); - - const panel = await getPanelByTitle(workspacePage, "Shadow"); - await expect(panel).toBeVisible(); - - await copyShorthand(panel); - - const shorthand = await page.evaluate(() => - navigator.clipboard.readText(), - ); - expect(shorthand).toBe("box-shadow: 4px 4px 4px 0px #00000033;"); - }); + // The colour space is a view setting for the sidebar, so the step that + // changes it runs last. + await test.step("Colour space changes the value and the copy", async () => { + await selectLayer(workspacePage, shapeToLayerName.fill.solid); + + const panel = await getPanelByTitle(workspacePage, "Fill"); + await expectPanelRows(panel, 1); + + const backgroundRow = panel + .getByTestId("property-row") + .filter({ hasText: "Background" }); + await expect(backgroundRow).toContainText("#0438d5 100%"); + + await copyPropertyFromPropertyRow(panel, "Background"); + const backgroundHEX = await page.evaluate(() => + navigator.clipboard.readText(), + ); + expect(backgroundHEX).toContain("background: #0438d5FF;"); + + await selectColorSpace(workspacePage, "rgba"); + + await expect(backgroundRow).toContainText("4, 56, 213, 1"); + + await copyPropertyFromPropertyRow(panel, "Background"); + const backgroundRGBA = await page.evaluate(() => + navigator.clipboard.readText(), + ); + expect(backgroundRGBA).toContain("background: rgba(4, 56, 213, 1);"); + }); +}); + +test("Stroke", async ({ page }) => { + const workspacePage = new WasmWorkspacePage(page); + await setupFile(workspacePage); + + await test.step("Solid", async () => { + await selectLayer(workspacePage, shapeToLayerName.stroke.solid); + await openInspectTab(workspacePage); + + const panel = await getPanelByTitle(workspacePage, "Stroke"); + await expectPanelRows(panel, 1); + }); + + await test.step("Gradient", async () => { + await selectLayer(workspacePage, shapeToLayerName.stroke.gradient); + + const panel = await getPanelByTitle(workspacePage, "Stroke"); + await expectPanelRows(panel, 1); + }); + + await test.step("Image", async () => { + await selectLayer(workspacePage, shapeToLayerName.stroke.image); + + const panel = await getPanelByTitle(workspacePage, "Stroke"); + await expectPanelRows(panel, 1); + + await expect( + panel.getByRole("img", { name: "Preview of the shape's fill" }), + ).toBeVisible(); + }); + + await test.step("Multiple", async () => { + await selectLayer(workspacePage, shapeToLayerName.stroke.multiple); + + const panel = await getPanelByTitle(workspacePage, "Stroke"); + await expectPanelRows(panel, 3); + + await expect( + panel.getByRole("img", { name: "Preview of the shape's fill" }), + ).toBeVisible(); + }); + + await test.step("Token", async () => { + await selectLayer(workspacePage, shapeToLayerName.stroke.token); + + const panel = await getPanelByTitle(workspacePage, "Stroke"); + await expectPanelRows(panel, 1); + + const borderColorRow = panel + .getByTestId("property-row") + .filter({ hasText: "Border color" }); + await expect(borderColorRow).toContainText("primary"); + await expect(borderColorRow).toBeVisible(); + }); +}); + +test("Typography", async ({ page }) => { + const workspacePage = new WasmWorkspacePage(page); + await setupFile(workspacePage); + + await test.step("Simple text", async () => { + await selectLayer(workspacePage, shapeToLayerName.text.simple); + await openInspectTab(workspacePage); + + const panel = await getPanelByTitle(workspacePage, "Text"); + await expectPanelRows(panel, 1); + await expect(panel.getByRole("presentation")).toBeVisible(); + }); + + await test.step("Tokens", async () => { + await selectLayer(workspacePage, shapeToLayerName.text.token); + + const panel = await getPanelByTitle(workspacePage, "Text"); + await expectPanelRows(panel, 1); + + const propertyRow = panel.getByTestId("property-row"); + + const fontFamilyToken = propertyRow.filter({ + hasText: "Font family", + }); + await expect(fontFamilyToken).toBeVisible(); + await expect(fontFamilyToken).toContainText("font.sans"); + + const fontSizeToken = propertyRow.filter({ + hasText: "Font size", + }); + await expect(fontSizeToken).toBeVisible(); + await expect(fontSizeToken).toContainText("medium"); + + const fontWeightToken = propertyRow.filter({ + hasText: "Font weight", + }); + await expect(fontWeightToken).toBeVisible(); + await expect(fontWeightToken).toContainText("bold"); + + await expect(panel.getByRole("presentation")).toBeVisible(); + }); + + await test.step("Composite token", async () => { + await selectLayer(workspacePage, shapeToLayerName.text.compositeToken); + + const panel = await getPanelByTitle(workspacePage, "Text"); + await expectPanelRows(panel, 1); + + const compositeTypographyRow = panel + .getByTestId("property-row") + .filter({ hasText: "Typography" }); + await expect(compositeTypographyRow).toBeVisible(); + await expect(compositeTypographyRow).toContainText("body"); + + await expect(panel.getByRole("presentation")).toBeVisible(); }); }); diff --git a/frontend/playwright/ui/specs/shortcuts.spec.js b/frontend/playwright/ui/specs/shortcuts.spec.js index e20e97b3fe..0d7b148c5d 100644 --- a/frontend/playwright/ui/specs/shortcuts.spec.js +++ b/frontend/playwright/ui/specs/shortcuts.spec.js @@ -1,232 +1,167 @@ import { test, expect } from "@playwright/test"; import ShortcutsPage from "../pages/ShortcutsPage"; -const customShortcutsFlag = "enable-custom-shortcuts"; +// The import and reset rules are unit-tested in +// frontend/test/frontend_tests/ui/settings_shortcuts_test.cljs (77 tests): +// validation, sanitising, the command grammar, reserved combinations, the +// profile merge, the diff modal and the restore modal. What remains here is +// the wiring only a browser proves: the file input, the diff modal, the RPC +// write, the download, the alert, the reload and the reset flows. test.beforeEach(async ({ page }) => { await ShortcutsPage.init(page); - await ShortcutsPage.mockConfigFlags(page, [customShortcutsFlag]); }); -test.describe("Shortcuts Settings Page", () => { - test("Shortcuts page loads correctly", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); +test("Import valid custom shortcuts", async ({ page }) => { + const shortcutsPage = new ShortcutsPage(page); + await shortcutsPage.goToShortcuts(); - await expect(shortcutsPage.shortcutsSection).toBeVisible(); - await expect(shortcutsPage.searchInput).toBeVisible(); + await shortcutsPage.importShortcuts({ + workspace: { "align-bottom": "ctrl+y" }, }); - test("Tabs are visible and clickable", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); + await shortcutsPage.confirmImportApply(); - await expect(shortcutsPage.allTab).toBeVisible(); - await expect(shortcutsPage.personalizedTab).toBeVisible(); - await expect(shortcutsPage.disabledTab).toBeVisible(); + await shortcutsPage.expectShortcutCustomized("Align bottom"); - await shortcutsPage.clickTab("Custom"); - await expect(shortcutsPage.personalizedTab).toHaveAttribute( - "aria-selected", - "true", - ); - const personalizedPlacehonder = page.getByText(/No custom shortcuts yet/i); - await expect(personalizedPlacehonder).toBeVisible(); - - await shortcutsPage.clickTab("Disabled"); - await expect(shortcutsPage.disabledTab).toHaveAttribute( - "aria-selected", - "true", - ); - const disabledPlaceholder = page.getByText(/No disabled shortcuts/i); - await expect(disabledPlaceholder).toBeVisible(); - - await shortcutsPage.clickTab("All"); - await expect(shortcutsPage.allTab).toHaveAttribute("aria-selected", "true"); - }); + await shortcutsPage.clickTab("Custom"); + await shortcutsPage.searchForShortcut("Align bottom"); + await shortcutsPage.expectShortcutVisible("Align bottom"); }); -test.describe("Shortcut Customization", () => { - test("User can edit a shortcut", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); +test("A file with nothing to apply shows the alert", async ({ page }) => { + const shortcutsPage = new ShortcutsPage(page); + await shortcutsPage.goToShortcuts(); - // Expand subsection - await shortcutsPage.expandSubsection("Alignment"); - - // Start edition of the shortcut - await shortcutsPage.clickEditShortcut("Align bottom"); - - // Press a new key combination - await shortcutsPage.pressKey("Control+y"); - - // Save the shortcut - await shortcutsPage.saveShortcut(); - - // Verify the shortcut is now customized - await shortcutsPage.expectShortcutCustomized("Align bottom"); - }); -}); - -test.describe("Shortcut Import", () => { - test("Import valid custom shortcuts", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); - - await shortcutsPage.importShortcuts({ - workspace: { "align-bottom": "ctrl+y" }, - }); - - await shortcutsPage.confirmImportApply(); - - await shortcutsPage.expectShortcutCustomized("Align bottom"); - - await shortcutsPage.clickTab("Custom"); - await shortcutsPage.searchForShortcut("Align bottom"); - await shortcutsPage.expectShortcutVisible("Align bottom"); - }); - - test("Import invalid JSON syntax", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); + const alert = page + .getByRole("alert") + .filter({ hasText: /not a valid shortcuts export/i }); + await test.step("Broken JSON does not parse", async () => { await shortcutsPage.importShortcutsRaw("{invalid"); + await expect(alert).toBeVisible(); - await expect( - page - .getByRole("alert") - .filter({ hasText: /not a valid shortcuts export/i }), - ).toBeVisible(); + // The error toast carries no timeout: it stays until another + // notification replaces it or the route changes, so it has to go before + // the next import can prove anything. + await alert.getByRole("button", { name: "Close" }).click(); + await expect(alert).toBeHidden(); }); - test("Import valid JSON with invalid schema", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); - + await test.step("A parsed file with no applicable entry is rejected", async () => { await shortcutsPage.importShortcuts({ - workspace: { "unknown-shortcut": "ctrl+y" }, - }); - - await expect( - page - .getByRole("alert") - .filter({ hasText: /not a valid shortcuts export/i }), - ).toBeVisible(); - }); - - test("Import JSON without workspace context accepted", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); - - await shortcutsPage.importShortcuts({ - dashboard: { "toggle-theme": "alt+m" }, - }); - - await shortcutsPage.confirmImportApply(); - - await expect( - page - .getByRole("alert") - .filter({ hasText: /not a valid shortcuts export/i }), - ).not.toBeVisible(); - }); - - test("Import JSON with unsupported shortcut format", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); - - await shortcutsPage.importShortcuts({ - workspace: { escape: 123 }, - }); - - await expect( - page - .getByRole("alert") - .filter({ hasText: /not a valid shortcuts export/i }), - ).toBeVisible(); - }); - - test("Import conflicting shortcuts", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); - - await shortcutsPage.importShortcuts({ - workspace: { - "align-bottom": "alt+a", - }, - }); - - await shortcutsPage.confirmImportApply(); - - await shortcutsPage.expectShortcutCustomized("Align bottom"); - - await shortcutsPage.expandSubsection("Alignment"); - await shortcutsPage.expectShortcutDisabled("Align left"); - - const exported = await shortcutsPage.getExportedJson(); - expect(exported.workspace).toMatchObject({ - "align-bottom": "alt+a", - "align-left": "", + workspace: { "unknown-shortcut": "ctrl+y", "align-bottom": 123 }, }); + await expect(alert).toBeVisible(); }); }); -test.describe("Shortcut Export", () => { - test("Export customized shortcuts", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); +test("Export includes customized and disabled shortcuts and imports back", async ({ + page, +}) => { + const shortcutsPage = new ShortcutsPage(page); + await shortcutsPage.goToShortcuts(); + await shortcutsPage.expandSubsection("Alignment"); + await shortcutsPage.importShortcuts({ + workspace: { + "align-bottom": "ctrl+y", + "align-left": "", + }, + }); + + await shortcutsPage.confirmImportApply(); + await shortcutsPage.expectShortcutCustomized("Align bottom"); + + const exported = await shortcutsPage.getExportedJson(); + expect(exported.workspace).toMatchObject({ + "align-bottom": "ctrl+y", + "align-left": "", + }); + + // The file the page wrote must pass the importer's own validation. + await shortcutsPage.restoreAllShortcuts(); + await shortcutsPage.expectShortcutNotCustomized("Align bottom"); + + await shortcutsPage.importShortcuts(exported); + await shortcutsPage.confirmImportApply(); + + await shortcutsPage.expectShortcutCustomized("Align bottom"); + await shortcutsPage.expectShortcutDisabled("Align left"); +}); + +test("Custom shortcuts persist after reload and cancelled edits do not", async ({ + page, +}) => { + const shortcutsPage = new ShortcutsPage(page); + await shortcutsPage.goToShortcuts(); + + await test.step("A cancelled edit is not saved", async () => { await shortcutsPage.expandSubsection("Alignment"); + await shortcutsPage.clickEditShortcut("Align left"); + await shortcutsPage.pressKey("Control+i"); + await shortcutsPage.cancelEdit(); + + await shortcutsPage.expectShortcutNotCustomized("Align left"); + }); + + await test.step("A saved edit survives the reload", async () => { await shortcutsPage.clickEditShortcut("Align bottom"); await shortcutsPage.pressKey("Control+y"); await shortcutsPage.saveShortcut(); await shortcutsPage.expectShortcutCustomized("Align bottom"); - const exported = await shortcutsPage.getExportedJson(); - expect(exported).toHaveProperty("workspace"); - expect(exported.workspace).toMatchObject({ - "align-bottom": "ctrl+y", - }); - }); - - test("Export includes disabled shortcuts", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); + await page.reload(); await shortcutsPage.goToShortcuts(); - await shortcutsPage.importShortcuts({ - workspace: { "align-bottom": "" }, - }); - - await shortcutsPage.confirmImportApply(); - - await shortcutsPage.searchForShortcut("Align bottom"); - await shortcutsPage.expectShortcutDisabled("Align bottom"); - - const exported = await shortcutsPage.getExportedJson(); - expect(exported.workspace).toMatchObject({ - "align-bottom": "", - }); + await shortcutsPage.expectShortcutCustomized("Align bottom"); + await shortcutsPage.expectShortcutNotCustomized("Align left"); }); }); -test.describe("Shortcut Conflict Detection", () => { - test("Detects conflict and disables old shortcut on save", async ({ - page, - }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); +test("Detects conflicts on edit and on import", async ({ page }) => { + const shortcutsPage = new ShortcutsPage(page); + await shortcutsPage.goToShortcuts(); + await shortcutsPage.expandSubsection("Alignment"); - await shortcutsPage.expandSubsection("Alignment"); + const conflictAlert = page + .getByRole("alert") + .filter({ hasText: /Already assigned to/i }); + + await test.step("Conflict with a default binding", async () => { await shortcutsPage.clickEditShortcut("Align bottom"); await shortcutsPage.pressKey("Alt+a"); - - await expect( - page.getByRole("alert").filter({ hasText: /Already assigned to/i }), - ).toBeVisible(); + await expect(conflictAlert).toBeVisible(); await shortcutsPage.saveShortcut(); await shortcutsPage.expectShortcutCustomized("Align bottom"); await shortcutsPage.expectShortcutDisabled("Align left"); + }); + + // Align bottom now holds alt+a as a custom binding. + await test.step("Conflict with a custom binding", async () => { + await shortcutsPage.clickEditShortcut("Align left"); + await shortcutsPage.pressKey("Alt+a"); + await expect(conflictAlert).toBeVisible(); + + await shortcutsPage.saveShortcut(); + await shortcutsPage.expectShortcutCustomized("Align left"); + await shortcutsPage.expectShortcutDisabled("Align bottom"); + }); + + // The importer disables the default binding a file takes over, so this + // runs the diff modal's apply path with a default binding in the way. + await test.step("Import takes a key a default binding holds", async () => { + await shortcutsPage.restoreAllShortcuts(); + await shortcutsPage.expectShortcutNotCustomized("Align bottom"); + + await shortcutsPage.importShortcuts({ + workspace: { "align-bottom": "alt+a" }, + }); + await shortcutsPage.confirmImportApply(); + + await shortcutsPage.expectShortcutCustomized("Align bottom"); + await shortcutsPage.expectShortcutDisabled("Align left"); const exported = await shortcutsPage.getExportedJson(); expect(exported.workspace).toMatchObject({ @@ -236,11 +171,13 @@ test.describe("Shortcut Conflict Detection", () => { }); }); -test.describe("Shortcut Reset", () => { - test("Reset after import restores defaults", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); +test("Reset restores defaults and empty tabs show their placeholders", async ({ + page, +}) => { + const shortcutsPage = new ShortcutsPage(page); + await shortcutsPage.goToShortcuts(); + await test.step("Reset all restores the defaults", async () => { await shortcutsPage.importShortcuts({ workspace: { "align-bottom": "ctrl+y" }, }); @@ -248,15 +185,30 @@ test.describe("Shortcut Reset", () => { await shortcutsPage.expectShortcutCustomized("Align bottom"); await shortcutsPage.restoreAllShortcuts(); + await shortcutsPage.expectShortcutNotCustomized("Align bottom"); }); - test("Reset button shows pending message and requires save to apply", async ({ - page, - }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); + await test.step("Empty tabs show their placeholders", async () => { + await shortcutsPage.clickTab("Custom"); + await expect(shortcutsPage.personalizedTab).toHaveAttribute( + "aria-selected", + "true", + ); + await expect(page.getByText(/No custom shortcuts yet/i)).toBeVisible(); + await shortcutsPage.clickTab("Disabled"); + await expect(shortcutsPage.disabledTab).toHaveAttribute( + "aria-selected", + "true", + ); + await expect(page.getByText(/No disabled shortcuts/i)).toBeVisible(); + + await shortcutsPage.clickTab("All"); + await expect(shortcutsPage.allTab).toHaveAttribute("aria-selected", "true"); + }); + + await test.step("A single reset waits for the save", async () => { await shortcutsPage.expandSubsection("Alignment"); await shortcutsPage.clickEditShortcut("Align bottom"); await shortcutsPage.pressKey("Control+y"); @@ -270,96 +222,11 @@ test.describe("Shortcut Reset", () => { page.getByText(/Saving will reset this shortcut/i), ).toBeVisible(); + // The reset is pending: it only lands with the save. + await shortcutsPage.expectShortcutCustomized("Align bottom"); + await shortcutsPage.saveShortcut(); await shortcutsPage.expectShortcutNotCustomized("Align bottom"); }); }); - -test.describe("Shortcut Persistence", () => { - test("Custom shortcuts persist after reload", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); - - await shortcutsPage.expandSubsection("Alignment"); - await shortcutsPage.clickEditShortcut("Align bottom"); - await shortcutsPage.pressKey("Control+y"); - await shortcutsPage.saveShortcut(); - await shortcutsPage.expectShortcutCustomized("Align bottom"); - - await page.reload(); - await shortcutsPage.goToShortcuts(); - await shortcutsPage.expectShortcutCustomized("Align bottom"); - }); -}); - -test.describe("Cancel Shortcut Editing", () => { - test("Cancel editing does not save changes", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); - - await shortcutsPage.expandSubsection("Alignment"); - await shortcutsPage.clickEditShortcut("Align bottom"); - await shortcutsPage.pressKey("Control+y"); - await shortcutsPage.cancelEdit(); - - await shortcutsPage.expectShortcutNotCustomized("Align bottom"); - }); -}); - -test.describe("Duplicate Shortcut Prevention", () => { - test("Assigning same shortcut to two actions shows conflict and disables first", async ({ - page, - }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); - - await shortcutsPage.expandSubsection("Alignment"); - - await shortcutsPage.clickEditShortcut("Align bottom"); - await shortcutsPage.pressKey("Control+y"); - await shortcutsPage.saveShortcut(); - await shortcutsPage.expectShortcutCustomized("Align bottom"); - - await shortcutsPage.clickEditShortcut("Align left"); - await shortcutsPage.pressKey("Control+y"); - - await expect( - page.getByRole("alert").filter({ hasText: /Already assigned to/i }), - ).toBeVisible(); - - await shortcutsPage.saveShortcut(); - await shortcutsPage.expectShortcutCustomized("Align left"); - - const exported = await shortcutsPage.getExportedJson(); - expect(exported.workspace).toMatchObject({ - "align-left": "ctrl+y", - "align-bottom": "", - }); - }); -}); - -test.describe("Shortcut Round-Trip", () => { - test("Export, reset, import restores configuration", async ({ page }) => { - const shortcutsPage = new ShortcutsPage(page); - await shortcutsPage.goToShortcuts(); - - await shortcutsPage.expandSubsection("Alignment"); - await shortcutsPage.clickEditShortcut("Align bottom"); - await shortcutsPage.pressKey("Control+y"); - await shortcutsPage.saveShortcut(); - await shortcutsPage.expectShortcutCustomized("Align bottom"); - - const exported = await shortcutsPage.getExportedJson(); - - await shortcutsPage.restoreAllShortcuts(); - await shortcutsPage.expectShortcutNotCustomized("Align bottom"); - - await shortcutsPage.importShortcuts(exported); - await shortcutsPage.confirmImportApply(); - await shortcutsPage.expectShortcutCustomized("Align bottom"); - - const reExported = await shortcutsPage.getExportedJson(); - expect(reExported).toEqual(exported); - }); -}); diff --git a/frontend/test/frontend_tests/data/workspace_sync_text_wasm_test.cljs b/frontend/test/frontend_tests/data/workspace_sync_text_wasm_test.cljs index dcb5a60c60..7d107d6462 100644 --- a/frontend/test/frontend_tests/data/workspace_sync_text_wasm_test.cljs +++ b/frontend/test/frontend_tests/data/workspace_sync_text_wasm_test.cljs @@ -198,7 +198,8 @@ (conj (dwu/append-undo {:undo-changes undo :redo-changes redo :undo-group edit-group - :tags #{}} + :tags #{} + :translation false} false)) :always