Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

perf(tools): mount tool picker categories as they near the viewport (#8234)

brios2db61b1006d2
diff --git a/frontend/editor/src/core/components/onboarding/tourUtils.test.ts b/frontend/editor/src/core/components/onboarding/tourUtils.test.ts
new file mode 100644
index 0000000000..6709d8fc87
--- /dev/null
+++ b/frontend/editor/src/core/components/onboarding/tourUtils.test.ts
@@ -0,0 +1,142 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import {
+ revealPickerTool,
+ waitForElement,
+ waitForHighlightable,
+} from "@app/components/onboarding/tourUtils";
+
+describe("tourUtils", () => {
+ beforeEach(() => {
+ document.body.innerHTML = "";
+ vi.useRealTimers();
+ });
+
+ afterEach(() => {
+ document.body.innerHTML = "";
+ });
+
+ describe("waitForElement", () => {
+ it("resolves immediately when the element already exists", async () => {
+ const el = document.createElement("div");
+ el.id = "target";
+ document.body.appendChild(el);
+
+ await expect(waitForElement("#target", 500)).resolves.toBeUndefined();
+ });
+
+ it("resolves when the element is added later", async () => {
+ const promise = waitForElement("#target", 1000);
+
+ setTimeout(() => {
+ const el = document.createElement("div");
+ el.id = "target";
+ document.body.appendChild(el);
+ }, 50);
+
+ await expect(promise).resolves.toBeUndefined();
+ });
+
+ it("resolves after timeout without throwing", async () => {
+ await expect(waitForElement("#missing", 50)).resolves.toBeUndefined();
+ });
+ });
+
+ describe("waitForHighlightable", () => {
+ it("resolves immediately when element has layout dimensions", async () => {
+ const el = document.createElement("div");
+ el.id = "target";
+ vi.spyOn(el, "getClientRects").mockReturnValue([
+ { width: 100, height: 40 } as DOMRect,
+ ] as unknown as DOMRectList);
+ document.body.appendChild(el);
+
+ const resizeSpy = vi.fn();
+ window.addEventListener("resize", resizeSpy);
+
+ await waitForHighlightable("#target", 500);
+
+ expect(resizeSpy).toHaveBeenCalled();
+ window.removeEventListener("resize", resizeSpy);
+ });
+
+ it("resolves after timeout if element never receives dimensions", async () => {
+ const el = document.createElement("div");
+ el.id = "target";
+ vi.spyOn(el, "getClientRects").mockReturnValue(
+ [] as unknown as DOMRectList,
+ );
+ document.body.appendChild(el);
+
+ await expect(
+ waitForHighlightable("#target", 50),
+ ).resolves.toBeUndefined();
+ });
+ });
+
+ describe("revealPickerTool", () => {
+ it("scrolls into view and resolves if element already exists and has layout", async () => {
+ const el = document.createElement("div");
+ el.setAttribute("data-tour", "tool-button-crop");
+ const scrollIntoViewSpy = vi.fn();
+ el.scrollIntoView = scrollIntoViewSpy;
+ vi.spyOn(el, "getClientRects").mockReturnValue([
+ { width: 80, height: 32 } as DOMRect,
+ ] as unknown as DOMRectList);
+ document.body.appendChild(el);
+
+ await revealPickerTool('[data-tour="tool-button-crop"]', 500);
+
+ expect(scrollIntoViewSpy).toHaveBeenCalledWith({
+ block: "center",
+ behavior: "smooth",
+ });
+ });
+
+ it("scrolls the .tool-picker-scrollable container until the lazy element mounts", async () => {
+ const scroller = document.createElement("div");
+ scroller.className = "tool-picker-scrollable";
+ Object.defineProperty(scroller, "clientHeight", {
+ value: 300,
+ configurable: true,
+ });
+ Object.defineProperty(scroller, "scrollHeight", {
+ value: 1200,
+ configurable: true,
+ });
+ scroller.scrollTop = 0;
+ document.body.appendChild(scroller);
+
+ let scrollCount = 0;
+ scroller.addEventListener("scroll", () => {
+ scrollCount += 1;
+ if (scrollCount === 2) {
+ const button = document.createElement("button");
+ button.setAttribute("data-tour", "tool-button-crop");
+ button.scrollIntoView = vi.fn();
+ vi.spyOn(button, "getClientRects").mockReturnValue([
+ { width: 80, height: 32 } as DOMRect,
+ ] as unknown as DOMRectList);
+ scroller.appendChild(button);
+ }
+ });
+
+ await revealPickerTool('[data-tour="tool-button-crop"]', 1000);
+
+ const mountedButton = document.querySelector(
+ '[data-tour="tool-button-crop"]',
+ );
+ expect(mountedButton).not.toBeNull();
+ expect(mountedButton?.scrollIntoView).toHaveBeenCalledWith({
+ block: "center",
+ behavior: "smooth",
+ });
+ expect(scrollCount).toBeGreaterThanOrEqual(2);
+ });
+
+ it("handles absence of .tool-picker-scrollable gracefully without throwing", async () => {
+ await expect(
+ revealPickerTool('[data-tour="tool-button-crop"]', 50),
+ ).resolves.toBeUndefined();
+ });
+ });
+});
diff --git a/frontend/editor/src/core/components/onboarding/tourUtils.ts b/frontend/editor/src/core/components/onboarding/tourUtils.ts
index e6d8828d39..370e38107c 100644
--- a/frontend/editor/src/core/components/onboarding/tourUtils.ts
+++ b/frontend/editor/src/core/components/onboarding/tourUtils.ts
@@ -40,6 +40,63 @@ const nudgeReactour = () => {
requestAnimationFrame(() => window.dispatchEvent(new Event("resize")));
};
+/**
+ * Scrolls the tool picker until a target tool button appears and is highlighted.
+ * Because tool picker sections are lazily mounted when scrolled near the viewport,
+ * offscreen tools like Crop do not exist in the DOM until scrolled towards.
+ */
+export async function revealPickerTool(
+ selector: string,
+ timeoutMs = 7000,
+): Promise<void> {
+ if (typeof document === "undefined") {
+ return;
+ }
+
+ const existing = document.querySelector<HTMLElement>(selector);
+ if (existing && existing.getClientRects().length > 0) {
+ existing.scrollIntoView({ block: "center", behavior: "smooth" });
+ await waitForHighlightable(selector, timeoutMs);
+ return;
+ }
+
+ const scroller = document.querySelector<HTMLElement>(
+ ".tool-picker-scrollable",
+ );
+ if (scroller) {
+ const stepDelta = Math.max(scroller.clientHeight * 0.8, 300);
+ const maxSteps = 20;
+
+ for (let step = 0; step < maxSteps; step += 1) {
+ const found = document.querySelector<HTMLElement>(selector);
+ if (found) {
+ found.scrollIntoView({ block: "center", behavior: "smooth" });
+ await waitForHighlightable(selector, timeoutMs);
+ return;
+ }
+
+ if (scroller.scrollTop + scroller.clientHeight >= scroller.scrollHeight) {
+ break;
+ }
+
+ scroller.scrollTop = Math.min(
+ scroller.scrollTop + stepDelta,
+ scroller.scrollHeight,
+ );
+ scroller.dispatchEvent(new Event("scroll"));
+
+ await new Promise((resolve) => setTimeout(resolve, 50));
+ }
+ }
+
+ const finalFound = document.querySelector<HTMLElement>(selector);
+ if (finalFound) {
+ finalFound.scrollIntoView({ block: "center", behavior: "smooth" });
+ }
+
+ await waitForHighlightable(selector, timeoutMs);
+}
+
/**
* Waits for a CSS selector to be present AND have a non-zero bounding box,
* then nudges Reactour to recalculate its spotlight position.
diff --git a/frontend/editor/src/core/components/onboarding/userStepsConfig.ts b/frontend/editor/src/core/components/onboarding/userStepsConfig.ts
index 85281e712e..c23f1fa5e3 100644
--- a/frontend/editor/src/core/components/onboarding/userStepsConfig.ts
+++ b/frontend/editor/src/core/components/onboarding/userStepsConfig.ts
@@ -1,6 +1,7 @@
import type { StepType } from "@reactour/tour";
import type { TFunction } from "i18next";
import {
+ revealPickerTool,
waitForElement,
waitForHighlightable,
} from "@app/components/onboarding/tourUtils";
@@ -84,6 +85,9 @@ export function createUserStepsConfig({
),
position: "right",
padding: 0,
+ action: async () => {
+ await revealPickerTool('[data-tour="tool-button-crop"]');
+ },
actionAfter: () => selectCropTool(),
},
[TourStep.TOOL_INTERFACE]: {
diff --git a/frontend/editor/src/core/components/tools/ToolPicker.tsx b/frontend/editor/src/core/components/tools/ToolPicker.tsx
index c6561ee7ea..b16ff7d879 100644
--- a/frontend/editor/src/core/components/tools/ToolPicker.tsx
+++ b/frontend/editor/src/core/components/tools/ToolPicker.tsx
@@ -1,4 +1,4 @@
-import React, { useMemo } from "react";
+import React, { useMemo, useRef } from "react";
import { Box, Stack } from "@mantine/core";
import { useTranslation } from "react-i18next";
import { Button } from "@app/ui/Button";
@@ -10,6 +10,7 @@ import { useFavoriteToolItems } from "@app/hooks/tools/useFavoriteToolItems";
import NoToolsFound from "@app/components/tools/shared/NoToolsFound";
import { renderToolButtons } from "@app/components/tools/shared/renderToolButtons";
import ToolButton from "@app/components/tools/toolPicker/ToolButton";
+import { LazyToolSection } from "@app/components/tools/toolPicker/LazyToolSection";
import { useToolWorkflowData } from "@app/contexts/ToolWorkflowContext";
import { useIsScrolled } from "@app/hooks/useIsScrolled";
import { ToolId } from "@app/types/toolId";
@@ -72,6 +73,9 @@ const ToolPicker = ({
const { t } = useTranslation();
const { scrolled, scrollRef } = useIsScrolled();
+ // The lazy sections observe against the scroller itself, so they need a
+ // stable ref alongside the callback ref that drives the header divider.
+ const scrollerRef = useRef<HTMLDivElement | null>(null);
const { sections: visibleSections } = useToolSections(filteredTools);
const { favoriteTools, toolRegistry } = useToolWorkflowData();
@@ -112,7 +116,10 @@ const ToolPicker = ({
</div>
)}
<Box
- ref={scrollRef}
+ ref={(el: HTMLDivElement | null) => {
+ scrollerRef.current = el;
+ return scrollRef(el);
+ }}
style={SCROLLABLE_STYLE}
className="tool-picker-scrollable"
>
@@ -230,21 +237,30 @@ const ToolPicker = ({
)}
{allSection &&
allSection.subcategories.map((sc: SubcategoryGroup) => (
- <Box key={sc.subcategoryId} w="100%">
- <div style={HEADER_TEXT_STYLE}>
- {toTitleCase(getSubcategoryLabel(t, sc.subcategoryId))}
- </div>
- {renderToolButtons(
- t,
- sc,
- selectedToolKey,
- onSelect,
- false,
- false,
- undefined,
- true,
+ <LazyToolSection
+ key={sc.subcategoryId}
+ estimatedHeight={32 + sc.tools.length * 44}
+ scrollRoot={scrollerRef}
+ label={toTitleCase(
+ getSubcategoryLabel(t, sc.subcategoryId),
)}
- </Box>
+ >
+ <Box w="100%">
+ <div style={HEADER_TEXT_STYLE}>
+ {toTitleCase(getSubcategoryLabel(t, sc.subcategoryId))}
+ </div>
+ {renderToolButtons(
+ t,
+ sc,
+ selectedToolKey,
+ onSelect,
+ false,
+ false,
+ undefined,
+ true,
+ )}
+ </Box>
+ </LazyToolSection>
))}
</Stack>
diff --git a/frontend/editor/src/core/components/tools/toolPicker/LazyToolSection.test.tsx b/frontend/editor/src/core/components/tools/toolPicker/LazyToolSection.test.tsx
new file mode 100644
index 0000000000..8cd0e5f330
--- /dev/null
+++ b/frontend/editor/src/core/components/tools/toolPicker/LazyToolSection.test.tsx
@@ -0,0 +1,156 @@
+import {
+ act,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from "@testing-library/react";
+import { MantineProvider } from "@mantine/core";
+import { createRef } from "react";
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
+
+import { LazyToolSection } from "@app/components/tools/toolPicker/LazyToolSection";
+
+class MockIntersectionObserver {
+ static instances: MockIntersectionObserver[] = [];
+ callback: IntersectionObserverCallback;
+ options?: IntersectionObserverInit;
+ observed: Element[] = [];
+ disconnected = false;
+ root = null;
+ rootMargin = "";
+ thresholds = [];
+
+ constructor(
+ callback: IntersectionObserverCallback,
+ options?: IntersectionObserverInit,
+ ) {
+ this.callback = callback;
+ this.options = options;
+ MockIntersectionObserver.instances.push(this);
+ }
+
+ observe(element: Element) {
+ this.observed.push(element);
+ }
+
+ disconnect() {
+ this.disconnected = true;
+ }
+
+ unobserve() {}
+
+ takeRecords(): IntersectionObserverEntry[] {
+ return [];
+ }
+
+ intersect() {
+ this.callback(
+ [{ isIntersecting: true } as IntersectionObserverEntry],
+ this as unknown as IntersectionObserver,
+ );
+ }
+}
+
+function renderSection(estimatedHeight = 200) {
+ return render(
+ <MantineProvider>
+ <LazyToolSection estimatedHeight={estimatedHeight}>
+ <a href="#tool">Tool list</a>
+ </LazyToolSection>
+ </MantineProvider>,
+ );
+}
+
+describe("LazyToolSection", () => {
+ const originalIntersectionObserver = global.IntersectionObserver;
+
+ beforeEach(() => {
+ MockIntersectionObserver.instances = [];
+ global.IntersectionObserver =
+ MockIntersectionObserver as unknown as typeof IntersectionObserver;
+ });
+
+ afterEach(() => {
+ global.IntersectionObserver = originalIntersectionObserver;
+ });
+
+ it("holds the children back until the section intersects", () => {
+ const { container } = renderSection(240);
+
+ expect(screen.queryByText("Tool list")).not.toBeInTheDocument();
+ const placeholder = container.querySelector("div[style]") as HTMLElement;
+ expect(placeholder.style.minHeight).toBe("240px");
+ expect(MockIntersectionObserver.instances).toHaveLength(1);
+ });
+
+ it("mounts the children on intersection and stops observing", async () => {
+ renderSection();
+
+ await act(async () => {
+ MockIntersectionObserver.instances[0].intersect();
+ });
+
+ await waitFor(() => {
+ expect(screen.getByText("Tool list")).toBeInTheDocument();
+ });
+ expect(MockIntersectionObserver.instances[0].disconnected).toBe(true);
+ });
+
+ it("observes against the given scroll root", () => {
+ const rootRef = createRef<HTMLDivElement>();
+ render(
+ <MantineProvider>
+ <div ref={rootRef}>
+ <LazyToolSection estimatedHeight={100} scrollRoot={rootRef}>
+ <a href="#tool">Tool list</a>
+ </LazyToolSection>
+ </div>
+ </MantineProvider>,
+ );
+
+ expect(MockIntersectionObserver.instances[0].options?.root).toBe(
+ rootRef.current,
+ );
+ });
+
+ it("mounts on placeholder focus and moves focus into the section", async () => {
+ const { container } = renderSection();
+ const placeholder = container.querySelector(
+ '[role="button"]',
+ ) as HTMLElement;
+
+ await act(async () => {
+ fireEvent.focus(placeholder);
+ });
+
+ await waitFor(() => {
+ expect(screen.getByText("Tool list")).toBeInTheDocument();
+ });
+ expect(document.activeElement).toBe(screen.getByText("Tool list"));
+ });
+
+ it("mounts on placeholder click", async () => {
+ const { container } = renderSection();
+ const placeholder = container.querySelector(
+ '[role="button"]',
+ ) as HTMLElement;
+
+ await act(async () => {
+ fireEvent.click(placeholder);
+ });
+
+ await waitFor(() => {
+ expect(screen.getByText("Tool list")).toBeInTheDocument();
+ });
+ });
+
+ it("mounts immediately when IntersectionObserver is unavailable", () => {
+ global.IntersectionObserver =
+ undefined as unknown as typeof IntersectionObserver;
+
+ renderSection();
+
+ expect(screen.getByText("Tool list")).toBeInTheDocument();
+ });
+});
diff --git a/frontend/editor/src/core/components/tools/toolPicker/LazyToolSection.tsx b/frontend/editor/src/core/components/tools/toolPicker/LazyToolSection.tsx
new file mode 100644
index 0000000000..b70bdcfa0f
--- /dev/null
+++ b/frontend/editor/src/core/components/tools/toolPicker/LazyToolSection.tsx
@@ -0,0 +1,87 @@
+import {
+ useEffect,
+ useRef,
+ useState,
+ type ReactNode,
+ type RefObject,
+} from "react";
+import { Box } from "@mantine/core";
+
+interface LazyToolSectionProps {
+ /** Rendered height reserved until the real content mounts, so the scrollbar stays put. */
+ estimatedHeight: number;
+ children: ReactNode;
+ /**
+ * The picker's scroll container. Its clip bounds the observer, so a viewport
+ * root would ignore the prefetch margin and mount sections only on sight.
+ */
+ scrollRoot?: RefObject<HTMLElement | null>;
+ /** Named on the keyboard placeholder so the revealed section has context. */
+ label?: string;
+}
+
+/**
+ * Mounts its children once the section comes near the picker viewport.
+ * The picker renders every category eagerly otherwise, which is most of the
+ * DOM on a page that may only show a couple of categories at a time. The
+ * placeholder is focusable so sequential Tab still reaches every section.
+ */
+export function LazyToolSection({
+ estimatedHeight,
+ children,
+ scrollRoot,
+ label,
+}: LazyToolSectionProps) {
+ const ref = useRef<HTMLDivElement>(null);
+ const [mounted, setMounted] = useState(false);
+ const focusOnMountRef = useRef(false);
+
+ useEffect(() => {
+ if (mounted) return;
+ const node = ref.current;
+ if (!node || typeof IntersectionObserver === "undefined") {
+ setMounted(true);
+ return;
+ }
+ const observer = new IntersectionObserver(
+ (entries) => {
+ if (entries.some((entry) => entry.isIntersecting)) {
+ setMounted(true);
+ observer.disconnect();
+ }
+ },
+ { root: scrollRoot?.current ?? null, rootMargin: "300px 0px" },
+ );
+ observer.observe(node);
+ return () => observer.disconnect();
+ }, [mounted, scrollRoot]);
+
+ useEffect(() => {
+ if (!mounted || !focusOnMountRef.current) return;
+ focusOnMountRef.current = false;
+ ref.current?.querySelector<HTMLElement>("a, button, [tabindex]")?.focus();
+ }, [mounted]);
+
+ return (
+ <Box
+ ref={ref}
+ w="100%"
+ style={mounted ? undefined : { minHeight: estimatedHeight }}
+ >
+ {mounted ? (
+ children
+ ) : (
+ <div
+ role="button"
+ tabIndex={0}
+ aria-label={label}
+ onClick={() => setMounted(true)}
+ onFocus={() => {
+ focusOnMountRef.current = true;
+ setMounted(true);
+ }}
+ />
+ )}
+ </Box>
+ );
+}
diff --git a/frontend/editor/src/core/tests/helpers/ui-helpers.ts b/frontend/editor/src/core/tests/helpers/ui-helpers.ts
index 85577fc890..6cf76cb9ea 100644
--- a/frontend/editor/src/core/tests/helpers/ui-helpers.ts
+++ b/frontend/editor/src/core/tests/helpers/ui-helpers.ts
@@ -189,3 +189,33 @@ export async function dismissTourTooltip(page: Page): Promise<void> {
await closeBtn.click();
}
}
+
+/**
+ * The tool picker mounts categories when they come near its viewport, so an
+ * offscreen tile or header is not in the DOM yet. Scroll the picker in steps
+ * until the target exists, then return it. No-op when it is already mounted.
+ */
+export async function revealInPicker(
+ page: Page,
+ target: Locator,
+): Promise<Locator> {
+ const scroller = page.locator(".tool-picker-scrollable").first();
+ for (let step = 0; step < 20 && (await target.count()) === 0; step += 1) {
+ await scroller.evaluate((el) => {
+ el.scrollTop = Math.min(el.scrollTop + el.clientHeight, el.scrollHeight);
+ });
+ await page.waitForTimeout(150);
+ }
+ return target;
+}
+
+/** Reveal a tool tile by its tool id, then return it. */
+export async function revealPickerTool(
+ page: Page,
+ toolId: string,
+): Promise<Locator> {
+ return revealInPicker(
+ page,
+ page.locator(`[data-tour="tool-button-${toolId}"]`),
+ );
+}
diff --git a/frontend/editor/src/core/tests/stubbed/auto-form-detection-walkthrough.spec.ts b/frontend/editor/src/core/tests/stubbed/auto-form-detection-walkthrough.spec.ts
index d3336072ec..4181acf227 100644
--- a/frontend/editor/src/core/tests/stubbed/auto-form-detection-walkthrough.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/auto-form-detection-walkthrough.spec.ts
@@ -1,5 +1,9 @@
import { test, expect } from "@app/tests/helpers/stub-test-base";
-import { SETTINGS_SURFACE, uploadFiles } from "@app/tests/helpers/ui-helpers";
+import {
+ SETTINGS_SURFACE,
+ revealPickerTool,
+ uploadFiles,
+} from "@app/tests/helpers/ui-helpers";
import type { Page, Route } from "@playwright/test";
import path from "node:path";
import fs from "node:fs";
@@ -174,9 +178,7 @@ for (const theme of THEMES) {
await applyTheme(page, theme);
await stubStatus(page);
await page.goto("/", { waitUntil: "domcontentloaded" });
- const tile = page
- .locator('[data-tour="tool-button-autoFormDetection"]')
- .first();
+ const tile = await revealPickerTool(page, "autoFormDetection");
await expect(tile).toBeVisible({ timeout: 15_000 });
await tile.scrollIntoViewIfNeeded();
await settle(page);
@@ -251,9 +253,7 @@ for (const theme of THEMES) {
r.fulfill({ json: disabledMap }),
);
await page.goto("/", { waitUntil: "domcontentloaded" });
- const tile = page
- .locator('[data-tour="tool-button-autoFormDetection"]')
- .first();
+ const tile = await revealPickerTool(page, "autoFormDetection");
await expect(tile).toBeVisible({ timeout: 15_000 });
await tile.scrollIntoViewIfNeeded();
await settle(page);
diff --git a/frontend/editor/src/core/tests/stubbed/auto-form-detection.spec.ts b/frontend/editor/src/core/tests/stubbed/auto-form-detection.spec.ts
index a88a14b032..b3d8060b0b 100644
--- a/frontend/editor/src/core/tests/stubbed/auto-form-detection.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/auto-form-detection.spec.ts
@@ -4,7 +4,10 @@ import {
mockAppApis,
seedCookieConsent,
} from "@app/tests/helpers/api-stubs";
-import { SETTINGS_SURFACE } from "@app/tests/helpers/ui-helpers";
+import {
+ SETTINGS_SURFACE,
+ revealPickerTool,
+} from "@app/tests/helpers/ui-helpers";
/**
* Stubbed coverage for the tool tile (shown even when the endpoint is disabled, so the tool stays
@@ -49,7 +52,7 @@ test.describe("Auto Form Detection tool", () => {
});
await page.goto("/");
- const tile = page.locator('[data-tour="tool-button-autoFormDetection"]');
+ const tile = await revealPickerTool(page, "autoFormDetection");
await expect(tile.first()).toBeVisible({ timeout: 10_000 });
});
@@ -64,10 +67,8 @@ test.describe("Auto Form Detection tool", () => {
});
await page.goto("/");
- await page
- .locator('[data-tour="tool-button-autoFormDetection"]')
- .first()
- .click();
+ const tile = await revealPickerTool(page, "autoFormDetection");
+ await tile.first().click();
await expect(page).toHaveURL(/auto-form-detection/i);
});
diff --git a/frontend/editor/src/core/tests/stubbed/convert.spec.ts b/frontend/editor/src/core/tests/stubbed/convert.spec.ts
index 52feefcb98..7ced09e372 100644
--- a/frontend/editor/src/core/tests/stubbed/convert.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/convert.spec.ts
@@ -8,7 +8,10 @@
import { test, expect, type Page } from "@playwright/test";
import path from "path";
import { mockAppApis } from "@app/tests/helpers/api-stubs";
-import { suppressNativeFilePicker } from "@app/tests/helpers/ui-helpers";
+import {
+ suppressNativeFilePicker,
+ revealPickerTool,
+} from "@app/tests/helpers/ui-helpers";
const FIXTURES_DIR = path.join(import.meta.dirname, "../test-fixtures");
const SAMPLE_PDF = path.join(FIXTURES_DIR, "sample.pdf");
@@ -40,7 +43,8 @@ async function uploadFile(page: Page, filePath: string) {
// After clicking, the URL changes to /convert and the settings appear.
// ---------------------------------------------------------------------------
async function navigateToConvert(page: Page) {
- await page.locator('[data-tour="tool-button-convert"]').click();
+ const tile = await revealPickerTool(page, "convert");
+ await tile.click();
await page.waitForSelector('[data-testid="convert-from-dropdown"]', {
timeout: 5000,
});
diff --git a/frontend/editor/src/core/tests/stubbed/main-dashboard.spec.ts b/frontend/editor/src/core/tests/stubbed/main-dashboard.spec.ts
index 07f7f32453..9bd46a3035 100644
--- a/frontend/editor/src/core/tests/stubbed/main-dashboard.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/main-dashboard.spec.ts
@@ -2,6 +2,7 @@ import { test, expect } from "@app/tests/helpers/stub-test-base";
import {
openSettings,
expandSettingsGroups,
+ revealInPicker,
} from "@app/tests/helpers/ui-helpers";
test.describe("2. Main Dashboard / Home Page", () => {
@@ -32,24 +33,26 @@ test.describe("2. Main Dashboard / Home Page", () => {
).toBeVisible();
const categories = [
- /Recommended/,
- /Signing/,
- /Document Security/,
- /Verification/,
- /Document Review/,
- /Page Formatting/,
- /Extraction/,
- /Removal/,
- /Automation/,
- /General/,
- /Advanced Formatting/,
- /Developer Tools/,
+ "Recommended",
+ "Signing",
+ "Document Security",
+ "Verification",
+ "Document Review",
+ "Page Formatting",
+ "Extraction",
+ "Removal",
+ "Automation",
+ "General",
+ "Advanced Formatting",
+ "Developer Tools",
];
for (const category of categories) {
- await expect(page.getByText(category).first()).toBeVisible({
- timeout: 10000,
- });
+ const header = await revealInPicker(
+ page,
+ page.getByText(category, { exact: true }).first(),
+ );
+ await expect(header).toBeVisible({ timeout: 10000 });
}
});
});
diff --git a/frontend/editor/src/core/tests/stubbed/tour-onboarding.spec.ts b/frontend/editor/src/core/tests/stubbed/tour-onboarding.spec.ts
index e63f14d99f..005fcbf922 100644
--- a/frontend/editor/src/core/tests/stubbed/tour-onboarding.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/tour-onboarding.spec.ts
@@ -4,6 +4,7 @@ import {
uploadFiles,
openSettings,
expandSettingsGroups,
+ revealPickerTool,
} from "@app/tests/helpers/ui-helpers";
/**
@@ -55,9 +56,8 @@ test.describe("15.1 Tour selectors - static layout", () => {
});
test("tool-button-crop is present in tool panel", async ({ page }) => {
- await expect(
- page.locator('[data-tour="tool-button-crop"]').first(),
- ).toBeVisible({ timeout: 10_000 });
+ const tile = await revealPickerTool(page, "crop");
+ await expect(tile.first()).toBeVisible({ timeout: 10_000 });
});
// help-button: not yet implemented in the redesigned FileSidebar layout.
diff --git a/frontend/editor/src/core/tests/stubbed/ui-review-capture.spec.ts b/frontend/editor/src/core/tests/stubbed/ui-review-capture.spec.ts
index d991297daa..9f5fef3763 100644
--- a/frontend/editor/src/core/tests/stubbed/ui-review-capture.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/ui-review-capture.spec.ts
@@ -1,5 +1,5 @@
import { test, expect } from "@app/tests/helpers/stub-test-base";
-import { uploadFiles } from "@app/tests/helpers/ui-helpers";
+import { revealPickerTool, uploadFiles } from "@app/tests/helpers/ui-helpers";
import type { Page, Route } from "@playwright/test";
import path from "node:path";
import fs from "node:fs";
@@ -146,9 +146,7 @@ test.use({ autoGoto: false });
test("tool-01-home-tile", async ({ page }) => {
await stubStatus(page);
await page.goto("/", { waitUntil: "domcontentloaded" });
- const tile = page
- .locator('[data-tour="tool-button-autoFormDetection"]')
- .first();
+ const tile = await revealPickerTool(page, "autoFormDetection");
await expect(tile).toBeVisible({ timeout: 15_000 });
await tile.scrollIntoViewIfNeeded();
await settle(page);
@@ -228,9 +226,7 @@ test("tool-06-endpoint-disabled", async ({ page }) => {
r.fulfill({ json: disabledMap }),
);
await page.goto("/", { waitUntil: "domcontentloaded" });
- const tile = page
- .locator('[data-tour="tool-button-autoFormDetection"]')
- .first();
+ const tile = await revealPickerTool(page, "autoFormDetection");
await expect(tile).toBeVisible({ timeout: 15_000 });
await tile.scrollIntoViewIfNeeded();
await settle(page);