mirror of
https://github.com/penpot/penpot.git
synced 2026-11-26 21:00:32 +00:00
🐛 Use ControlOrMeta for primary modifier in Playwright specs
Chromium now sends the host's user agent, so on macOS Penpot binds its shortcuts to Command and reads metaKey for ctrl-click selection. Specs that pressed a literal Control stopped working there. Switch those presses and click modifiers to ControlOrMeta. Keep Control where Penpot binds a bare key (zoom) or where the spec records a raw combo in the shortcut editor. Document the rule in the frontend developer guide, the Playwright memories and the migrate-ds-area skill. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
08365f6e1f
commit
f3fa38ecf6
@ -104,6 +104,10 @@ the file: two PRs that both append at the end conflict.
|
||||
`[class*='…']`, or `a.or(b)` when the element type changes (raw
|
||||
`[class*='menu-btn']` before, `getByRole("button", { name: "Options" })`
|
||||
after). Scope `.or()` to the area so it cannot match elsewhere.
|
||||
- Press the primary modifier as `ControlOrMeta`, never a literal
|
||||
`Control` (`keyboard.press("ControlOrMeta+d")`,
|
||||
`click({ modifiers: ["ControlOrMeta"] })`): on macOS Penpot binds its
|
||||
shortcuts to Command, so `Control` fails there.
|
||||
- Missing data? Add a fixture under `frontend/playwright/data/` and mock
|
||||
it (`dashboardPage.mockRPC(...)`, `DashboardPage.mockConfigFlags` for
|
||||
flags). Watch for expired or inconsistent fixtures (dates in the past,
|
||||
|
||||
@ -42,6 +42,8 @@ async (page) => {
|
||||
}
|
||||
```
|
||||
|
||||
For the primary modifier (Ctrl on Linux/Windows, Command on macOS) use `ControlOrMeta`, not `Control`; see `mem:frontend/testing-playwright`.
|
||||
|
||||
## Coordinate Planning
|
||||
|
||||
Playwright mouse coordinates and `getBoundingClientRect()` use viewport CSS pixels, not screen coordinates or device pixels. Read the viewport controls' `viewBox` and rectangle at the time of the gesture; pan, zoom and panels change the mapping. Ruler labels can be frame-relative and are not a substitute for the viewBox.
|
||||
|
||||
@ -4,4 +4,5 @@
|
||||
- The web server serves the release bundle in `frontend/resources/public`, not live sources. Rebuild from `frontend/` with `./scripts/build` after product edits or a branch switch with different sources/assets; a spec-only edit does not require that rebuild. A stale bundle that fails at boot says nothing about the spec.
|
||||
- Mock the RPC and socket traffic your page needs; the integration suite does not exercise live backend behavior. `BasePage.mockRPC` expects a command name, not the full RPC URL. Set up `BaseWebSocketPage` mocks before workspace initialization subscribes.
|
||||
- Prefer user-facing locators. Layer rows are an exception: selection can add hide/lock titles to their accessible name. Use `WorkspacePage.layerRow`/`layerRows` and `selectRow`/`selectLayer` rather than matching the entire role name or clicking twice.
|
||||
- Press the primary modifier as `ControlOrMeta`, never a literal `Control`, in `keyboard.press` and in `click({ modifiers })`. Chromium sends the host's user agent, so on macOS Penpot binds `c-mod`/`ca-mod` shortcuts to Command and `kbd/mod?` reads `metaKey`; a literal `Control` passes on Linux CI and fails on macOS. Keep `Control` only where Penpot reads `ctrlKey` itself, or where the spec records a raw key combo (the shortcut editor).
|
||||
- For build-once CI and stable check names see `mem:frontend/e2e-ci-workflow`. For targeted live pointer and keyboard input see `mem:frontend/playwright-gestures`.
|
||||
|
||||
@ -636,6 +636,19 @@ page.getByText("Penpot is the free open-");
|
||||
|
||||
To locate the rest of the elements we continue exploring the list of queries according to the order of priority. If none of the above options match the item, we resort to <code class="language-js">getByTestId</code> as a last resort.
|
||||
|
||||
#### Keyboard shortcuts and modifier keys
|
||||
|
||||
Penpot maps its shortcuts to the user's OS: <code class="language-js">Ctrl</code> on Linux and Windows, <code class="language-js">Command</code> on macOS. Playwright's Chromium reports the real host OS, so a test that presses a literal <code class="language-js">Control</code> passes on Linux and fails on macOS.
|
||||
|
||||
Use <code class="language-js">ControlOrMeta</code> for the primary modifier, both in key presses and in clicks:
|
||||
|
||||
```js
|
||||
await page.keyboard.press("ControlOrMeta+d");
|
||||
await layer.click({ modifiers: ["ControlOrMeta"] });
|
||||
```
|
||||
|
||||
Keep <code class="language-js">Control</code> only when the app reads the Ctrl key itself on every OS, or when the test records a raw key combination, such as a custom shortcut.
|
||||
|
||||
#### Assertions
|
||||
|
||||
Assertions use Playwright's <code class="language-js">expect</code> method. Here are some tips for writing your assertions:
|
||||
|
||||
@ -73,7 +73,7 @@ test("Updates a text font", async ({ page }) => {
|
||||
await workspace.waitForFirstRender();
|
||||
|
||||
await workspace.clickLeafLayer("this is a text");
|
||||
await page.keyboard.press("Control+b");
|
||||
await page.keyboard.press("ControlOrMeta+b");
|
||||
|
||||
await workspace.hideUI();
|
||||
|
||||
|
||||
@ -191,7 +191,7 @@ test("Multiselection of text and typographies", async ({ page }) => {
|
||||
});
|
||||
// Select rectangle and elipse together
|
||||
await rectangleLayer.click();
|
||||
await elipseLayer.click({ modifiers: ["Control"] });
|
||||
await elipseLayer.click({ modifiers: ["ControlOrMeta"] });
|
||||
await expect(textSection).not.toBeVisible();
|
||||
|
||||
// Select plain text layer
|
||||
@ -201,7 +201,7 @@ test("Multiselection of text and typographies", async ({ page }) => {
|
||||
await expect(textSection.getByText("Mixed assets")).not.toBeVisible();
|
||||
|
||||
// Select two plain text layer with different font family
|
||||
await plainTextLayerTwo.click({ modifiers: ["Control"] });
|
||||
await plainTextLayerTwo.click({ modifiers: ["ControlOrMeta"] });
|
||||
await expect(textSection).toBeVisible();
|
||||
await expect(
|
||||
textSection.getByTitle("Font family").getByText("Mixed Font Families"),
|
||||
@ -213,7 +213,7 @@ test("Multiselection of text and typographies", async ({ page }) => {
|
||||
await expect(textSection.getByText("Typography one")).toBeVisible();
|
||||
|
||||
// Select two typography text layer with different typography
|
||||
await typographyTextLayerTwo.click({ modifiers: ["Control"] });
|
||||
await typographyTextLayerTwo.click({ modifiers: ["ControlOrMeta"] });
|
||||
await expect(textSection).toBeVisible();
|
||||
await expect(textSection.getByText("Mixed assets")).toBeVisible();
|
||||
|
||||
@ -223,36 +223,36 @@ test("Multiselection of text and typographies", async ({ page }) => {
|
||||
await expect(textSection.getByLabel("token-typo-one")).toBeVisible();
|
||||
|
||||
// Select two token typography text layer with different token typography
|
||||
await tokenTypographyTextLayerTwo.click({ modifiers: ["Control"] });
|
||||
await tokenTypographyTextLayerTwo.click({ modifiers: ["ControlOrMeta"] });
|
||||
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 typographyTextLayerOne.click({ modifiers: ["ControlOrMeta"] });
|
||||
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 plainTextLayer.click({ modifiers: ["ControlOrMeta"] });
|
||||
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 typographyTextLayerOne.click({ modifiers: ["ControlOrMeta"] });
|
||||
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 tokenTypographyTextLayerOne.click({ modifiers: ["ControlOrMeta"] });
|
||||
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 elipseLayer.click({ modifiers: ["ControlOrMeta"] });
|
||||
await expect(textSection).not.toBeVisible();
|
||||
});
|
||||
|
||||
@ -204,9 +204,9 @@ test.describe("Design tab", () => {
|
||||
await workspace.rectShapeButton.click();
|
||||
await workspace.clickWithDragViewportAt(128, 128, 200, 100);
|
||||
await workspace.clickLeafLayer("Rectangle");
|
||||
await page.keyboard.press("Control+D");
|
||||
await page.keyboard.press("ControlOrMeta+D");
|
||||
await expect(workspace.layers.getByText("Rectangle")).toHaveCount(2);
|
||||
await page.keyboard.press("Control+A");
|
||||
await page.keyboard.press("ControlOrMeta+A");
|
||||
|
||||
await expect(
|
||||
workspace.rightSidebar.getByRole("button", { name: "Flatten" }),
|
||||
@ -308,9 +308,9 @@ test.describe("Design tab", () => {
|
||||
await workspace.rectShapeButton.click();
|
||||
await workspace.clickWithDragViewportAt(128, 128, 200, 100);
|
||||
await workspace.clickLeafLayer("Rectangle");
|
||||
await page.keyboard.press("Control+D");
|
||||
await page.keyboard.press("ControlOrMeta+D");
|
||||
await expect(workspace.layers.getByText("Rectangle")).toHaveCount(2);
|
||||
await page.keyboard.press("Control+A");
|
||||
await page.keyboard.press("ControlOrMeta+A");
|
||||
|
||||
await expect(
|
||||
workspace.rightSidebar.getByRole("button", { name: /^Align left/ }),
|
||||
@ -946,7 +946,7 @@ test.describe("Undo history", () => {
|
||||
await page.keyboard.press("r");
|
||||
await workspace.clickWithDragViewportAt(128, 128, 200, 100);
|
||||
|
||||
await page.keyboard.press("Control+Alt+h");
|
||||
await page.keyboard.press("ControlOrMeta+Alt+h");
|
||||
await page.getByRole("tab", { name: "Actions" }).click();
|
||||
const panel = page.getByRole("tabpanel", { name: "Actions" });
|
||||
const entry = panel.getByText("New rectangle");
|
||||
@ -1035,7 +1035,7 @@ test.describe("Plugins", () => {
|
||||
await workspace.mockRPC("get-profile", profile);
|
||||
}
|
||||
await workspace.goToWorkspace();
|
||||
await workspace.page.keyboard.press("Control+Alt+P");
|
||||
await workspace.page.keyboard.press("ControlOrMeta+Alt+P");
|
||||
};
|
||||
|
||||
test("Shows the plugins manager without plugins", async ({ page }) => {
|
||||
@ -1159,7 +1159,7 @@ test.describe("Selected colors", () => {
|
||||
});
|
||||
|
||||
await workspace.clickToggableLayer("Board");
|
||||
await page.keyboard.press("Control+A");
|
||||
await page.keyboard.press("ControlOrMeta+A");
|
||||
|
||||
await expect(
|
||||
workspace.rightSidebar.getByRole("button", { name: "More colors" }),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user