mirror of
https://github.com/penpot/penpot.git
synced 2026-11-22 10:20:51 +00:00
* ♻️ 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
113 lines
4.3 KiB
JavaScript
113 lines
4.3 KiB
JavaScript
import { test, expect } from "@playwright/test";
|
|
import { BaseWebSocketPage } from "../pages/BaseWebSocketPage";
|
|
import { WasmWorkspacePage } from "../pages/WasmWorkspacePage";
|
|
import { setupTokensFileRender, unfoldTokenType } from "./tokens/helpers";
|
|
|
|
// Regression smoke for issue #7440: the scroll position of a left sidebar tab
|
|
// must survive a tab switch, and each tab keeps its own position. The store
|
|
// behind it (save per key, forget one key, restore and retry) is covered by
|
|
// `ui/sidebar_scroll_test.cljs`, so one test is enough here.
|
|
// Ported from closed PR #7544 and adapted to the current implementation
|
|
// (scroll store held in the sidebar + async restore on mount) and to the
|
|
// current fixtures and page objects.
|
|
|
|
// We allow a small tolerance because content can shift slightly on remount.
|
|
const POSITION_TOLERANCE = 20; // pixels
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
await WasmWorkspacePage.init(page);
|
|
await BaseWebSocketPage.mockRPC(page, "get-teams", "get-teams-tokens.json");
|
|
});
|
|
|
|
async function visibleScrollContainers(page) {
|
|
const containers = page.locator(
|
|
'[data-testid="left-sidebar"] [data-scroll-container="true"]',
|
|
);
|
|
const count = await containers.count();
|
|
const visible = [];
|
|
for (let i = 0; i < count; i++) {
|
|
const el = containers.nth(i);
|
|
// eslint-disable-next-line no-await-in-loop
|
|
if (await el.evaluate((node) => !!node && node.offsetParent !== null)) {
|
|
visible.push(el);
|
|
}
|
|
}
|
|
return visible;
|
|
}
|
|
|
|
async function scrollableContainers(page) {
|
|
const visible = await visibleScrollContainers(page);
|
|
const scrollable = [];
|
|
for (const el of visible) {
|
|
// eslint-disable-next-line no-await-in-loop
|
|
if (
|
|
await el.evaluate((node) => node.scrollHeight > node.clientHeight + 100)
|
|
) {
|
|
scrollable.push(el);
|
|
}
|
|
}
|
|
return scrollable;
|
|
}
|
|
|
|
async function scrollToBottom(locator) {
|
|
await locator.evaluate((el) => {
|
|
el.scrollTop = el.scrollHeight;
|
|
});
|
|
// Programmatic scrolls dispatch scroll events asynchronously; wait for
|
|
// the save handler before switching tabs.
|
|
await locator.page().waitForTimeout(150);
|
|
}
|
|
|
|
async function expectScrollRestored(locator, expected) {
|
|
// Restore runs in a post-mount effect with frame retries, so poll
|
|
// instead of asserting immediately after the tab click.
|
|
await expect
|
|
.poll(async () => locator.evaluate((el) => el.scrollTop), {
|
|
timeout: 10000,
|
|
})
|
|
.toBeGreaterThanOrEqual(expected - POSITION_TOLERANCE);
|
|
}
|
|
|
|
test("Sidebar maintains independent scroll positions per tab", async ({
|
|
page,
|
|
}) => {
|
|
const { tokensSidebar } = await setupTokensFileRender(page);
|
|
await unfoldTokenType(tokensSidebar, "color");
|
|
|
|
// Scroll Tokens to the bottom.
|
|
const tokensContainers = await scrollableContainers(page);
|
|
expect(
|
|
tokensContainers.length,
|
|
"Tokens tab should have a scrollable container",
|
|
).toBeGreaterThan(0);
|
|
await scrollToBottom(tokensContainers[0]);
|
|
const tokensPos = await tokensContainers[0].evaluate((el) => el.scrollTop);
|
|
expect(tokensPos).toBeGreaterThan(0);
|
|
|
|
// A hop through Assets must bring back the Tokens position: this round trip
|
|
// was its own test before the merge.
|
|
await page.getByRole("tab", { name: "Assets" }).click();
|
|
await page.getByRole("tab", { name: "Tokens" }).click();
|
|
const tokensAfterAssets = (await scrollableContainers(page))[0];
|
|
await expectScrollRestored(tokensAfterAssets, tokensPos);
|
|
|
|
// Switch to Layers: fresh panel, must start at top (not contaminated
|
|
// by the Tokens position saved under a different key).
|
|
await page.getByRole("tab", { name: "Layers" }).click();
|
|
const layersVisible = await visibleScrollContainers(page);
|
|
expect(layersVisible.length).toBeGreaterThan(0);
|
|
const layersPos = await layersVisible[0].evaluate((el) => el.scrollTop);
|
|
expect(layersPos).toBe(0);
|
|
|
|
// Back to Tokens: its own position must be restored, not Layers'.
|
|
await page.getByRole("tab", { name: "Tokens" }).click();
|
|
const tokensRestored = (await scrollableContainers(page))[0];
|
|
await expectScrollRestored(tokensRestored, tokensPos);
|
|
|
|
// And back to Layers: still untouched at top.
|
|
await page.getByRole("tab", { name: "Layers" }).click();
|
|
const layersAgain = await visibleScrollContainers(page);
|
|
const layersAgainPos = await layersAgain[0].evaluate((el) => el.scrollTop);
|
|
expect(layersAgainPos).toBe(0);
|
|
});
|