penpot/frontend/playwright/ui/specs/multiseleccion.spec.js
Andrey Antukh 52750d14de
♻️ Reduce the frontend e2e suite by merging equivalent specs (#13094)
* ♻️ Merge duplicated e2e loads and harden ten spec groups

Collapse multi-case Playwright specs into one test with a named step per
case, so the app or document loads once per group instead of once per
case. No case is dropped. In scope, the affected cases fall from 85 to
52 tests and from about 1300 to 760 worker-seconds.

- stroke-to-path and toolbar (15 to 2 tests, -80%): each step anchors a
  layer row to its exact name, checks the count grows by one and that the
  clicked row is selected before the context menu. The skipped path case
  now uses the tool's click-per-node and Enter gesture. The curve step
  counts exact Path rows; the update-file override that returned a whole
  file is gone; the toolbar test runs on the DOM renderer because the
  prebuilt WASM bundle creates no text.
- dimension tokens and colorpicker (12 to 6, -45%): steps assert the
  resolved pill value, not just the pill; the width/height step detaches
  the extra pill. HSB now awaits isVisible on real labels, gradient steps
  count stops and the radial case switches its own type.
- export frames and multiselection (11 to 3, -70%): rows use aria-checked
  instead of a 500 ms sleep, and steps wait for the sidebar before editing
  so a stale render cannot write to the previous selection. The frames
  entry is checked by row count and the "file" item by id.
- variants and workspace (41 to 37, -29%): waits now follow rendered
  state, the duplicated setupEmptyFile is gone, and the layer tree derives
  its children container from the row's own id. The copy/paste flake is
  fixed with a selectRow retry, Escape to deselect, hover instead of
  clicks and idempotent container expansion.
- grid editor and sidebar scroll (6 to 4, -24%): the editor opens once and
  blind 200/500 ms waits are gone; hover checks computed opacity because
  the button is hidden with opacity: 0. Only the second scroll test stays;
  the store has nine unit tests in ui/sidebar_scroll_test.cljs.

Also drop a dead binding, restore two Taiga links and fix comments that
cited the wrong drawing.cljs ranges and cancel-drawing's docstring.

AI-assisted-by: deepseek-v4.1-flash

* ♻️ Close the e2e merge review findings

Restore the renderer coverage the merge lost and make the merged steps
measure their own work.

The five shape tools run under WASM again, and the text tool runs there
too with the v2 editor flag: WasmWorkspacePage already enables it, so
the toolbar gesture keeps its drag and typing assertions. Curve now
compares the exact Path rows with their own baseline.

WorkspacePage gains layerRows, and layerRow delegates to it; toolbar,
stroke-to-path and export-frames use them instead of local copies. The
variants setup waits for the component icon and the variant rows
instead of two fixed sleeps, selectRow clicks once, and the cut/paste
step asserts its own delta. The stale comments lose their line numbers,
Path is no longer called the pencil, the orphan fixture is deleted, and
the sidebar smoke regains the Assets round trip.

Document the local e2e bundle prerequisite in the frontend testing
memory.

Closes #13093

AI-assisted-by: deepseek-v4.1-flash

* 🐛 Wait for the layer selection in the token spec

The dimension-token test clicked a layer row and went back to the Tokens
tab without proving the selection. A lost click left the previous shape
selected, and the border-radius step could pass on that shape. The
selection now goes through WorkspacePage.selectRow, which clicks once and
waits for aria-checked.

selectRow moves from variants.spec.js into the page object, and
selectLayer delegates to it, so the click-and-wait selection lives in one
place.

AI-assisted-by: deepseek-v4.1-flash
2026-11-20 18:55:19 +01:00

259 lines
9.4 KiB
JavaScript

import { test, expect } from "@playwright/test";
import { WasmWorkspacePage } from "../pages/WasmWorkspacePage";
test.beforeEach(async ({ page }) => {
await WasmWorkspacePage.init(page);
await WasmWorkspacePage.mockConfigFlags(page, ["enable-feature-token-input"]);
});
test("Multiselection shows the mixed value of every sidebar section", async ({
page,
}) => {
const workspacePage = new WasmWorkspacePage(page);
await workspacePage.setupEmptyFile();
await workspacePage.mockRPC(
/get\-file\?/,
"workspace/get-file-copy-paste.json",
);
await workspacePage.mockRPC(
"get-file-fragment?file-id=*&fragment-id=*",
"workspace/get-file-copy-paste-fragment.json",
);
await workspacePage.goToWorkspace({
fileId: "870f9f10-87b5-8137-8005-934804124660",
pageId: "870f9f10-87b5-8137-8005-934804124661",
});
const measuresSection = workspacePage.rightSidebar.getByRole("region", {
name: "shape-measures-section",
});
const fillSection = workspacePage.rightSidebar.getByRole("region", {
name: "Fill section",
});
const strokeSection = workspacePage.rightSidebar.getByRole("region", {
name: "Stroke section",
});
const widthInput = measuresSection.getByRole("textbox", {
name: "Width",
exact: true,
});
// Rows are checkboxes bound to the selection (`aria-checked`), so reading
// that attribute replaces the 500 ms sleep of `clickLeafLayer`. A plain click
// selects one shape and Shift extends the selection to the range; both are
// asynchronous, so the helpers assert the whole state they need and not only
// the row they clicked: a plain click on an already selected row changes
// nothing visible on that row.
const rows = workspacePage.layers.getByTestId("layer-row");
const firstRow = rows.nth(0);
const secondRow = rows.nth(1);
// The rows flip before the sidebar re-renders for the new selection: the
// options panel is throttled and the selection arrives through a deferred
// render, so a value typed into that stale render is written to every shape
// of the previous selection. After a multi-selection the stale `Width` is
// still "Mixed", so this waits for the multi -> single transition only. A
// change from one single shape to another needs its own wait on the value it
// expects before editing.
const waitForSingleShape = async () => {
await expect(widthInput).not.toHaveAttribute("placeholder", "Mixed");
};
const selectOnly = async (row, other) => {
await row.click();
await expect(row).toBeChecked();
await expect(other).not.toBeChecked();
await waitForSingleShape();
};
const selectBoth = async (first, second) => {
await first.click();
await expect(first).toBeChecked();
await expect(second).not.toBeChecked();
await waitForSingleShape();
await second.click({ modifiers: ["Shift"] });
await expect(first).toBeChecked();
await expect(second).toBeChecked();
};
await test.step("measures", async () => {
await selectOnly(firstRow, secondRow);
const heightInput = measuresSection.getByRole("textbox", {
name: "Height",
exact: true,
});
const xPosInput = measuresSection.getByRole("textbox", {
name: "X axis",
exact: true,
});
const yPosInput = measuresSection.getByRole("textbox", {
name: "Y axis",
exact: true,
});
await expect(widthInput).toHaveValue("360");
await expect(heightInput).toHaveValue("53");
await expect(xPosInput).toHaveValue("1094");
await expect(yPosInput).toHaveValue("856");
// The two shapes differ in every measure, so all four go blank.
await selectBoth(firstRow, secondRow);
await expect(widthInput).toHaveAttribute("placeholder", "Mixed");
await expect(heightInput).toHaveAttribute("placeholder", "Mixed");
await expect(xPosInput).toHaveAttribute("placeholder", "Mixed");
await expect(yPosInput).toHaveAttribute("placeholder", "Mixed");
});
await test.step("fill", async () => {
await selectOnly(firstRow, secondRow);
await expect(fillSection).toBeVisible();
await expect(fillSection.getByText(/Mixed/i)).not.toBeVisible();
await selectBoth(firstRow, secondRow);
await expect(fillSection.getByText("Mixed")).toBeVisible();
});
await test.step("stroke", async () => {
await selectOnly(firstRow, secondRow);
await expect(strokeSection).toBeVisible();
await expect(strokeSection.getByText(/Mixed/i)).not.toBeVisible();
await selectBoth(firstRow, secondRow);
await expect(strokeSection.getByText("Mixed")).toBeVisible();
});
// The rotation step mutates the document, so it runs last: no earlier step
// can see a shape whose rotation changed.
await test.step("rotation", async () => {
await selectOnly(secondRow, firstRow);
const rotationInput = measuresSection.getByRole("textbox", {
name: "Rotation",
exact: true,
});
await expect(rotationInput).toBeVisible();
await rotationInput.fill("45");
await page.keyboard.press("Enter");
await expect(rotationInput).toHaveValue("45");
// Only one of the two rotated, so the grouped value differs.
await firstRow.click({ modifiers: ["Shift"] });
await expect(firstRow).toBeChecked();
await expect(secondRow).toBeChecked();
await expect(rotationInput).toHaveAttribute("placeholder", "Mixed");
});
});
test("Multiselection of text and typographies", async ({ page }) => {
const workspacePage = new WasmWorkspacePage(page);
await workspacePage.setupEmptyFile(page);
await workspacePage.mockRPC(
/get\-file\?/,
"workspace/multiselection-typography.json",
);
await workspacePage.goToWorkspace({
fileId: "c7ce0794-0992-8105-8004-38f280443849",
pageId: "1062e0a0-8fe0-80ae-8007-e70b4993f5f0",
});
await workspacePage.mockRPC(
"update-file?id=*",
"workspace/update-file-empty.json",
);
const plainTextLayer = workspacePage.layers.getByTestId("layer-row").nth(5);
const plainTextLayerTwo = workspacePage.layers
.getByTestId("layer-row")
.nth(2);
const typographyTextLayerOne = workspacePage.layers
.getByTestId("layer-row")
.nth(7);
const typographyTextLayerTwo = workspacePage.layers
.getByTestId("layer-row")
.nth(4);
const tokenTypographyTextLayerOne = workspacePage.layers
.getByTestId("layer-row")
.nth(6);
const tokenTypographyTextLayerTwo = workspacePage.layers
.getByTestId("layer-row")
.nth(3);
const rectangleLayer = workspacePage.layers.getByTestId("layer-row").nth(1);
const elipseLayer = workspacePage.layers.getByTestId("layer-row").nth(0);
const textSection = workspacePage.rightSidebar.getByRole("region", {
name: "Text section",
});
// Select rectangle and elipse together
await rectangleLayer.click();
await elipseLayer.click({ modifiers: ["Control"] });
await expect(textSection).not.toBeVisible();
// Select plain text layer
await plainTextLayer.click();
await expect(textSection).toBeVisible();
await expect(textSection.getByText("Mixed assets")).not.toBeVisible();
// Select two plain text layer with different font family
await plainTextLayerTwo.click({ modifiers: ["Control"] });
await expect(textSection).toBeVisible();
await expect(
textSection.getByTitle("Font family").getByText("Mixed Font Families"),
).toBeVisible();
// Select typography text layer
await typographyTextLayerOne.click();
await expect(textSection).toBeVisible();
await expect(textSection.getByText("Typography one")).toBeVisible();
// Select two typography text layer with different typography
await typographyTextLayerTwo.click({ modifiers: ["Control"] });
await expect(textSection).toBeVisible();
await expect(textSection.getByText("Mixed assets")).toBeVisible();
// Select token typography text layer
await tokenTypographyTextLayerOne.click();
await expect(textSection).toBeVisible();
await expect(textSection.getByLabel("token-typo-one")).toBeVisible();
// Select two token typography text layer with different token typography
await tokenTypographyTextLayerTwo.click({ modifiers: ["Control"] });
await expect(textSection).toBeVisible();
await expect(textSection.getByText("Mixed tokens")).toBeVisible();
//Select plain text layer and typography text layer together
await plainTextLayer.click();
await typographyTextLayerOne.click({ modifiers: ["Control"] });
await expect(textSection).toBeVisible();
await expect(textSection.getByText("Mixed assets")).toBeVisible();
//Select plain text layer and typography text layer together on reverse order
await typographyTextLayerOne.click();
await plainTextLayer.click({ modifiers: ["Control"] });
await expect(textSection).toBeVisible();
await expect(textSection.getByText("Mixed assets")).toBeVisible();
//Selen token typography text layer and typography text layer together
await tokenTypographyTextLayerOne.click();
await typographyTextLayerOne.click({ modifiers: ["Control"] });
await expect(textSection).toBeVisible();
await expect(textSection.getByText("Mixed assets")).toBeVisible();
//Select token typography text layer and typography text layer together on reverse order
await typographyTextLayerOne.click();
await tokenTypographyTextLayerOne.click({ modifiers: ["Control"] });
await expect(textSection).toBeVisible();
await expect(textSection.getByText("Mixed assets")).toBeVisible();
// Select rectangle and elipse together
await rectangleLayer.click();
await elipseLayer.click({ modifiers: ["Control"] });
await expect(textSection).not.toBeVisible();
});