penpot/frontend/playwright/ui/specs/text-options-missing-font.spec.js
Andrey Antukh f27bfdf76a
♻️ Reduce the routes, viewer, theme and typography e2e specs (#13059)
* ♻️ Reduce the routes, viewer, theme and typography e2e specs

The five specs of Task 10 (routes, theme, viewer and roles) go from 14
tests to 6, and the two of Task 11 (missing font and add typography)
from 9 to 4. Nine unit tests cover rules that had none: five for the
private legacy-match and four for the viewer frame navigation. No
skipped test and no fixture removed.

The browser keeps the wiring: the known and unknown hash as two steps
of one test, the theme applied live without a reload, the viewer role
walked in two loads with the context menu counted instead of trusted,
and the typography states merged around shared fixtures. The viewer
zoom click comes back as a header step; the arrows e2e becomes unit
tests, with the Next button still clicked by the child-click test. The
missing-font test asserts the renamed, disabled typography button
instead of a hidden one it never described.

WorkspacePage gains reloadWorkspace, which clears the socket registry,
reloads and reopens the mock, and settles on the sitemap page name or
on the canvas when the restored sidebar tab hides it. layerRow matches
rows by anchored text, because a selected row's action buttons can join
its accessible name, and selectLayer accepts click options for the
shift-click steps. The font specs use both and no longer import
MockWebSocketHelper.

The viewer role asserts its two absences by testid: new-project-button
already existed and add-custom-font is new in fonts.cljs, the only
product change, with the visible side covered by dashboard.spec.
routes_test adds the path-params case for legacy-match; viewer_test
asserts the first event and the page id of the frame navigation, and
watch-events delivers asynchronously and handles the nil a watch can
return.

Measured at four workers: 23 to 10 tests; Task 10 from 141.3 to
68.5/72.3 worker-seconds and Task 11 from 150.1 to 109.0/109.3.

Closes #13058

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

* 🐛 Let the two reduced e2e steps fail when they should

The typography step selected the next layer with Shift, which in the layers
panel is a range selection: the range also brought in the text with a
typography token, so the button was hidden by the applied token and not by
the mixed values. A mod-click adds only that shape, and two new assertions
keep the token and the asset texts out of the selection.

The logo step clicked 100 px below the logo and asserted the URL, which
potok updates after the click returns, so the assertion matched the old URL
on its first poll. Probing elementFromPoint under the logo answers the
hit-area question directly.

AI-assisted-by: deepseek-v4.1-flash
2026-11-20 17:41:43 +01:00

167 lines
6.1 KiB
JavaScript

import { test, expect } from "@playwright/test";
import { WorkspacePage } from "../pages/WorkspacePage";
// ---------------------------------------------------------------------------
// The "Create typography style" button (workspace.options.convert-to-typography)
// in the text options sidebar is rendered when none of these hold for the
// selected text shape(s) (src/app/main/ui/workspace/sidebar/options/menus/text.cljs):
//
// (when (and (not typography) (not multiple?) (not applied-token-name)) ...)
//
// A missing font is a different state: the button stays, its aria-label
// becomes the font-not-available message and it is disabled.
//
// The first test covers the font state, the second one each condition of the
// `when`.
// ---------------------------------------------------------------------------
function convertToTypographyButton(workspace) {
return workspace.rightSidebar.getByRole("button", {
name: "Create typography style",
});
}
function fontNotAvailableButton(workspace) {
return workspace.rightSidebar.getByRole("button", {
name: /no longer available/,
});
}
// Matches the button in either state, so "absent" cannot be satisfied by a
// rename.
function typographyButtonAnyState(workspace) {
return workspace.rightSidebar.getByRole("button", {
name: /Create typography style|no longer available/,
});
}
function textSection(workspace) {
return workspace.rightSidebar.getByRole("region", { name: "Text section" });
}
// Fixture render-wasm/get-file-text-custom-fonts.json has a text shape
// ("Penpot & Dragons") using a custom team font-id and no typography/token
// applied - otherwise exactly the state that reveals the button once its
// font resolves. Toggling the get-font-variants mock between "the team owns
// this font" and "empty" simulates the font being present vs. missing.
const CUSTOM_FONTS_FILE = {
id: "434b0541-fa2f-802f-8006-59827d964a9b",
pageId: "434b0541-fa2f-802f-8006-59827d964a9c",
};
test("The font of the shape decides the button", async ({ page }) => {
await WorkspacePage.init(page);
const workspace = new WorkspacePage(page);
await workspace.setupEmptyFile();
await workspace.mockRPC(
/get\-file\?/,
"render-wasm/get-file-text-custom-fonts.json",
);
await test.step("font missing", async () => {
// The team does not own the shape's custom font, so it can't be resolved.
await workspace.mockRPC(
"get-font-variants?team-id=*",
"workspace/get-font-variants-empty.json",
);
await workspace.goToWorkspace({
fileId: CUSTOM_FONTS_FILE.id,
pageId: CUSTOM_FONTS_FILE.pageId,
});
await workspace.selectLayer("Penpot & Dragons");
// The button is not removed: its label explains the missing font and it
// is disabled. Asserting only that the "Create typography style" locator
// is hidden passed for the wrong reason, because the label is what
// changes.
await expect(fontNotAvailableButton(workspace)).toBeVisible();
await expect(fontNotAvailableButton(workspace)).toBeDisabled();
await expect(convertToTypographyButton(workspace)).toHaveCount(0);
});
await test.step("font resolved", async () => {
// The team owns the shape's custom font, so it resolves normally. The
// last matching route wins, and the reload fetches the variants again.
await workspace.mockRPC(
"get-font-variants?team-id=*",
"render-wasm/get-font-variants-custom-fonts.json",
);
await workspace.reloadWorkspace();
await workspace.selectLayer("Penpot & Dragons");
await expect(convertToTypographyButton(workspace)).toBeVisible();
await expect(convertToTypographyButton(workspace)).toBeEnabled();
await expect(fontNotAvailableButton(workspace)).toHaveCount(0);
});
});
// multiselection-typography.json holds, in the same page, a plain text, one
// with an in-file typography asset, and one with a typography token applied.
// The three ineligible cases share one page load; each step selects another
// layer.
const SHARED_FILE = {
id: "c7ce0794-0992-8105-8004-38f280443849",
pageId: "1062e0a0-8fe0-80ae-8007-e70b4993f5f0",
};
test("Ineligible selections hide the button", async ({ page }) => {
await WorkspacePage.init(page);
const workspace = new WorkspacePage(page);
await workspace.setupEmptyFile();
await workspace.mockRPC(
/get\-file\?/,
"workspace/multiselection-typography.json",
);
await workspace.goToWorkspace({
fileId: SHARED_FILE.id,
pageId: SHARED_FILE.pageId,
});
await test.step("a plain text keeps the button", async () => {
await workspace.selectLayer("Text with no typography");
await expect(convertToTypographyButton(workspace)).toBeEnabled();
});
await test.step("an applied typography asset hides it", async () => {
await workspace.selectLayer("Text with typography asset one");
await expect(textSection(workspace)).toBeVisible();
await expect(typographyButtonAnyState(workspace)).toHaveCount(0);
});
await test.step("an applied typography token hides it", async () => {
await workspace.selectLayer("Text with typography token one");
await expect(textSection(workspace)).toBeVisible();
await expect(typographyButtonAnyState(workspace)).toHaveCount(0);
});
await test.step("several selected texts hide it", async () => {
await workspace.selectLayer("Text with no typography");
await workspace.selectLayer("Text with no typography two", {
modifiers: ["ControlOrMeta"],
});
await expect(
workspace.layerRow("Text with no typography"),
).toHaveAttribute("aria-checked", "true");
await expect(
workspace.layerRow("Text with no typography two"),
).toHaveAttribute("aria-checked", "true");
// With either of these in the selection, `applied-token-name` would be
// `:multiple` and the button would be hidden for that reason.
await expect(
workspace.layerRow("Text with typography token two"),
).toHaveAttribute("aria-checked", "false");
await expect(
workspace.layerRow("Text with typography asset two"),
).toHaveAttribute("aria-checked", "false");
await expect(typographyButtonAnyState(workspace)).toHaveCount(0);
});
});