mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
Reuse E2E pages and confirm saved navigator changes
This commit is contained in:
1 parent
eacb24ea79
commit
005f4992a6
9 files changed
+74
-44
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import type { BrowserContext } from "@playwright/test";
|
||||
import type { BrowserContext, Page } from "@playwright/test";
|
||||
import {
|
||||
migratePages,
|
||||
serializePages,
|
||||
@@ -12,15 +12,18 @@ export const pageTemplateText = "Content page template heading";
|
||||
|
||||
export const createBuilderEditingProject = ({
|
||||
context,
|
||||
page,
|
||||
name,
|
||||
includePageTemplate = false,
|
||||
}: {
|
||||
context: BrowserContext;
|
||||
page?: Page;
|
||||
name: string;
|
||||
includePageTemplate?: boolean;
|
||||
}) =>
|
||||
createSeededBuilderProject({
|
||||
context,
|
||||
page,
|
||||
email: `${name}@webstudio.test`,
|
||||
title: name,
|
||||
builderToken: `${name}-${randomUUID()}-builder-token`,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { BrowserContext } from "@playwright/test";
|
||||
import type { BrowserContext, Page } from "@playwright/test";
|
||||
import { insertAuthorizationToken, loadDevBuild, updateBuild } from "../db";
|
||||
import { createProjectThroughApi } from "./create-project";
|
||||
|
||||
@@ -7,18 +7,25 @@ type BuildUpdate = Omit<Parameters<typeof updateBuild>[1], "version">;
|
||||
|
||||
export const createSeededBuilderProject = async ({
|
||||
context,
|
||||
page,
|
||||
email,
|
||||
title,
|
||||
builderToken,
|
||||
createBuildUpdate,
|
||||
}: {
|
||||
context: BrowserContext;
|
||||
page?: Page;
|
||||
email: string;
|
||||
title: string;
|
||||
builderToken: string;
|
||||
createBuildUpdate: (build: Build) => BuildUpdate | Promise<BuildUpdate>;
|
||||
}) => {
|
||||
const projectId = await createProjectThroughApi({ context, email, title });
|
||||
const projectId = await createProjectThroughApi({
|
||||
context,
|
||||
page,
|
||||
email,
|
||||
title,
|
||||
});
|
||||
const build = await loadDevBuild({ projectId });
|
||||
await updateBuild(build.id, {
|
||||
...(await createBuildUpdate(build)),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import type { BrowserContext, Page } from "@playwright/test";
|
||||
import type { SerializedPages } from "@webstudio-is/project-migrations/pages";
|
||||
import type { Instance, Prop } from "@webstudio-is/sdk";
|
||||
import { loadDevBuild } from "../db";
|
||||
@@ -111,10 +112,12 @@ const seedBuild = (serializedPages: string) => {
|
||||
|
||||
export const createDragProject = async (
|
||||
context: BrowserContext,
|
||||
name: string
|
||||
name: string,
|
||||
page?: Page
|
||||
) => {
|
||||
return await createSeededBuilderProject({
|
||||
context,
|
||||
page,
|
||||
email: `drag-${name}@webstudio.test`,
|
||||
title: `Drag ${name}`,
|
||||
builderToken: `drag-${name}-${randomUUID()}-builder-token`,
|
||||
@@ -146,4 +149,3 @@ export const loadPages = async (projectId: string) => {
|
||||
const build = await loadDevBuild({ projectId });
|
||||
return JSON.parse(build.pages) as SerializedPages;
|
||||
};
|
||||
import type { BrowserContext } from "@playwright/test";
|
||||
@@ -277,6 +277,7 @@ test("Props panel expression bindings and checkbox state persist after reload",
|
||||
}) => {
|
||||
const fixture = await createBuilderEditingProject({
|
||||
context,
|
||||
page,
|
||||
name: "props-runtime",
|
||||
});
|
||||
const anchorText = "Expression-bound link";
|
||||
|
||||
@@ -59,15 +59,17 @@ const submitContactForm = async (url: string, formId: string) =>
|
||||
|
||||
test("Generated Preview delivers MCP-authored forms with readable email and browser context", async ({
|
||||
context,
|
||||
page,
|
||||
}) => {
|
||||
await startPreviewFormMcpClient();
|
||||
const setupPage = await context.newPage();
|
||||
const projectId = await createProjectThroughApi({
|
||||
context,
|
||||
page,
|
||||
page: setupPage,
|
||||
email: "mcp-default-contact@webstudio.test",
|
||||
title: "MCP default contact Form",
|
||||
});
|
||||
await setupPage.close();
|
||||
|
||||
const {
|
||||
formData: {
|
||||
formId: formDataFormId,
|
||||
@@ -322,6 +324,7 @@ test("Generated Preview delivers MCP-authored forms with readable email and brow
|
||||
).toBe(true);
|
||||
});
|
||||
await test.step("dynamic route form delivers scoped submission and browser values", async () => {
|
||||
const page = await context.newPage();
|
||||
await page.route("**/*", (route) =>
|
||||
new URL(route.request().url()).hostname === "127.0.0.1"
|
||||
? route.continue()
|
||||
|
||||
@@ -25,6 +25,7 @@ test("Builder and MCP Form actions deliver from generated Preview", async ({
|
||||
await startPreviewFormMcpClient();
|
||||
const fixture = await createBuilderEditingProject({
|
||||
context,
|
||||
page,
|
||||
name: "mcp-email-scenarios",
|
||||
});
|
||||
await test.step("save the legacy Webhook Form action through Builder", async () => {
|
||||
|
||||
@@ -54,6 +54,7 @@ test("MCP-authored Form submission exposes its saved HTTP exchange without anoth
|
||||
}) => {
|
||||
const fixture = await createBuilderEditingProject({
|
||||
context,
|
||||
page,
|
||||
name: "mcp-form-resource-snapshot",
|
||||
});
|
||||
const receiver = await startFormDeliveryReceiver();
|
||||
|
||||
@@ -391,9 +391,7 @@ const insertComponentPanelOption = async ({
|
||||
name: string;
|
||||
}) => {
|
||||
await searchComponentsPanel({ page, text: name });
|
||||
const save = waitForChangeToBeSaved({ page });
|
||||
await page.getByRole("option", { name, exact: true }).click();
|
||||
await save;
|
||||
};
|
||||
|
||||
const openCommandPanel = async ({ page }: { page: Page }) => {
|
||||
@@ -431,7 +429,6 @@ const runCommandPanelStructuralAction = async ({
|
||||
await commandInput.fill(command);
|
||||
await selectCommandPanelItem({ page, text: command });
|
||||
if (option === undefined) {
|
||||
await waitForChangeToBeSaved({ page });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -446,7 +443,6 @@ const runCommandPanelStructuralAction = async ({
|
||||
await optionInput.waitFor();
|
||||
await optionInput.fill(option);
|
||||
await selectCommandPanelItem({ page, text: option });
|
||||
await waitForChangeToBeSaved({ page });
|
||||
};
|
||||
|
||||
const runCommandPanelTagInsertion = async ({
|
||||
@@ -462,7 +458,6 @@ const runCommandPanelTagInsertion = async ({
|
||||
});
|
||||
await commandInput.fill(tag);
|
||||
await selectCommandPanelItem({ page, text: `<${tag}>` });
|
||||
await waitForChangeToBeSaved({ page });
|
||||
};
|
||||
|
||||
const selectCommandPanelInstance = async ({
|
||||
@@ -513,7 +508,6 @@ const editSelectedNavigatorLabel = async ({
|
||||
await editableLabel.waitFor({ state: "visible" });
|
||||
await editableLabel.fill(label);
|
||||
await editableLabel.press("Enter");
|
||||
await waitForChangeToBeSaved({ page });
|
||||
};
|
||||
|
||||
test("Builder Navigator keyboard move, reparent, and reorder persist after reload", async ({
|
||||
@@ -522,6 +516,7 @@ test("Builder Navigator keyboard move, reparent, and reorder persist after reloa
|
||||
}) => {
|
||||
const fixture = await createBuilderEditingProject({
|
||||
context,
|
||||
page,
|
||||
name: "navigator-keyboard",
|
||||
});
|
||||
const sectionText = "Navigator move section";
|
||||
@@ -655,6 +650,7 @@ test("Builder Navigator and command panel edits persist after reload", async ({
|
||||
}) => {
|
||||
const fixture = await createBuilderEditingProject({
|
||||
context,
|
||||
page,
|
||||
name: "navigator-commands",
|
||||
});
|
||||
const anchorText = "Initial content";
|
||||
@@ -671,36 +667,47 @@ test("Builder Navigator and command panel edits persist after reload", async ({
|
||||
await waitForCanvasText({ page, text: anchorText });
|
||||
await selectCanvasTextInstance({ page, text: anchorText });
|
||||
|
||||
await openComponentsPanel({ page });
|
||||
await insertComponentPanelOption({ page, name: componentName });
|
||||
const initial = await inspectBuild(fixture);
|
||||
const imageCount = initial.countComponent(componentName);
|
||||
const imageCount = initial.countComponent(componentName) + 1;
|
||||
const divCount = initial.countElementTag("div");
|
||||
const sectionCount = initial.countElementTag("section");
|
||||
const asideCount = initial.countElementTag("aside");
|
||||
await openComponentsPanel({ page });
|
||||
await insertComponentPanelOption({ page, name: componentName });
|
||||
await expect
|
||||
.poll(async () =>
|
||||
(await inspectBuild(fixture)).countComponent(componentName)
|
||||
)
|
||||
.toBe(imageCount);
|
||||
|
||||
await test.step("rename, wrap, and unwrap the Image", async () => {
|
||||
await openNavigatorPanel({ page });
|
||||
await selectNavigatorItem({ page, itemName: componentName });
|
||||
await editSelectedNavigatorLabel({ page, label: renamedLabel });
|
||||
expect(await getInstanceLabelCount({ fixture, label: renamedLabel })).toBe(
|
||||
1
|
||||
);
|
||||
await expect
|
||||
.poll(() => getInstanceLabelCount({ fixture, label: renamedLabel }))
|
||||
.toBe(1);
|
||||
|
||||
await runCommandPanelStructuralAction({
|
||||
page,
|
||||
command: "Wrap",
|
||||
option: "div",
|
||||
});
|
||||
expect(await getElementTagCount({ fixture, tag: "div" })).toBe(
|
||||
divCount + 1
|
||||
);
|
||||
await expect
|
||||
.poll(() => getElementTagCount({ fixture, tag: "div" }))
|
||||
.toBe(divCount + 1);
|
||||
|
||||
await selectCommandPanelInstance({ page, label: renamedLabel });
|
||||
await runCommandPanelStructuralAction({ page, command: "Unwrap" });
|
||||
const unwrapped = await inspectBuild(fixture);
|
||||
expect(unwrapped.countElementTag("div")).toBe(divCount);
|
||||
expect(unwrapped.countComponent(componentName)).toBe(imageCount);
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const unwrapped = await inspectBuild(fixture);
|
||||
return {
|
||||
divs: unwrapped.countElementTag("div"),
|
||||
images: unwrapped.countComponent(componentName),
|
||||
};
|
||||
})
|
||||
.toEqual({ divs: divCount, images: imageCount });
|
||||
});
|
||||
|
||||
await test.step("convert a new wrapper to a section", async () => {
|
||||
@@ -710,9 +717,9 @@ test("Builder Navigator and command panel edits persist after reload", async ({
|
||||
command: "Wrap",
|
||||
option: "div",
|
||||
});
|
||||
expect(await getElementTagCount({ fixture, tag: "div" })).toBe(
|
||||
divCount + 1
|
||||
);
|
||||
await expect
|
||||
.poll(() => getElementTagCount({ fixture, tag: "div" }))
|
||||
.toBe(divCount + 1);
|
||||
|
||||
await openNavigatorPanel({ page });
|
||||
await selectNavigatorItem({ page, itemName: "div" });
|
||||
@@ -721,19 +728,26 @@ test("Builder Navigator and command panel edits persist after reload", async ({
|
||||
command: "Convert",
|
||||
option: "section",
|
||||
});
|
||||
const converted = await inspectBuild(fixture);
|
||||
expect(converted.countElementTag("div")).toBe(divCount);
|
||||
expect(converted.countElementTag("section")).toBe(sectionCount + 1);
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const converted = await inspectBuild(fixture);
|
||||
return {
|
||||
divs: converted.countElementTag("div"),
|
||||
sections: converted.countElementTag("section"),
|
||||
};
|
||||
})
|
||||
.toEqual({ divs: divCount, sections: sectionCount + 1 });
|
||||
});
|
||||
|
||||
await test.step("insert an aside using the command panel", async () => {
|
||||
await selectBodyInNavigator({ page });
|
||||
await runCommandPanelTagInsertion({ page, tag: "aside" });
|
||||
expect(await getElementTagCount({ fixture, tag: "aside" })).toBe(
|
||||
asideCount + 1
|
||||
);
|
||||
await expect
|
||||
.poll(() => getElementTagCount({ fixture, tag: "aside" }))
|
||||
.toBe(asideCount + 1);
|
||||
});
|
||||
|
||||
await waitForSyncComplete({ page });
|
||||
await measure("pages actions reload structural edits", async () => {
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
@@ -756,6 +770,7 @@ test("Builder clipboard shortcuts and paste targets preserve saved content", asy
|
||||
}) => {
|
||||
const fixture = await createBuilderEditingProject({
|
||||
context,
|
||||
page,
|
||||
name: "builder-clipboard",
|
||||
includePageTemplate: true,
|
||||
});
|
||||
|
||||
@@ -7,17 +7,14 @@ import {
|
||||
import { openProjectBuilder } from "../flows/builder";
|
||||
import { dragTreeRow, getTreeRowByButton } from "../flows/drag";
|
||||
import { openPagesPanel } from "../flows/pages-panel";
|
||||
import { test, withBrowserContext } from "../test";
|
||||
import { test } from "../test";
|
||||
|
||||
let fixture: Awaited<ReturnType<typeof createDragProject>>;
|
||||
|
||||
test.beforeAll(async ({ browser }) => {
|
||||
fixture = await withBrowserContext(browser, (context) =>
|
||||
createDragProject(context, "pages")
|
||||
);
|
||||
});
|
||||
|
||||
test("Pages panel pointer drag reorders and nests pages", async ({ page }) => {
|
||||
test("Pages panel pointer drag reorders and nests pages", async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
const fixture = await createDragProject(context, "pages", page);
|
||||
await context.clearCookies();
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
|
||||
Reference in new issue
Block a user