diff --git a/frontend/playwright/ui/pages/DashboardPage.js b/frontend/playwright/ui/pages/DashboardPage.js index 8d0f7df082..7fbe50c9cd 100644 --- a/frontend/playwright/ui/pages/DashboardPage.js +++ b/frontend/playwright/ui/pages/DashboardPage.js @@ -75,7 +75,7 @@ export class DashboardPage extends BaseWebSocketPage { .getByTestId("dashboard-header") .getByRole("heading", { level: 1 }); - this.addProjectButton = page.getByRole("button", { name: "+ NEW PROJECT" }); + this.addProjectButton = page.getByTestId("new-project-button"); this.projectName = page.getByText("Project 1"); this.draftsLink = this.sidebar.getByText("Drafts"); diff --git a/frontend/playwright/ui/pages/WorkspacePage.js b/frontend/playwright/ui/pages/WorkspacePage.js index 4037d6dd3e..fdae33d004 100644 --- a/frontend/playwright/ui/pages/WorkspacePage.js +++ b/frontend/playwright/ui/pages/WorkspacePage.js @@ -256,6 +256,23 @@ export class WorkspacePage extends BaseWebSocketPage { } } + // Reload the workspace keeping the mocked backend: the socket registry + // still holds the mock of the document that is about to be destroyed, and + // the new document's socket has to be reopened. `waitForPageName` is false + // for reloads that keep the sidebar on Assets or Tokens: there the sitemap + // page name is not rendered, so the canvas is the settle signal. + async reloadWorkspace({ pageName = "Page 1", waitForPageName = true } = {}) { + MockWebSocketHelper.clear(); + await this.page.reload(); + this.#ws = await this.waitForNotificationsWebSocket(); + await this.#ws.mockOpen(); + if (waitForPageName) { + await this.#waitForWebSocketReadiness(pageName); + } else { + await expect(this.viewport).toBeVisible({ timeout: 30000 }); + } + } + async #waitForWebSocketReadiness(pageName) { // TODO: find a better event to settle whether the app is ready to receive notifications via ws await expect(this.pageName).toHaveText(pageName, { timeout: 30000 }) diff --git a/frontend/playwright/ui/specs/dashboard-viewer-role.spec.js b/frontend/playwright/ui/specs/dashboard-viewer-role.spec.js index 0ab4ef8446..a8b09353d3 100644 --- a/frontend/playwright/ui/specs/dashboard-viewer-role.spec.js +++ b/frontend/playwright/ui/specs/dashboard-viewer-role.spec.js @@ -1,6 +1,11 @@ import { test, expect } from "@playwright/test"; import DashboardPage from "../pages/DashboardPage"; +// A viewer's permission is not a frontend rule: `:can-edit` arrives in the +// `get-teams` payload and the dashboard components read it inline, so there is +// no pure predicate to move to a unit test. These tests keep the browser proof +// and walk the sections a viewer reaches from the sidebar. + test.beforeEach(async ({ page }) => { await DashboardPage.init(page); @@ -11,21 +16,7 @@ test.beforeEach(async ({ page }) => { ); }); -test("User can't create a new project", async ({ page }) => { - const dashboardPage = new DashboardPage(page); - await dashboardPage.goToDashboard(); - await expect(dashboardPage.addProjectButton).toBeHidden(); -}); - -test("User has an empty placeholder", async ({ page }) => { - const dashboardPage = new DashboardPage(page); - await dashboardPage.goToDashboard(); - await expect( - dashboardPage.page.getByTestId("empty-placeholder"), - ).toBeVisible(); -}); - -test("User hasn't context menu options for edit file", async ({ page }) => { +test("A viewer sees no project or file edit affordances", async ({ page }) => { await DashboardPage.mockRPC( page, "get-all-projects", @@ -34,29 +25,42 @@ test("User hasn't context menu options for edit file", async ({ page }) => { const dashboardPage = new DashboardPage(page); await dashboardPage.setupDrafts(); - await dashboardPage.goToDrafts(); + await dashboardPage.goToDashboard(); - const button = dashboardPage.page.getByRole("button", { name: /New File 2/ }); - await button.click(); - await button.click({ button: "right" }); + await test.step("no project creation in the recent files section", async () => { + await expect(dashboardPage.addProjectButton).toHaveCount(0); + await expect( + dashboardPage.page.getByTestId("empty-placeholder"), + ).toBeVisible(); + }); - await expect(dashboardPage.page.getByText("rename")).toBeHidden(); - await expect(dashboardPage.page.getByText("duplicate")).toBeHidden(); - await expect( - dashboardPage.page.getByText("add as shared library"), - ).toBeHidden(); - await expect(dashboardPage.page.getByText("delete")).toBeHidden(); + await test.step("no file creation in the drafts section", async () => { + await dashboardPage.sidebar.getByText("Drafts", { exact: true }).click(); + await expect(dashboardPage.mainHeading).toHaveText("Drafts"); + await expect(page.getByTestId("new-file")).toHaveCount(0); + }); + + await test.step("no edit options in the file context menu", async () => { + const button = page.getByRole("button", { name: /New File 2/ }); + await button.click(); + await button.click({ button: "right" }); + + // A viewer keeps the two unconditional items (open in a new tab and + // download). Anything gated by `can-edit` that leaks into the menu makes + // this count grow, which is what the four labels below only describe. + await expect(page.getByRole("menuitem")).toHaveCount(2); + + await expect(page.getByText("rename")).toBeHidden(); + await expect(page.getByText("duplicate")).toBeHidden(); + await expect(page.getByText("add as shared library")).toBeHidden(); + await expect(page.getByText("delete")).toBeHidden(); + }); }); -test("User hasn't create file button", async ({ page }) => { +test("A viewer cannot add a custom font", async ({ page }) => { const dashboardPage = new DashboardPage(page); - await dashboardPage.setupDrafts(); - await dashboardPage.goToDrafts(); - await expect(dashboardPage.page.getByText("+ New File")).toBeHidden(); -}); -test("User hasn't add font button", async ({ page }) => { - const dashboardPage = new DashboardPage(page); await dashboardPage.goToFonts(); - await expect(dashboardPage.page.getByText("add custom font")).toBeHidden(); + + await expect(page.getByTestId("add-custom-font")).toHaveCount(0); }); diff --git a/frontend/playwright/ui/specs/dashboard.spec.js b/frontend/playwright/ui/specs/dashboard.spec.js index d20b90cfd4..8e205386e3 100644 --- a/frontend/playwright/ui/specs/dashboard.spec.js +++ b/frontend/playwright/ui/specs/dashboard.spec.js @@ -116,7 +116,9 @@ test("User has create file button", async ({ page }) => { test("User has add font button", async ({ page }) => { const dashboardPage = new DashboardPage(page); await dashboardPage.goToFonts(); - await expect(dashboardPage.page.getByText("add custom font")).toBeVisible(); + await expect( + dashboardPage.page.getByTestId("add-custom-font"), + ).toBeVisible(); }); test("Bug 9443, Admin can not demote owner", async ({ page }) => { diff --git a/frontend/playwright/ui/specs/email-verification.spec.js b/frontend/playwright/ui/specs/email-verification.spec.js index f15be88e20..bfa5985eab 100644 --- a/frontend/playwright/ui/specs/email-verification.spec.js +++ b/frontend/playwright/ui/specs/email-verification.spec.js @@ -8,34 +8,29 @@ test.beforeEach(async ({ page }) => { await RegisterPage.initWithLoggedOutUser(page); }); -test.describe("Email verification", () => { - for (const colorScheme of ["light", "dark"]) { - test(`Newly verified account follows the ${colorScheme} system theme`, async ({ - page, - }) => { - await page.emulateMedia({ colorScheme }); - const registerPage = new RegisterPage(page); - await registerPage.setupEmailVerificationSuccess(); +test("Verified account follows the system theme and shows it in settings", async ({ + page, +}) => { + const registerPage = new RegisterPage(page); - await registerPage.goToVerifyToken(); - await page.waitForURL(/screen=dashboard/); - - // The dark theme uses the legacy body class "default". - await expect(page.locator("body")).toHaveClass( - colorScheme === "dark" ? "default" : "light", - ); - }); - } - - test("Settings > UI Theme shows System theme selected, not blank", async ({ - page, - }) => { - const registerPage = new RegisterPage(page); + await test.step("follows the dark system theme", async () => { + await page.emulateMedia({ colorScheme: "dark" }); await registerPage.setupEmailVerificationSuccess(); await registerPage.goToVerifyToken(); await page.waitForURL(/screen=dashboard/); + // The dark theme uses the legacy body class "default". + await expect(page.locator("body")).toHaveClass("default"); + }); + + await test.step("follows a change to the light system theme", async () => { + await page.emulateMedia({ colorScheme: "light" }); + + await expect(page.locator("body")).toHaveClass("light"); + }); + + await test.step("shows the System theme in settings", async () => { await page.goto("/?screen=settings-options"); // The language select is the first combobox on the page, the theme diff --git a/frontend/playwright/ui/specs/legacy-hash-redirect.spec.js b/frontend/playwright/ui/specs/legacy-hash-redirect.spec.js index 64122dbe17..66c1ed8f08 100644 --- a/frontend/playwright/ui/specs/legacy-hash-redirect.spec.js +++ b/frontend/playwright/ui/specs/legacy-hash-redirect.spec.js @@ -11,26 +11,26 @@ test.beforeEach(async ({ page }) => { await login.initWithLoggedOutUser(); }); -test("Legacy auth hash URL redirects to query-string format", async ({ - page, -}) => { +test("Legacy hash URLs translate or fall through", async ({ page }) => { const loginPage = new LoginPage(page); - await page.goto("/#/auth/login"); + await test.step("a known hash translates to the query string", async () => { + await page.goto("/#/auth/login"); - await expect(page).toHaveURL(/screen=auth-login/); - expect(new URL(page.url()).hash).toBe(""); - await expect(loginPage.initialHeading).toBeVisible(); -}); - -test("Unknown legacy hash falls through to the query flow", async ({ - page, -}) => { - const loginPage = new LoginPage(page); - // The unknown-route fallback rechecks profile AND teams. - await loginPage.mockRPC("get-teams", "logged-in-user/get-teams-default.json"); - - await page.goto("/?template=foo#/nope"); - - await expect(loginPage.initialHeading).toBeVisible(); + await expect(page).toHaveURL(/screen=auth-login/); + expect(new URL(page.url()).hash).toBe(""); + await expect(loginPage.initialHeading).toBeVisible(); + }); + + await test.step("an unknown hash falls through to the query flow", async () => { + // The unknown-route fallback rechecks profile AND teams. + await loginPage.mockRPC( + "get-teams", + "logged-in-user/get-teams-default.json", + ); + + await page.goto("/?template=foo#/nope"); + + await expect(loginPage.initialHeading).toBeVisible(); + }); }); diff --git a/frontend/playwright/ui/specs/text-options-missing-font.spec.js b/frontend/playwright/ui/specs/text-options-missing-font.spec.js index f8a50343a2..3028886c45 100644 --- a/frontend/playwright/ui/specs/text-options-missing-font.spec.js +++ b/frontend/playwright/ui/specs/text-options-missing-font.spec.js @@ -1,17 +1,18 @@ import { test, expect } from "@playwright/test"; import { WorkspacePage } from "../pages/WorkspacePage"; -import { WasmWorkspacePage } from "../pages/WasmWorkspacePage"; // --------------------------------------------------------------------------- // The "Create typography style" button (workspace.options.convert-to-typography) -// in the text options sidebar is only shown when ALL of these hold for the +// 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): -// (and (some? font) (not typography) (not multiple?) (not applied-token-name)) -// Each test below isolates one condition that must independently hide it: -// - font missing (font-id not registered in app.main.fonts/fontsdb) -// - a typography asset is applied (typography-ref-id set) -// - multiple shapes are selected with differing attributes -// - a typography design token is applied (applied-tokens :typography) +// +// (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) { @@ -20,182 +21,146 @@ function convertToTypographyButton(workspace) { }); } -test.describe("font missing", () => { - // 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 FILE = { - id: "434b0541-fa2f-802f-8006-59827d964a9b", - pageId: "434b0541-fa2f-802f-8006-59827d964a9c", - }; - - test.beforeEach(async ({ page }) => { - await WorkspacePage.init(page); +function fontNotAvailableButton(workspace) { + return workspace.rightSidebar.getByRole("button", { + name: /no longer available/, }); +} - test("Create typography style button is hidden when the shape font is missing", async ({ - page, - }) => { - const workspace = new WorkspacePage(page); - await workspace.setupEmptyFile(); - await workspace.mockRPC( - /get\-file\?/, - "render-wasm/get-file-text-custom-fonts.json", - ); +// 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: FILE.id, pageId: FILE.pageId }); + await workspace.goToWorkspace({ + fileId: CUSTOM_FONTS_FILE.id, + pageId: CUSTOM_FONTS_FILE.pageId, + }); - await workspace.clickLeafLayer("Penpot & Dragons"); + await workspace.selectLayer("Penpot & Dragons"); - await expect(convertToTypographyButton(workspace)).not.toBeVisible(); + // 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); }); - test("Create typography style button is visible once the shape font resolves", async ({ - page, - }) => { - const workspace = new WorkspacePage(page); - await workspace.setupEmptyFile(); - await workspace.mockRPC( - /get\-file\?/, - "render-wasm/get-file-text-custom-fonts.json", - ); - // The team owns the shape's custom font, so it resolves normally. + 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.goToWorkspace({ fileId: FILE.id, pageId: FILE.pageId }); + await workspace.reloadWorkspace(); - await workspace.clickLeafLayer("Penpot & Dragons"); + await workspace.selectLayer("Penpot & Dragons"); await expect(convertToTypographyButton(workspace)).toBeVisible(); + await expect(convertToTypographyButton(workspace)).toBeEnabled(); + await expect(fontNotAvailableButton(workspace)).toHaveCount(0); }); }); -test.describe("typography asset applied", () => { - // multiselection-typography.json: "Text with typography asset one" has a - // typography-ref-id pointing at an in-file typography asset (font - // gfont-agdasima, a built-in Google font that resolves with no extra - // mocking), and is not multi-selected or token-applied. - const FILE = { - id: "c7ce0794-0992-8105-8004-38f280443849", - pageId: "1062e0a0-8fe0-80ae-8007-e70b4993f5f0", - }; +// 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.beforeEach(async ({ page }) => { - await WorkspacePage.init(page); +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, }); - test("Create typography style button is hidden when a typography asset is applied", async ({ - page, - }) => { - const workspace = new WorkspacePage(page); - await workspace.setupEmptyFile(); - await workspace.mockRPC( - /get\-file\?/, - "workspace/multiselection-typography.json", - ); - await workspace.goToWorkspace({ fileId: FILE.id, pageId: FILE.pageId }); + await test.step("a plain text keeps the button", async () => { + await workspace.selectLayer("Text with no typography"); - await workspace.clickLeafLayer("Text with typography asset one"); - - // Sanity check: the text options panel did render for this shape - the - // button is specifically hidden by the applied typography, not because - // the whole panel failed to show up. - await expect( - workspace.rightSidebar.getByRole("region", { name: "Text section" }), - ).toBeVisible(); - await expect(convertToTypographyButton(workspace)).not.toBeVisible(); - }); -}); - -test.describe("multiple selection", () => { - // get-file-text-multiple-selection.json has two text shapes sharing the - // same (resolvable, built-in) font-id but differing font-size, with no - // typography or token applied - so selecting both together isolates - // `multiple?` becoming true without also making the font unresolved. - const FILE = { - id: "434b0541-fa2f-802f-8006-6a827d964a9b", - pageId: "434b0541-fa2f-802f-8006-6a827d964a9c", - }; - - test.beforeEach(async ({ page }) => { - await WorkspacePage.init(page); + await expect(convertToTypographyButton(workspace)).toBeEnabled(); }); - test("Create typography style button is hidden when multiple shapes with different values are selected", async ({ - page, - }) => { - const workspace = new WorkspacePage(page); - await workspace.setupEmptyFile(); - await workspace.mockRPC( - /get\-file\?/, - "workspace/get-file-text-multiple-selection.json", - ); - await workspace.goToWorkspace({ fileId: FILE.id, pageId: FILE.pageId }); + await test.step("an applied typography asset hides it", async () => { + await workspace.selectLayer("Text with typography asset one"); - await workspace.clickLeafLayer("Text multiple selection one"); - await expect(convertToTypographyButton(workspace)).toBeVisible(); + await expect(textSection(workspace)).toBeVisible(); + await expect(typographyButtonAnyState(workspace)).toHaveCount(0); + }); - await workspace.clickLeafLayer("Text multiple selection two", { - modifiers: ["Shift"], + 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(convertToTypographyButton(workspace)).not.toBeVisible(); - }); -}); - -test.describe("typography token applied", () => { - // get-file-token-tooltip.json: "Text with token" has a typography design - // token applied (applied-tokens :typography) using font gfont-arizonia (a - // built-in Google font that resolves with no extra mocking). - test.beforeEach(async ({ page }) => { - await WasmWorkspacePage.init(page); - await WasmWorkspacePage.mockRPC(page, "get-teams", "get-teams-tokens.json"); - }); - - test("Create typography style button is hidden when a typography token is applied", async ({ - page, - }) => { - const workspace = new WasmWorkspacePage(page); - await workspace.mockConfigFlags(["enable-feature-token-input"]); - await workspace.setupEmptyFile(); - await workspace.mockRPC("get-team?id=*", "workspace/get-team-tokens.json"); - await workspace.mockRPC( - /get\-file\?/, - "workspace/get-file-token-tooltip.json", - ); - await workspace.mockRPC( - /get\-file\-fragment\?/, - "workspace/get-file-fragment-tokens.json", - ); - await workspace.mockRPC( - "update-file?id=*", - "workspace/update-file-create-rect.json", - ); - await workspace.goToWorkspace({ - fileId: "c7ce0794-0992-8105-8004-38f280443849", - pageId: "4530574a-7a0a-807b-8008-0107b2c4628e", - }); - - await page.getByRole("tab", { name: "Layers" }).click(); - await workspace.layers - .getByTestId("layer-row") - .filter({ hasText: "Text with token" }) - .click(); - - // Sanity check: the text options panel did render for this shape - the - // button is specifically hidden by the applied token, not because the - // whole panel failed to show up. await expect( - workspace.rightSidebar.getByRole("region", { name: "Text section" }), - ).toBeVisible(); - await expect(convertToTypographyButton(workspace)).not.toBeVisible(); + 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); }); }); diff --git a/frontend/playwright/ui/specs/viewer-content.spec.js b/frontend/playwright/ui/specs/viewer-content.spec.js index f17b1f22eb..5d2ee1b4e8 100644 --- a/frontend/playwright/ui/specs/viewer-content.spec.js +++ b/frontend/playwright/ui/specs/viewer-content.spec.js @@ -5,9 +5,6 @@ test.beforeEach(async ({ page }) => { await ViewerPage.init(page); }); -const multipleBoardsFileId = "dd5cc0bb-91ff-81b9-8004-77df9cd3edb0"; -const multipleBoardsPageId = "dd5cc0bb-91ff-81b9-8004-77df9cd3edb3"; - const interactionBlocksChildFileId = "cc000000-0000-0000-0000-000000000001"; const interactionBlocksChildPageId = "cc000000-0000-0000-0000-000000000002"; @@ -45,20 +42,3 @@ test("Child click interaction works when parent has mouse-leave interaction", as await expect(viewer.page).toHaveURL(/index=0/, { timeout: 5000 }); }); - -test("Navigate with arrows", async ({ page }) => { - const viewer = new ViewerPage(page); - await viewer.setupLoggedInUser(); - await viewer.setupFileWithMultipleBoards(viewer); - - await viewer.goToViewer({ - fileId: multipleBoardsFileId, - pageId: multipleBoardsPageId, - }); - - const nextButton = viewer.page.getByRole("button", { - name: "Next", - }); - await nextButton.click(); - await expect(viewer.page).toHaveURL(/&index=1/); -}); diff --git a/frontend/playwright/ui/specs/viewer-header.spec.js b/frontend/playwright/ui/specs/viewer-header.spec.js index 805d31c66e..1cb3126f13 100644 --- a/frontend/playwright/ui/specs/viewer-header.spec.js +++ b/frontend/playwright/ui/specs/viewer-header.spec.js @@ -8,35 +8,41 @@ test.beforeEach(async ({ page }) => { const singleBoardFileId = "dd5cc0bb-91ff-81b9-8004-77df9cd3edb1"; const singleBoardPageId = "dd5cc0bb-91ff-81b9-8004-77df9cd3edb2"; -test("Clips link area of the logo", async ({ page }) => { +// The zoom menu needs a board, so the header test runs on the single-board +// fixture. The logo hit area holds on either fixture. +test("The viewer header keeps its hit area and its zoom menu", async ({ + page, +}) => { const viewerPage = new ViewerPage(page); await viewerPage.setupLoggedInUser(); - await viewerPage.setupEmptyFile(); - - await viewerPage.goToViewer(); - - const viewerUrl = page.url(); - - const logoLink = viewerPage.page.getByTestId("penpot-logo-link"); - await expect(logoLink).toBeVisible(); - - const { x, y } = await logoLink.boundingBox(); - await viewerPage.page.mouse.click(x, y + 100); - await expect(page.url()).toBe(viewerUrl); -}); - -test("Updates URL with zoom type", async ({ page }) => { - const viewer = new ViewerPage(page); - await viewer.setupLoggedInUser(); - await viewer.setupFileWithSingleBoard(viewer); - - await viewer.goToViewer({ + await viewerPage.setupFileWithSingleBoard(); + await viewerPage.goToViewer({ fileId: singleBoardFileId, pageId: singleBoardPageId, }); - await viewer.page.getByTitle("Zoom").click(); - await viewer.page.getByText(/Fit/).click(); + await test.step("the logo hit area ends at the logo", async () => { + const logoLink = page.getByTestId("penpot-logo-link"); + await expect(logoLink).toBeVisible(); - await expect(viewer.page).toHaveURL(/&zoom=fit/); + // Navigating is a potok side effect that lands after the click, so a URL + // assertion could still match the old URL. Probe the point under the logo + // instead: a hit area that leaks there would navigate. + const { x, y } = await logoLink.boundingBox(); + const hitsLogo = await page.evaluate( + ([px, py]) => + !!document + .elementFromPoint(px, py) + ?.closest('[data-testid="penpot-logo-link"]'), + [x, y + 100], + ); + expect(hitsLogo).toBe(false); + }); + + await test.step("zoom to fit updates the URL", async () => { + await page.getByTitle("Zoom").click(); + await page.getByText(/Fit/).click(); + + await expect(page).toHaveURL(/&zoom=fit/); + }); }); diff --git a/frontend/playwright/ui/specs/workspace-assets-add-typography.spec.js b/frontend/playwright/ui/specs/workspace-assets-add-typography.spec.js index b9639cb7a0..06304ed12b 100644 --- a/frontend/playwright/ui/specs/workspace-assets-add-typography.spec.js +++ b/frontend/playwright/ui/specs/workspace-assets-add-typography.spec.js @@ -4,8 +4,8 @@ import { WorkspacePage } from "../pages/WorkspacePage"; // --------------------------------------------------------------------------- // The "Add typography" button in the local library typographies section // (src/app/main/ui/workspace/sidebar/assets/typographies.cljs) creates a -// typography from the selected text. It is disabled, and its label explains -// why, when: +// typography from the selected text. Its aria-label changes and the button is +// disabled when: // - the selected text uses a font that is not installed // - two or more texts are selected // --------------------------------------------------------------------------- @@ -17,35 +17,41 @@ function addTypographyButton(workspace, name) { }); } -test.beforeEach(async ({ page }) => { +// The text shape uses a custom team font-id, and the get-font-variants mock +// decides whether that font is installed or missing. +const CUSTOM_FONTS_FILE = { + id: "434b0541-fa2f-802f-8006-59827d964a9b", + pageId: "434b0541-fa2f-802f-8006-59827d964a9c", +}; + +// Two text shapes that share the same built-in font, so only the selection +// count changes between the two states. +const MULTIPLE_SELECTION_FILE = { + id: "434b0541-fa2f-802f-8006-6a827d964a9b", + pageId: "434b0541-fa2f-802f-8006-6a827d964a9c", +}; + +test("The font of the selected text decides the button", async ({ page }) => { await WorkspacePage.init(page); -}); -test.describe("font of the selected text", () => { - // render-wasm/get-file-text-custom-fonts.json has a text shape - // ("Penpot & Dragons") using a custom team font-id. The get-font-variants - // mock decides whether that font is installed or missing. - const FILE = { - id: "434b0541-fa2f-802f-8006-59827d964a9b", - pageId: "434b0541-fa2f-802f-8006-59827d964a9c", - }; + const workspace = new WorkspacePage(page); + await workspace.setupEmptyFile(); + await workspace.mockRPC( + /get\-file\?/, + "render-wasm/get-file-text-custom-fonts.json", + ); - test("Add typography is enabled when the selected text font is installed", async ({ - 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 installed", async () => { await workspace.mockRPC( "get-font-variants?team-id=*", "render-wasm/get-font-variants-custom-fonts.json", ); - await workspace.goToWorkspace({ fileId: FILE.id, pageId: FILE.pageId }); + await workspace.goToWorkspace({ + fileId: CUSTOM_FONTS_FILE.id, + pageId: CUSTOM_FONTS_FILE.pageId, + }); - await workspace.clickLeafLayer("Penpot & Dragons"); + await workspace.selectLayer("Penpot & Dragons"); await workspace.clickAssets(); await expect( @@ -53,22 +59,18 @@ test.describe("font of the selected text", () => { ).toBeEnabled(); }); - test("Add typography is disabled when the selected text font is missing", async ({ - 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 last matching route wins, and the reload fetches the variants again. await workspace.mockRPC( "get-font-variants?team-id=*", "workspace/get-font-variants-empty.json", ); - await workspace.goToWorkspace({ fileId: FILE.id, pageId: FILE.pageId }); - - await workspace.clickLeafLayer("Penpot & Dragons"); + // The reload keeps the Assets tab, where the sitemap page name is not + // rendered, so the method settles on the canvas instead. + await workspace.reloadWorkspace({ waitForPageName: false }); + // The sidebar restores the Assets tab; the layer tree needs Layers. + await workspace.clickLayers(); + await workspace.selectLayer("Penpot & Dragons"); await workspace.clickAssets(); await expect( @@ -77,27 +79,32 @@ test.describe("font of the selected text", () => { }); }); -test.describe("number of selected texts", () => { - // workspace/get-file-text-multiple-selection.json has two text shapes that - // use the same built-in font, so only the selection count changes. - const FILE = { - id: "434b0541-fa2f-802f-8006-6a827d964a9b", - pageId: "434b0541-fa2f-802f-8006-6a827d964a9c", - }; +test("The number of selected texts decides the button", async ({ page }) => { + await WorkspacePage.init(page); - test("Add typography is disabled when two texts are selected", async ({ - page, - }) => { - const workspace = new WorkspacePage(page); - await workspace.setupEmptyFile(); - await workspace.mockRPC( - /get\-file\?/, - "workspace/get-file-text-multiple-selection.json", - ); - await workspace.goToWorkspace({ fileId: FILE.id, pageId: FILE.pageId }); + const workspace = new WorkspacePage(page); + await workspace.setupEmptyFile(); + await workspace.mockRPC( + /get\-file\?/, + "workspace/get-file-text-multiple-selection.json", + ); + await workspace.goToWorkspace({ + fileId: MULTIPLE_SELECTION_FILE.id, + pageId: MULTIPLE_SELECTION_FILE.pageId, + }); - await workspace.clickLeafLayer("Text multiple selection one"); - await workspace.clickLeafLayer("Text multiple selection two", { + await test.step("one text", async () => { + await workspace.selectLayer("Text multiple selection one"); + await workspace.clickAssets(); + + await expect( + addTypographyButton(workspace, "Add typography"), + ).toBeEnabled(); + }); + + await test.step("two texts", async () => { + await workspace.clickLayers(); + await workspace.selectLayer("Text multiple selection two", { modifiers: ["Shift"], }); await workspace.clickAssets(); @@ -109,23 +116,4 @@ test.describe("number of selected texts", () => { ), ).toBeDisabled(); }); - - test("Add typography is enabled when one text is selected", async ({ - page, - }) => { - const workspace = new WorkspacePage(page); - await workspace.setupEmptyFile(); - await workspace.mockRPC( - /get\-file\?/, - "workspace/get-file-text-multiple-selection.json", - ); - await workspace.goToWorkspace({ fileId: FILE.id, pageId: FILE.pageId }); - - await workspace.clickLeafLayer("Text multiple selection one"); - await workspace.clickAssets(); - - await expect( - addTypographyButton(workspace, "Add typography"), - ).toBeEnabled(); - }); }); diff --git a/frontend/src/app/main/ui/dashboard/fonts.cljs b/frontend/src/app/main/ui/dashboard/fonts.cljs index b42014ffba..ab981958c4 100644 --- a/frontend/src/app/main/ui/dashboard/fonts.cljs +++ b/frontend/src/app/main/ui/dashboard/fonts.cljs @@ -213,6 +213,7 @@ [:> button* {:variant "primary" :type "button" :class (stl/css :add-font-button) + :data-testid "add-custom-font" :on-click on-click} (tr "labels.add-custom-font") [:& file-uploader {:input-id "font-upload" diff --git a/frontend/test/frontend_tests/data/viewer_test.cljs b/frontend/test/frontend_tests/data/viewer_test.cljs index 94f43904b2..90669aa1bf 100644 --- a/frontend/test/frontend_tests/data/viewer_test.cljs +++ b/frontend/test/frontend_tests/data/viewer_test.cljs @@ -11,6 +11,7 @@ [app.main.router :as rt] [beicon.v2.core :as rx] [cljs.test :as t] + [frontend-tests.helpers.async :as async] [potok.v2.core :as ptk])) (def ^:private page-id @@ -70,12 +71,12 @@ (t/is (= (get-in result [:viewer-local :zoom-type]) :fill)) (t/is (number? (get-in result [:viewer-local :zoom])))))) -(defn- watch-events - "Collect the events an event's watch emits synchronously." +(defn ^:async watch-events + "Collect the events a watch emits, waiting for its stream to terminate." [event state] (let [out (atom [])] - (some-> (ptk/watch event state nil) - (rx/subscribe #(swap! out conj %))) + (await (async/observe (or (ptk/watch event state nil) (rx/empty)) + :on-next #(swap! out conj %))) @out)) (defn- zoom-state @@ -88,19 +89,19 @@ (some? zoom-type) (assoc :zoom-type zoom-type))}) -(t/deftest update-zoom-querystring-does-not-navigate-when-url-already-matches +(t/deftest ^:async update-zoom-querystring-does-not-navigate-when-url-already-matches (t/testing "zoom type already described by the query string" - (t/is (empty? (watch-events dv/update-zoom-querystring - (zoom-state "fit" :fit))))) + (t/is (empty? (await (watch-events dv/update-zoom-querystring + (zoom-state "fit" :fit)))))) (t/testing "no zoom type and no zoom query param" - (t/is (empty? (watch-events dv/update-zoom-querystring - (zoom-state nil nil)))))) + (t/is (empty? (await (watch-events dv/update-zoom-querystring + (zoom-state nil nil))))))) -(t/deftest update-zoom-querystring-navigates-when-zoom-changes +(t/deftest ^:async update-zoom-querystring-navigates-when-zoom-changes (t/testing "zoom type differs from the query string" - (let [events (watch-events dv/update-zoom-querystring - (zoom-state "fit" :fill)) + (let [events (await (watch-events dv/update-zoom-querystring + (zoom-state "fit" :fill))) {:keys [id params options]} (some-> (first events) deref)] (t/is (= 1 (count events))) (t/is (= :viewer id)) @@ -108,8 +109,8 @@ (t/is (true? (::rt/replace options))))) (t/testing "zoom query param absent, other params preserved" - (let [events (watch-events dv/update-zoom-querystring - (zoom-state nil :fit)) + (let [events (await (watch-events dv/update-zoom-querystring + (zoom-state nil :fit))) {:keys [params]} (some-> (first events) deref)] (t/is (= 1 (count events))) (t/is (= :fit (:zoom params))) @@ -117,13 +118,13 @@ (t/is (= "0" (:index params))))) (t/testing "zoom type cleared drops the query param" - (let [events (watch-events dv/update-zoom-querystring - (zoom-state "fit" nil)) + (let [events (await (watch-events dv/update-zoom-querystring + (zoom-state "fit" nil))) {:keys [params]} (some-> (first events) deref)] (t/is (= 1 (count events))) (t/is (not (contains? params :zoom)))))) -(t/deftest bundle-fetched-with-zoom-fill-url-does-not-navigate +(t/deftest ^:async bundle-fetched-with-zoom-fill-url-does-not-navigate ;; Regression test for the React "maximum update depth exceeded" ;; error (2.18.0-RC5): loading the viewer with a URL that already ;; contains `zoom=fill` re-entered the cycle zoom-to-fill → @@ -138,18 +139,18 @@ (-> state (assoc-in [:route :params :query] query) (assoc-in [:route :query-params] query))))] - (let [events (watch-events (dv/bundle-fetched - {:file {:id page-id - :data {:pages [page-id] - :pages-index {page-id {:objects {}}}}} - :project {} - :team {:features []} - :share-links [] - :libraries [] - :users [] - :permissions {} - :thumbnails {}}) - state) + (let [events (await (watch-events (dv/bundle-fetched + {:file {:id page-id + :data {:pages [page-id] + :pages-index {page-id {:objects {}}}}} + :project {} + :team {:features []} + :share-links [] + :libraries [] + :users [] + :permissions {} + :thumbnails {}}) + state)) ;; `update-page-position-data` and `go-to-frame-auto` are part ;; of the normal init sequence; the navigation events are the ;; ones that can restart the zoom cycle. @@ -174,21 +175,21 @@ (let [query {:file-id (str (uuid/custom 2 2)) :section "interactions" :index "0"}] {:route {:params {:query query} :query-params query}})) -(t/deftest initialize-without-page-id-fetches-the-bundle +(t/deftest ^:async initialize-without-page-id-fetches-the-bundle ;; The viewer route passes `:page-id nil` when the URL has none; the ;; params check used to reject it before any fetch. - (let [events (watch-events (dv/initialize {:file-id (uuid/custom 2 2) - :page-id nil - :share-id nil}) - {})] + (let [events (await (watch-events (dv/initialize {:file-id (uuid/custom 2 2) + :page-id nil + :share-id nil}) + {}))] (t/is (= [::dv/fetch-bundle] (map ptk/type (remove nil? events)))))) -(t/deftest bundle-fetched-without-page-id-names-the-first-page +(t/deftest ^:async bundle-fetched-without-page-id-names-the-first-page (t/testing "the route is replaced by one naming the first page" (let [first-page (uuid/custom 3 1) - events (watch-events (dv/bundle-fetched - (minimal-bundle [first-page (uuid/custom 3 2)])) - (route-without-page-id)) + events (await (watch-events (dv/bundle-fetched + (minimal-bundle [first-page (uuid/custom 3 2)])) + (route-without-page-id))) {:keys [id params options]} (some-> (first events) deref)] (t/is (= 1 (count events))) (t/is (= :viewer id)) @@ -197,7 +198,39 @@ (t/is (true? (::rt/replace options))))) (t/testing "a file without pages keeps the route" - (let [events (watch-events (dv/bundle-fetched (minimal-bundle [])) - (route-without-page-id)) + (let [events (await (watch-events (dv/bundle-fetched (minimal-bundle [])) + (route-without-page-id))) navigations (filter #(= :app.main.router/navigate (ptk/type %)) events)] (t/is (empty? navigations))))) + +;; --- Frame navigation ------------------------------------------------------ +;; The viewer arrows emit `close-thread` and a navigation to the next or +;; previous index, and nothing at the ends of the sequence. + +(t/deftest ^:async select-next-frame-navigates-to-the-next-frame + (let [events (await (watch-events dv/select-next-frame + (base-state {:frames [{} {} {}] :index 1}))) + {:keys [id params]} (some-> (second events) deref)] + (t/is (= 2 (count events))) + (t/is (= :app.main.data.comments/close-comment-thread (ptk/type (first events)))) + (t/is (= :viewer id)) + (t/is (= 2 (:index params))) + (t/is (= (str page-id) (:page-id params))))) + +(t/deftest ^:async select-next-frame-stays-on-the-last-frame + (t/is (empty? (await (watch-events dv/select-next-frame + (base-state {:frames [{} {} {}] :index 2})))))) + +(t/deftest ^:async select-prev-frame-navigates-to-the-previous-frame + (let [events (await (watch-events dv/select-prev-frame + (base-state {:frames [{} {} {}] :index 1}))) + {:keys [id params]} (some-> (second events) deref)] + (t/is (= 2 (count events))) + (t/is (= :app.main.data.comments/close-comment-thread (ptk/type (first events)))) + (t/is (= :viewer id)) + (t/is (= 0 (:index params))) + (t/is (= (str page-id) (:page-id params))))) + +(t/deftest ^:async select-prev-frame-stays-on-the-first-frame + (t/is (empty? (await (watch-events dv/select-prev-frame + (base-state {:frames [{} {} {}] :index 0})))))) diff --git a/frontend/test/frontend_tests/ui/routes_test.cljs b/frontend/test/frontend_tests/ui/routes_test.cljs index 08c2203187..24a49a2c5a 100644 --- a/frontend/test/frontend_tests/ui/routes_test.cljs +++ b/frontend/test/frontend_tests/ui/routes_test.cljs @@ -157,3 +157,34 @@ (swap! storage/session dissoc :template)) (done')) done)))) + +;; --- Legacy hash table ----------------------------------------------------- +;; The router built from `legacy-routes` is a `defonce`, so its entries are +;; fixed when the namespace loads. These tests only reach the unconditional +;; ones; a flag cannot add or remove routes here. + +(t/deftest legacy-match-resolves-a-top-level-path + (let [match (#'routes/legacy-match "/auth/login")] + (t/is (= :auth-login (:name match))) + (t/is (= {} (:params match))))) + +(t/deftest legacy-match-resolves-a-nested-path + (let [match (#'routes/legacy-match "/dashboard/files")] + (t/is (= :dashboard-files (:name match))) + (t/is (= {} (:params match))))) + +(t/deftest legacy-match-keeps-the-query-string-params + (let [team-id (str (uuid/next)) + match (#'routes/legacy-match (str "/workspace?team-id=" team-id))] + (t/is (= :workspace (:name match))) + (t/is (= team-id (:team-id (:params match)))))) + +(t/deftest legacy-match-returns-nil-for-an-unknown-path + (t/is (nil? (#'routes/legacy-match "/nope")))) + +(t/deftest legacy-match-keeps-the-path-params + ;; /render-sprite is the only legacy route with a path param. + (let [file-id (str (uuid/next)) + match (#'routes/legacy-match (str "/render-sprite/" file-id))] + (t/is (= :render-sprite (:name match))) + (t/is (= file-id (:file-id (:params match))))))