mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 02:05:31 +00:00
Stabilize website scene and keyboard language checks (#10808)
* fix(website): stabilize scene and keyboard language checks Drive scene frames explicitly so sparse browser paints do not consume the test deadline. Let the landing page commit a locale change while its optional plugin count loads. * test(website): advance the plugin panel crossfade before asserting removal * test(website): settle native animations during the plugin panel swap Playwright advances JavaScript frames, while the browser keeps a separate timeline for native animations. Finish the mockup’s finite native animations at the panel checkpoint so either animation path removes the outgoing panel.
This commit is contained in:
@@ -9,19 +9,23 @@ async function chooseLanguage(page: Page, language: string) {
|
||||
await page.getByRole("menuitemradio", { name: language }).click();
|
||||
}
|
||||
|
||||
async function withPageScriptsHeld(page: Page, run: (release: () => void) => Promise<void>) {
|
||||
let releaseScripts!: () => void;
|
||||
const scriptsReleased = new Promise<void>((resolve) => {
|
||||
releaseScripts = resolve;
|
||||
async function withRequestsHeld(
|
||||
page: Page,
|
||||
pattern: string,
|
||||
run: (release: () => void) => Promise<void>,
|
||||
) {
|
||||
let releaseRequests!: () => void;
|
||||
const requestsReleased = new Promise<void>((resolve) => {
|
||||
releaseRequests = resolve;
|
||||
});
|
||||
await page.route("**/*.js", async (route) => {
|
||||
await scriptsReleased;
|
||||
await page.route(pattern, async (route) => {
|
||||
await requestsReleased;
|
||||
await route.continue();
|
||||
});
|
||||
try {
|
||||
await run(releaseScripts);
|
||||
await run(releaseRequests);
|
||||
} finally {
|
||||
releaseScripts();
|
||||
releaseRequests();
|
||||
await page.unrouteAll({ behavior: "wait" });
|
||||
}
|
||||
}
|
||||
@@ -198,13 +202,17 @@ test("switches language from the keyboard", async ({ page }) => {
|
||||
await expect(languageButton(page)).toBeFocused();
|
||||
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await expect(page.getByRole("menuitemradio", { name: "English" })).toBeFocused();
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await expect(page.getByRole("menuitemradio", { name: /简体中文/ })).toBeFocused();
|
||||
await page.keyboard.press("Enter");
|
||||
|
||||
await expect(page).toHaveURL(/\/zh-CN$/);
|
||||
await expect(languageButton(page)).toHaveText("ZH");
|
||||
await expect(languageButton(page)).toBeFocused();
|
||||
// A slow plugin count must not delay the new language or lose keyboard focus.
|
||||
await withRequestsHeld(page, "**/_serverFn/**", async () => {
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(page).toHaveURL(/\/zh-CN$/);
|
||||
await expect(languageButton(page)).toHaveText("ZH");
|
||||
await expect(languageButton(page)).toBeFocused();
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("on a phone", () => {
|
||||
@@ -260,7 +268,7 @@ test("shows the changelog in Chinese", async ({ page }) => {
|
||||
});
|
||||
|
||||
test("waits for scripts before enabling the language menu", async ({ page }) => {
|
||||
await withPageScriptsHeld(page, async (releaseScripts) => {
|
||||
await withRequestsHeld(page, "**/*.js", async (releaseScripts) => {
|
||||
await page.goto("/docs/cli#running-agents", { waitUntil: "commit" });
|
||||
await expect(languageButton(page)).toBeVisible();
|
||||
await expect(languageButton(page)).toBeDisabled();
|
||||
|
||||
@@ -10,6 +10,37 @@ async function openHomepage(page: Page, window = { width: 1512, height: 930 }) {
|
||||
await waitForHydration(page);
|
||||
}
|
||||
|
||||
/** The scene advances at most 64 ms per frame. Drive its frames independently of CI paint speed. */
|
||||
async function openHomepageWithSceneClock(
|
||||
page: Page,
|
||||
viewport?: { width: number; height: number },
|
||||
) {
|
||||
await page.clock.install();
|
||||
await openHomepage(page, viewport);
|
||||
await page.clock.pauseAt(await page.evaluate(() => Date.now() + 1000));
|
||||
}
|
||||
|
||||
async function centerMockup(mockup: Locator) {
|
||||
await mockup.evaluate((element) =>
|
||||
element.scrollIntoView({ block: "center", behavior: "instant" }),
|
||||
);
|
||||
}
|
||||
|
||||
async function finishPanelSwap(page: Page, mockup: Locator, outgoingPanel: Locator) {
|
||||
await expect
|
||||
.poll(async () => {
|
||||
await page.clock.runFor(250);
|
||||
// Playwright's clock drives JavaScript frames. Native animations use the document timeline.
|
||||
await mockup.evaluate((element) => {
|
||||
for (const animation of element.getAnimations({ subtree: true })) {
|
||||
if (Number.isFinite(animation.effect?.getComputedTiming().endTime)) animation.finish();
|
||||
}
|
||||
});
|
||||
return outgoingPanel.count();
|
||||
})
|
||||
.toBe(0);
|
||||
}
|
||||
|
||||
async function viewPhones(page: Page) {
|
||||
await page.getByRole("img", { name: "Paseo agent chat", exact: true }).scrollIntoViewIfNeeded();
|
||||
}
|
||||
@@ -110,12 +141,7 @@ test("the hero opens on orchestration across providers and machines", async ({ p
|
||||
test("the orchestration scene plays from an empty chat to the open roster of subagents", async ({
|
||||
page,
|
||||
}) => {
|
||||
// The scene clock moves at most 64ms per animation frame. Headless WebKit on a busy CI runner
|
||||
// paints a few frames a second, so on the real clock the scene plays in slow motion and misses
|
||||
// any wall-clock timeout. The test holds the page clock and plays the scene itself.
|
||||
await page.clock.install();
|
||||
await openHomepage(page);
|
||||
await page.clock.pauseAt(await page.evaluate(() => Date.now() + 1000));
|
||||
await openHomepageWithSceneClock(page);
|
||||
const mockup = page.getByRole("img", { name: desktopName, exact: true });
|
||||
const composer = mockup.getByText("Message the agent, tag @files, or use /commands and /skills");
|
||||
await playScene(page, "Orchestration", composer);
|
||||
@@ -141,30 +167,34 @@ test("the orchestration scene plays from an empty chat to the open roster of sub
|
||||
});
|
||||
|
||||
test("the opening scene waits until most of the mockup is on screen", async ({ page }) => {
|
||||
await openHomepage(page);
|
||||
await openHomepageWithSceneClock(page);
|
||||
const mockup = page.getByRole("img", { name: desktopName, exact: true });
|
||||
const request = mockup.getByText("Fix the issues labeled ready, one worktree each.");
|
||||
await expect(mockup).not.toBeInViewport({ ratio: 0.6 });
|
||||
|
||||
// A scene that started at load sends the request within three seconds.
|
||||
await page.waitForTimeout(4500);
|
||||
await page.clock.runFor(4500);
|
||||
await expect(request).toHaveCount(0);
|
||||
|
||||
await mockup.scrollIntoViewIfNeeded();
|
||||
await expect(request).toBeVisible({ timeout: 10_000 });
|
||||
await centerMockup(mockup);
|
||||
await expect(mockup).toBeInViewport({ ratio: 0.6 });
|
||||
await page.clock.runFor(4500);
|
||||
await expect(request).toBeVisible();
|
||||
});
|
||||
|
||||
test("the opening scene starts in a window shorter than most of the mockup", async ({ page }) => {
|
||||
await openHomepage(page, { width: 1400, height: 320 });
|
||||
await openHomepageWithSceneClock(page, { width: 1400, height: 320 });
|
||||
const mockup = page.getByRole("img", { name: desktopName, exact: true });
|
||||
const request = mockup.getByText("Fix the issues labeled ready, one worktree each.");
|
||||
await mockup.scrollIntoViewIfNeeded();
|
||||
await centerMockup(mockup);
|
||||
await expect(mockup).toBeInViewport();
|
||||
await expect(mockup).not.toBeInViewport({ ratio: 0.6 });
|
||||
await expect(request).toBeVisible({ timeout: 10_000 });
|
||||
await page.clock.runFor(4500);
|
||||
await expect(request).toBeVisible();
|
||||
});
|
||||
|
||||
test("the plugins scene installs the panel, then changes it on request", async ({ page }) => {
|
||||
await openHomepage(page);
|
||||
await openHomepageWithSceneClock(page);
|
||||
const mockup = page.getByRole("img", { name: desktopName, exact: true });
|
||||
const changesPanel = mockup.getByText("Uncommitted", { exact: true });
|
||||
const pluginPanel = mockup.getByText("Recently merged", { exact: true });
|
||||
@@ -174,12 +204,14 @@ test("the plugins scene installs the panel, then changes it on request", async (
|
||||
await expect(pluginPanel).toHaveCount(0);
|
||||
|
||||
// Installing the plugin swaps the docked panel for the one the agent built.
|
||||
await expect(pluginPanel).toBeVisible({ timeout: 20_000 });
|
||||
await expect(changesPanel).toHaveCount(0);
|
||||
await page.clock.runFor(5500);
|
||||
await expect(pluginPanel).toBeVisible();
|
||||
await finishPanelSwap(page, mockup, changesPanel);
|
||||
await expect(failingCheck).toHaveCount(0);
|
||||
|
||||
// The second request reloads the plugin and the open panel lists the failing check.
|
||||
await expect(failingCheck).toBeVisible({ timeout: 15_000 });
|
||||
await page.clock.runFor(6000);
|
||||
await expect(failingCheck).toBeVisible();
|
||||
await expect(
|
||||
mockup.getByText("paseo plugin reload release-radar", { exact: true }),
|
||||
).toBeVisible();
|
||||
|
||||
@@ -18,18 +18,14 @@ export function agentRouteOptions(slug: AgentPageSlug) {
|
||||
locale,
|
||||
});
|
||||
},
|
||||
loader: async () => ({ pluginCount: await getPluginCount() }),
|
||||
loader: () => ({ pluginCount: getPluginCount().catch(() => null) }),
|
||||
component: function AgentLandingPage() {
|
||||
const { t } = useTranslation();
|
||||
const data = useLoaderData({ strict: false }) as { pluginCount?: number | null } | undefined;
|
||||
const { pluginCount } = useLoaderData({ strict: false }) as {
|
||||
pluginCount: Promise<number | null>;
|
||||
};
|
||||
const page = getAgentPage(slug, t);
|
||||
return (
|
||||
<LandingPage
|
||||
title={page.title}
|
||||
subtitle={page.subtitle}
|
||||
pluginCount={data?.pluginCount ?? null}
|
||||
/>
|
||||
);
|
||||
return <LandingPage title={page.title} subtitle={page.subtitle} pluginCount={pluginCount} />;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Await } from "@tanstack/react-router";
|
||||
import { PLUGINS_LINKED } from "~/plugins/launch";
|
||||
import { categoryHref } from "~/plugins/links";
|
||||
import type { CategorySlug } from "~/plugins/categories";
|
||||
@@ -114,14 +115,14 @@ import "~/styles.css";
|
||||
interface LandingPageProps {
|
||||
title: React.ReactNode;
|
||||
subtitle: React.ReactNode;
|
||||
pluginCount?: number | null;
|
||||
pluginCount: Promise<number | null>;
|
||||
showHubEyebrow?: boolean;
|
||||
}
|
||||
|
||||
export function LandingPage({
|
||||
title,
|
||||
subtitle,
|
||||
pluginCount = null,
|
||||
pluginCount,
|
||||
showHubEyebrow = false,
|
||||
}: LandingPageProps) {
|
||||
return (
|
||||
@@ -613,7 +614,7 @@ function ProductLead({
|
||||
actions,
|
||||
}: {
|
||||
icon: LucideIcon;
|
||||
title: string;
|
||||
title: React.ReactNode;
|
||||
description?: string;
|
||||
actions?: React.ReactNode;
|
||||
}) {
|
||||
@@ -979,17 +980,23 @@ const PLUGIN_CLIENT_COMPONENTS = {
|
||||
),
|
||||
};
|
||||
|
||||
function ExtensibleSection({ pluginCount }: { pluginCount?: number | null }) {
|
||||
function ExtensibleSection({ pluginCount }: { pluginCount: Promise<number | null> }) {
|
||||
const { t } = useTranslation();
|
||||
const pluginActions = React.useMemo(() => <PluginActions />, []);
|
||||
const description = React.useMemo(
|
||||
() => <Trans i18nKey="landing.plugins.description" components={PLUGIN_CLIENT_COMPONENTS} />,
|
||||
[],
|
||||
);
|
||||
const libraryTitle =
|
||||
pluginCount && pluginCount > 0
|
||||
? t("landing.plugins.libraryTitleCount", { count: pluginCount })
|
||||
: t("landing.plugins.libraryTitle");
|
||||
const libraryTitle = React.useMemo(() => {
|
||||
const fallback = t("landing.plugins.libraryTitle");
|
||||
return (
|
||||
<Await promise={pluginCount} fallback={fallback}>
|
||||
{(count) =>
|
||||
count && count > 0 ? t("landing.plugins.libraryTitleCount", { count }) : fallback
|
||||
}
|
||||
</Await>
|
||||
);
|
||||
}, [pluginCount, t]);
|
||||
return (
|
||||
<FeatureSection
|
||||
eyebrow={t("landing.eyebrows.plugins")}
|
||||
|
||||
@@ -16,7 +16,7 @@ export const Route = createFileRoute("/{-$locale}/")({
|
||||
locale,
|
||||
});
|
||||
},
|
||||
loader: async () => ({ pluginCount: await getPluginCount() }),
|
||||
loader: () => ({ pluginCount: getPluginCount().catch(() => null) }),
|
||||
component: Home,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user