mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
perf: Reduce Builder E2E reloads and fix artifact lookup
This commit is contained in:
1 parent
1b41123a2a
commit
253d63562c
15 files changed
+960
-1257
No files matched your search
@@ -57,8 +57,8 @@ runs:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
for attempt in {1..84}; do
|
||||
count=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/artifacts?name=builder-e2e-build" --jq '.total_count')
|
||||
if [ "$count" -gt 0 ]; then
|
||||
available=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/artifacts?name=builder-e2e-build" --jq '.artifacts | max_by(.id) | .expired == false')
|
||||
if [ "$available" = true ]; then
|
||||
exit 0
|
||||
fi
|
||||
sleep 5
|
||||
@@ -72,6 +72,8 @@ runs:
|
||||
with:
|
||||
name: builder-e2e-build
|
||||
path: .
|
||||
# Use the same REST artifact lookup as the wait step.
|
||||
github-token: ${{ github.token }}
|
||||
|
||||
- name: Verify Builder E2E build inputs
|
||||
if: steps.build-cache.outputs.cache-hit != 'true'
|
||||
|
||||
@@ -5,6 +5,7 @@ on:
|
||||
types: [labeled]
|
||||
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
deployments: write
|
||||
pull-requests: write
|
||||
|
||||
+58
@@ -128,3 +128,61 @@ test("asset settings move to the selected subfolder only after leaving the folde
|
||||
);
|
||||
await expect.element(first).toBeVisible();
|
||||
});
|
||||
|
||||
test("dragging a selected folder into a folder moves the entire selection", async () => {
|
||||
act(() => {
|
||||
$assetFolders.set(
|
||||
createAssetFoldersFixture(
|
||||
createAssetFolderFixture({ id: "parent", name: "Parent" }),
|
||||
createAssetFolderFixture({ id: "alpha", name: "Alpha" }),
|
||||
createAssetFolderFixture({ id: "bravo", name: "Bravo" })
|
||||
)
|
||||
);
|
||||
});
|
||||
const alpha = page.getByRole("button", { name: "Folder Alpha", exact: true });
|
||||
const bravo = page.getByRole("button", { name: "Folder Bravo", exact: true });
|
||||
const parent = page.getByRole("button", {
|
||||
name: "Folder Parent",
|
||||
exact: true,
|
||||
});
|
||||
await act(async () => alpha.click());
|
||||
await act(async () => bravo.click({ modifiers: ["ControlOrMeta"] }));
|
||||
expect(page.getByRole("option", { selected: true }).elements()).toHaveLength(
|
||||
2
|
||||
);
|
||||
await act(async () => userEvent.dragAndDrop(bravo, parent));
|
||||
await expect.element(alpha).not.toBeInTheDocument();
|
||||
await expect.element(bravo).not.toBeInTheDocument();
|
||||
await act(async () => parent.dblClick());
|
||||
await expect.element(alpha).toBeVisible();
|
||||
await expect.element(bravo).toBeVisible();
|
||||
});
|
||||
|
||||
test("the context menu moves all selected assets into the chosen folder", async () => {
|
||||
const first = page.getByTitle("first.txt");
|
||||
const second = page.getByTitle("second.txt");
|
||||
await act(async () => first.click());
|
||||
await act(async () => second.click({ modifiers: ["ControlOrMeta"] }));
|
||||
await act(async () => second.click({ button: "right" }));
|
||||
await act(async () =>
|
||||
page.getByRole("menuitem", { name: "Move", exact: true }).click()
|
||||
);
|
||||
const dialog = page.getByRole("dialog", { name: "Move items" });
|
||||
await act(async () =>
|
||||
dialog.getByRole("combobox", { name: "Folder", exact: true }).click()
|
||||
);
|
||||
await act(async () =>
|
||||
page.getByRole("option", { name: "Parent", exact: true }).click()
|
||||
);
|
||||
await act(async () =>
|
||||
dialog.getByRole("button", { name: "Move", exact: true }).click()
|
||||
);
|
||||
|
||||
await expect.element(first).not.toBeInTheDocument();
|
||||
await expect.element(second).not.toBeInTheDocument();
|
||||
await act(async () =>
|
||||
page.getByRole("button", { name: "Folder Parent", exact: true }).dblClick()
|
||||
);
|
||||
await expect.element(first).toBeVisible();
|
||||
await expect.element(second).toBeVisible();
|
||||
});
|
||||
@@ -1 +1,7 @@
|
||||
# Valid MDX sibling
|
||||
|
||||
<MissingE2ETemplate />
|
||||
|
||||
Valid content after the missing template.
|
||||
|
||||
<LifecycleCard>Authored lifecycle card</LifecycleCard>
|
||||
@@ -1,5 +0,0 @@
|
||||
# Valid MDX sibling
|
||||
|
||||
<MissingE2ETemplate />
|
||||
|
||||
Valid content after the missing template.
|
||||
@@ -1,5 +1,10 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import type { BrowserContext } from "@playwright/test";
|
||||
import { encodeDataSourceVariable } from "@webstudio-is/sdk";
|
||||
import { loadDevBuild, updateBuild } from "../db";
|
||||
import { getAssetUploadApiUrl } from "@webstudio-is/sdk/runtime";
|
||||
import { insertAuthorizationToken, loadDevBuild, updateBuild } from "../db";
|
||||
import { builderUrl } from "../test";
|
||||
|
||||
type InstanceData = {
|
||||
type: "instance";
|
||||
@@ -29,6 +34,7 @@ type DataSourceData = {
|
||||
|
||||
const blockId = "content-block";
|
||||
const templateId = "content-block-template";
|
||||
export const lifecycleTemplateId = "lifecycle-card-template";
|
||||
|
||||
const getBuildData = async (projectId: string) => {
|
||||
const build = await loadDevBuild({ projectId });
|
||||
@@ -55,33 +61,12 @@ export const configureRepresentableContentBlockBody = async (
|
||||
await updateBuild(build.id, { instances: JSON.stringify(instances) });
|
||||
};
|
||||
|
||||
export const configureEmptyHeadingTemplate = async (projectId: string) => {
|
||||
const { build, instances } = await getBuildData(projectId);
|
||||
const templates = instances.find((instance) => instance.id === templateId);
|
||||
if (templates === undefined) {
|
||||
throw new Error("Expected the Content Block templates fixture instance");
|
||||
}
|
||||
const emptyHeadingId = "empty-heading-template";
|
||||
templates.children.push({ type: "id", value: emptyHeadingId });
|
||||
instances.push({
|
||||
type: "instance",
|
||||
id: emptyHeadingId,
|
||||
component: "ws:element",
|
||||
tag: "h1",
|
||||
name: "EmptyHeadingTemplate",
|
||||
label: "Empty Heading Template",
|
||||
children: [],
|
||||
});
|
||||
await updateBuild(build.id, { instances: JSON.stringify(instances) });
|
||||
};
|
||||
|
||||
export const configureNamedTemplateLifecycle = async (projectId: string) => {
|
||||
const { build, instances } = await getBuildData(projectId);
|
||||
const templates = instances.find((instance) => instance.id === templateId);
|
||||
if (templates === undefined) {
|
||||
throw new Error("Expected the Content Block templates fixture instance");
|
||||
}
|
||||
const lifecycleTemplateId = "lifecycle-card-template";
|
||||
templates.children.push({ type: "id", value: lifecycleTemplateId });
|
||||
instances.push({
|
||||
type: "instance",
|
||||
@@ -95,43 +80,104 @@ export const configureNamedTemplateLifecycle = async (projectId: string) => {
|
||||
await updateBuild(build.id, { instances: JSON.stringify(instances) });
|
||||
};
|
||||
|
||||
const configureSourceBlock = ({
|
||||
instances,
|
||||
props,
|
||||
expression,
|
||||
export const mdxEditorPageNames = {
|
||||
detail: "Dynamic MDX detail",
|
||||
repeated: "Repeated MDX content",
|
||||
};
|
||||
|
||||
export const prepareMdxEditorPages = async ({
|
||||
context,
|
||||
projectId,
|
||||
sourceFilename,
|
||||
alternateFilename,
|
||||
emptyFilename,
|
||||
}: {
|
||||
instances: InstanceData[];
|
||||
props: PropData[];
|
||||
expression: string;
|
||||
context: BrowserContext;
|
||||
projectId: string;
|
||||
sourceFilename: string;
|
||||
alternateFilename: string;
|
||||
emptyFilename: string;
|
||||
}) => {
|
||||
const block = instances.find((instance) => instance.id === blockId);
|
||||
if (block === undefined) {
|
||||
throw new Error("Expected the Content Block fixture instance");
|
||||
const token = randomUUID();
|
||||
await insertAuthorizationToken({
|
||||
token,
|
||||
projectId,
|
||||
name: "MDX fixture setup",
|
||||
relation: "builders",
|
||||
canUseApi: true,
|
||||
});
|
||||
const upload = async (filename: string, uploadedFilename = filename) => {
|
||||
const url = new URL(getAssetUploadApiUrl(uploadedFilename), builderUrl);
|
||||
url.searchParams.set("projectId", projectId);
|
||||
url.searchParams.set("type", "file");
|
||||
url.searchParams.set("format", "mdx");
|
||||
if (uploadedFilename !== filename) {
|
||||
url.searchParams.set("force", "true");
|
||||
}
|
||||
const response = await context.request.post(url.href, {
|
||||
headers: {
|
||||
"x-auth-token": token,
|
||||
"content-type": "application/octet-stream",
|
||||
},
|
||||
data: await readFile(new URL(`./assets/${filename}`, import.meta.url)),
|
||||
});
|
||||
if (response.ok() === false) {
|
||||
throw new Error(
|
||||
`MDX fixture upload failed for ${filename}: ${response.status()}`
|
||||
);
|
||||
}
|
||||
const { uploadedAssets } = (await response.json()) as {
|
||||
uploadedAssets: Array<{ id: string }>;
|
||||
};
|
||||
const [asset] = uploadedAssets;
|
||||
if (asset === undefined) {
|
||||
throw new Error(`Expected an asset ID for ${filename}`);
|
||||
}
|
||||
return asset.id;
|
||||
};
|
||||
const [
|
||||
{ build, instances, props, dataSources },
|
||||
sourceAssetId,
|
||||
alternateAssetId,
|
||||
emptyAssetId,
|
||||
detailSourceAssetId,
|
||||
detailAlternateAssetId,
|
||||
] = await Promise.all([
|
||||
getBuildData(projectId),
|
||||
upload(sourceFilename),
|
||||
upload(alternateFilename),
|
||||
upload(emptyFilename),
|
||||
upload(sourceFilename, `detail-${sourceFilename}`),
|
||||
upload(alternateFilename, `detail-${alternateFilename}`),
|
||||
]);
|
||||
|
||||
const homeBlock = instances.find((instance) => instance.id === blockId);
|
||||
const homeTemplates = instances.find(
|
||||
(instance) => instance.id === templateId
|
||||
);
|
||||
if (homeBlock === undefined || homeTemplates === undefined) {
|
||||
throw new Error("Expected the Content Block fixture instances");
|
||||
}
|
||||
block.children = [{ type: "id", value: templateId }];
|
||||
const emptyHeadingId = "empty-heading-template";
|
||||
homeTemplates.children.push({ type: "id", value: emptyHeadingId });
|
||||
instances.push({
|
||||
type: "instance",
|
||||
id: emptyHeadingId,
|
||||
component: "ws:element",
|
||||
tag: "h1",
|
||||
name: "EmptyHeadingTemplate",
|
||||
label: "Empty Heading Template",
|
||||
children: [],
|
||||
});
|
||||
homeBlock.children = [{ type: "id", value: templateId }];
|
||||
props.push({
|
||||
id: "content-block-source",
|
||||
instanceId: blockId,
|
||||
name: "src",
|
||||
type: "expression",
|
||||
value: expression,
|
||||
type: "asset",
|
||||
value: emptyAssetId,
|
||||
});
|
||||
};
|
||||
|
||||
export const configureDynamicDetailContentBlock = async ({
|
||||
projectId,
|
||||
initialAssetId,
|
||||
}: {
|
||||
projectId: string;
|
||||
initialAssetId: string;
|
||||
}) => {
|
||||
const { build, instances, props, dataSources } =
|
||||
await getBuildData(projectId);
|
||||
configureSourceBlock({
|
||||
instances,
|
||||
props,
|
||||
expression: "$ws$system.params.assetid",
|
||||
});
|
||||
const pages = JSON.parse(build.pages) as {
|
||||
homePageId: string;
|
||||
rootFolderId: string;
|
||||
@@ -145,80 +191,99 @@ export const configureDynamicDetailContentBlock = async ({
|
||||
}>;
|
||||
folders: Array<{ id: string; children: string[] }>;
|
||||
};
|
||||
const homePage = pages.pages.find((page) => page.id === pages.homePageId);
|
||||
if (homePage === undefined) {
|
||||
throw new Error("Expected the Content Block fixture home page");
|
||||
}
|
||||
const dynamicPageId = homePage.id;
|
||||
const homeRootId = "mdx-detail-home-root";
|
||||
const body = instances.find(
|
||||
(instance) => instance.id === homePage.rootInstanceId
|
||||
);
|
||||
if (body === undefined) {
|
||||
throw new Error("Expected the Content Block fixture page root");
|
||||
}
|
||||
instances.push({ ...body, id: homeRootId, children: [] });
|
||||
pages.pages.push({
|
||||
...homePage,
|
||||
id: "mdx-detail-home-page",
|
||||
name: "MDX detail home",
|
||||
title: JSON.stringify("MDX detail home"),
|
||||
path: "",
|
||||
history: [],
|
||||
rootInstanceId: homeRootId,
|
||||
});
|
||||
pages.homePageId = "mdx-detail-home-page";
|
||||
const home = pages.pages.find((page) => page.id === pages.homePageId);
|
||||
const rootFolder = pages.folders.find(
|
||||
(folder) => folder.id === pages.rootFolderId
|
||||
);
|
||||
if (rootFolder === undefined) {
|
||||
throw new Error("Expected the Content Block fixture root folder");
|
||||
if (home === undefined || rootFolder === undefined) {
|
||||
throw new Error(
|
||||
"Expected the Content Block fixture home page and root folder"
|
||||
);
|
||||
}
|
||||
rootFolder.children = [
|
||||
pages.homePageId,
|
||||
dynamicPageId,
|
||||
...rootFolder.children.filter((id) => id !== dynamicPageId),
|
||||
];
|
||||
homePage.name = "Dynamic MDX detail";
|
||||
homePage.title = JSON.stringify("Dynamic MDX detail");
|
||||
homePage.path = "/:assetid";
|
||||
homePage.history = [`/${initialAssetId}`];
|
||||
await updateBuild(build.id, {
|
||||
instances: JSON.stringify(instances),
|
||||
props: JSON.stringify(props),
|
||||
dataSources: JSON.stringify(dataSources),
|
||||
pages: JSON.stringify(pages),
|
||||
});
|
||||
return dynamicPageId;
|
||||
};
|
||||
|
||||
export const configureRepeatedContentBlock = async ({
|
||||
projectId,
|
||||
assetIds,
|
||||
}: {
|
||||
projectId: string;
|
||||
assetIds: [string, string];
|
||||
}) => {
|
||||
const { build, instances, props, dataSources } =
|
||||
await getBuildData(projectId);
|
||||
const addSourcePage = ({
|
||||
id,
|
||||
name,
|
||||
path,
|
||||
history,
|
||||
expression,
|
||||
collectionId,
|
||||
}: {
|
||||
id: string;
|
||||
name: string;
|
||||
path: string;
|
||||
history?: string[];
|
||||
expression: string;
|
||||
collectionId?: string;
|
||||
}) => {
|
||||
const rootInstanceId = `${id}-root`;
|
||||
const blockInstanceId = `${id}-block`;
|
||||
const blockTemplateId = `${id}-templates`;
|
||||
pages.pages.push({
|
||||
...home,
|
||||
id,
|
||||
name,
|
||||
title: JSON.stringify(name),
|
||||
path,
|
||||
history,
|
||||
rootInstanceId,
|
||||
});
|
||||
rootFolder.children.push(id);
|
||||
instances.push(
|
||||
{
|
||||
type: "instance",
|
||||
id: rootInstanceId,
|
||||
component: "ws:element",
|
||||
tag: "body",
|
||||
children: [{ type: "id", value: collectionId ?? blockInstanceId }],
|
||||
},
|
||||
{
|
||||
type: "instance",
|
||||
id: blockInstanceId,
|
||||
component: "ws:block",
|
||||
children: [{ type: "id", value: blockTemplateId }],
|
||||
},
|
||||
{
|
||||
type: "instance",
|
||||
id: blockTemplateId,
|
||||
component: "ws:block-template",
|
||||
children: [],
|
||||
}
|
||||
);
|
||||
props.push({
|
||||
id: `${id}-source`,
|
||||
instanceId: blockInstanceId,
|
||||
name: "src",
|
||||
type: "expression",
|
||||
value: expression,
|
||||
});
|
||||
return blockInstanceId;
|
||||
};
|
||||
|
||||
addSourcePage({
|
||||
id: "mdx-detail-page",
|
||||
name: mdxEditorPageNames.detail,
|
||||
path: "/:assetid",
|
||||
history: [`/${detailSourceAssetId}`],
|
||||
expression: "$ws$system.params.assetid",
|
||||
});
|
||||
|
||||
const collectionId = "mdx-content-collection";
|
||||
const itemParameterId = "mdx-content-collection-item";
|
||||
const itemKeyParameterId = "mdx-content-collection-item-key";
|
||||
configureSourceBlock({
|
||||
instances,
|
||||
props,
|
||||
expression: `${encodeDataSourceVariable(itemParameterId)}?.assetId`,
|
||||
const repeatedPageId = "mdx-repeated-page";
|
||||
const repeatedBlockId = addSourcePage({
|
||||
id: repeatedPageId,
|
||||
name: mdxEditorPageNames.repeated,
|
||||
path: "/repeated",
|
||||
expression: `${encodeDataSourceVariable(itemParameterId)}.assetId`,
|
||||
collectionId,
|
||||
});
|
||||
const body = instances.find((instance) => instance.id === "body");
|
||||
if (body === undefined) {
|
||||
throw new Error("Expected the Content Block fixture body");
|
||||
}
|
||||
body.children = [{ type: "id", value: collectionId }];
|
||||
instances.push({
|
||||
type: "instance",
|
||||
id: collectionId,
|
||||
component: "ws:collection",
|
||||
children: [{ type: "id", value: blockId }],
|
||||
children: [{ type: "id", value: repeatedBlockId }],
|
||||
});
|
||||
props.push(
|
||||
{
|
||||
@@ -226,7 +291,7 @@ export const configureRepeatedContentBlock = async ({
|
||||
instanceId: collectionId,
|
||||
name: "data",
|
||||
type: "json",
|
||||
value: assetIds.map((assetId) => ({ assetId })),
|
||||
value: [sourceAssetId, alternateAssetId].map((assetId) => ({ assetId })),
|
||||
},
|
||||
{
|
||||
id: "mdx-content-collection-item-prop",
|
||||
@@ -261,5 +326,12 @@ export const configureRepeatedContentBlock = async ({
|
||||
instances: JSON.stringify(instances),
|
||||
props: JSON.stringify(props),
|
||||
dataSources: JSON.stringify(dataSources),
|
||||
pages: JSON.stringify(pages),
|
||||
});
|
||||
return {
|
||||
homePageName: home.name,
|
||||
repeatedPageId,
|
||||
detailSourceAssetId,
|
||||
detailAlternateAssetId,
|
||||
};
|
||||
};
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
uploadAsset,
|
||||
} from "../flows/assets-panel";
|
||||
import { openProjectBuilder } from "../flows/builder";
|
||||
import { dragPointer } from "../flows/drag";
|
||||
import {
|
||||
waitForChangeToBeSaved,
|
||||
waitForSyncStatus,
|
||||
@@ -16,17 +15,29 @@ import { test } from "../test";
|
||||
|
||||
test.describe.configure({ mode: "parallel" });
|
||||
|
||||
test("Assets can be selected by dragging across the panel", async ({
|
||||
test("Asset selection and drag work across a long folder list", async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
const fixture = await createContentModeProject({
|
||||
context: context,
|
||||
email: "asset-folder-lasso-select-e2e@webstudio.test",
|
||||
title: "Asset Folder Lasso Select E2E",
|
||||
builderToken: "asset-folder-lasso-select-e2e-builder-token",
|
||||
email: "asset-folder-autoscroll-e2e@webstudio.test",
|
||||
title: "Asset Folder Autoscroll E2E",
|
||||
builderToken: "asset-folder-autoscroll-e2e-builder-token",
|
||||
});
|
||||
|
||||
// The long list is a precondition for the drag, so seed its filler folders together.
|
||||
const createdAt = new Date().toISOString();
|
||||
await insertAssetFolders(
|
||||
Array.from({ length: 24 }, (_, index) => ({
|
||||
id: randomUUID(),
|
||||
projectId: fixture.projectId,
|
||||
name: `Filler ${String(index).padStart(2, "0")}`,
|
||||
parentId: null,
|
||||
createdAt,
|
||||
}))
|
||||
);
|
||||
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
@@ -44,6 +55,8 @@ test("Assets can be selected by dragging across the panel", async ({
|
||||
});
|
||||
const firstAsset = page.getByTitle(firstAssetTitle);
|
||||
const secondAsset = page.getByTitle(secondAssetTitle);
|
||||
await firstAsset.scrollIntoViewIfNeeded();
|
||||
await secondAsset.scrollIntoViewIfNeeded();
|
||||
const firstBounds = await firstAsset.boundingBox();
|
||||
const secondBounds = await secondAsset.boundingBox();
|
||||
const viewport = firstAsset.locator(
|
||||
@@ -83,104 +96,13 @@ test("Assets can be selected by dragging across the panel", async ({
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("Multiselected folders can be dragged into a folder", async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
const fixture = await createContentModeProject({
|
||||
context: context,
|
||||
email: "asset-folder-multifolder-drag-e2e@webstudio.test",
|
||||
title: "Asset Folder Multifolder Drag E2E",
|
||||
builderToken: "asset-folder-multifolder-drag-e2e-builder-token",
|
||||
});
|
||||
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
await openAssetsPanel({ page });
|
||||
const destination = await createAssetFolder({
|
||||
page,
|
||||
name: "Destination",
|
||||
});
|
||||
const alpha = await createAssetFolder({ page, name: "Alpha" });
|
||||
const bravo = await createAssetFolder({ page, name: "Bravo" });
|
||||
|
||||
await alpha.click();
|
||||
await bravo.click({
|
||||
modifiers: [process.platform === "darwin" ? "Meta" : "Control"],
|
||||
});
|
||||
if (
|
||||
(await page.locator('[role="option"][aria-selected="true"]').count()) !== 2
|
||||
) {
|
||||
throw new Error("Expected both folders to be selected before dragging");
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
waitForChangeToBeSaved({ page, timeout: 30_000 }),
|
||||
dragPointer({
|
||||
page,
|
||||
source: bravo,
|
||||
target: destination,
|
||||
ready: async () =>
|
||||
(await destination.getAttribute("data-is-drop-over")) === "true",
|
||||
}),
|
||||
]);
|
||||
await alpha.waitFor({ state: "hidden" });
|
||||
await bravo.waitFor({ state: "hidden" });
|
||||
await destination.dblclick();
|
||||
await page
|
||||
.getByRole("button", { name: "Folder Alpha", exact: true })
|
||||
.waitFor();
|
||||
await page
|
||||
.getByRole("button", { name: "Folder Bravo", exact: true })
|
||||
.waitFor();
|
||||
});
|
||||
|
||||
test("Dragging an asset auto-scrolls a long folder list", async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
const fixture = await createContentModeProject({
|
||||
context: context,
|
||||
email: "asset-folder-autoscroll-e2e@webstudio.test",
|
||||
title: "Asset Folder Autoscroll E2E",
|
||||
builderToken: "asset-folder-autoscroll-e2e-builder-token",
|
||||
});
|
||||
|
||||
// The long list is a precondition for the drag, so seed its filler folders together.
|
||||
const createdAt = new Date().toISOString();
|
||||
await insertAssetFolders(
|
||||
Array.from({ length: 24 }, (_, index) => ({
|
||||
id: randomUUID(),
|
||||
projectId: fixture.projectId,
|
||||
name: `Filler ${String(index).padStart(2, "0")}`,
|
||||
parentId: null,
|
||||
createdAt,
|
||||
}))
|
||||
);
|
||||
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
await openAssetsPanel({ page });
|
||||
const assetTitle = await uploadAsset({
|
||||
page,
|
||||
filename: "upload-image.svg",
|
||||
});
|
||||
await page.keyboard.press("Escape");
|
||||
const scrollArea = page.locator("[data-asset-manager-scroll-area]");
|
||||
const destination = await createAssetFolder({
|
||||
page,
|
||||
name: "Destination",
|
||||
});
|
||||
const asset = page.getByTitle(assetTitle);
|
||||
const asset = firstAsset;
|
||||
await asset.scrollIntoViewIfNeeded();
|
||||
if ((await scrollArea.evaluate((element) => element.scrollTop)) === 0) {
|
||||
throw new Error("Expected the long asset list to be scrolled");
|
||||
@@ -254,61 +176,7 @@ test("Dragging an asset auto-scrolls a long folder list", async ({
|
||||
|
||||
await asset.waitFor({ state: "hidden" });
|
||||
await destination.dblclick();
|
||||
await page.getByTitle(assetTitle).waitFor();
|
||||
});
|
||||
|
||||
test("Multiselected assets can be moved from the context menu", async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
const fixture = await createContentModeProject({
|
||||
context: context,
|
||||
email: "asset-folder-menu-move-e2e@webstudio.test",
|
||||
title: "Asset Folder Menu Move E2E",
|
||||
builderToken: "asset-folder-menu-move-e2e-builder-token",
|
||||
});
|
||||
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
await openAssetsPanel({ page });
|
||||
const destination = await createAssetFolder({
|
||||
page,
|
||||
name: "Destination",
|
||||
});
|
||||
const firstAssetTitle = await uploadAsset({
|
||||
page,
|
||||
filename: "upload-image.svg",
|
||||
});
|
||||
const secondAssetTitle = await uploadAsset({
|
||||
page,
|
||||
filename: "replacement-image.svg",
|
||||
});
|
||||
const firstAsset = page.getByTitle(firstAssetTitle);
|
||||
const secondAsset = page.getByTitle(secondAssetTitle);
|
||||
|
||||
await firstAsset.click();
|
||||
await secondAsset.click({
|
||||
modifiers: [process.platform === "darwin" ? "Meta" : "Control"],
|
||||
});
|
||||
await secondAsset.click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "Move", exact: true }).click();
|
||||
const dialog = page.getByRole("dialog", { name: "Move items" });
|
||||
await dialog.getByRole("combobox", { name: "Folder" }).click();
|
||||
await page.getByRole("option", { name: "Destination", exact: true }).click();
|
||||
await Promise.all([
|
||||
waitForChangeToBeSaved({ page, timeout: 30_000 }),
|
||||
dialog.getByRole("button", { name: "Move", exact: true }).click(),
|
||||
]);
|
||||
|
||||
await firstAsset.waitFor({ state: "hidden" });
|
||||
await secondAsset.waitFor({ state: "hidden" });
|
||||
await destination.dblclick();
|
||||
await page.getByTitle(firstAssetTitle).waitFor();
|
||||
await page.getByTitle(secondAssetTitle).waitFor();
|
||||
await firstAsset.waitFor();
|
||||
});
|
||||
|
||||
test("Folders can be multiselected and deleted as one operation", async ({
|
||||
@@ -322,6 +190,16 @@ test("Folders can be multiselected and deleted as one operation", async ({
|
||||
builderToken: "asset-folder-multiselect-e2e-builder-token",
|
||||
});
|
||||
const folderNames = ["Alpha", "Bravo", "Charlie"];
|
||||
const createdAt = new Date().toISOString();
|
||||
await insertAssetFolders(
|
||||
folderNames.map((name) => ({
|
||||
id: randomUUID(),
|
||||
projectId: fixture.projectId,
|
||||
name,
|
||||
parentId: null,
|
||||
createdAt,
|
||||
}))
|
||||
);
|
||||
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
@@ -330,10 +208,9 @@ test("Folders can be multiselected and deleted as one operation", async ({
|
||||
});
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
await openAssetsPanel({ page });
|
||||
const folders = [];
|
||||
for (const name of folderNames) {
|
||||
folders.push(await createAssetFolder({ page, name }));
|
||||
}
|
||||
const folders = folderNames.map((name) =>
|
||||
page.getByRole("button", { name: `Folder ${name}`, exact: true })
|
||||
);
|
||||
|
||||
await folders[1]!.click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "Settings" }).waitFor();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import {
|
||||
createAssetFolder,
|
||||
dragAssetToFolder,
|
||||
@@ -9,7 +10,8 @@ import {
|
||||
waitForChangeToBeSaved,
|
||||
waitForSyncStatus,
|
||||
} from "../flows/sync-status";
|
||||
import { createContentModeProject } from "../fixtures/content-mode-suite";
|
||||
import { insertAssetFolders, insertAuthorizationToken } from "../db";
|
||||
import { createProjectThroughApi } from "../fixtures/create-project";
|
||||
import { dashboardUrl, test } from "../test";
|
||||
|
||||
test("Asset folder moves survive Builder reload and project cloning", async ({
|
||||
@@ -17,26 +19,41 @@ test("Asset folder moves survive Builder reload and project cloning", async ({
|
||||
context,
|
||||
}) => {
|
||||
const cloneTitle = "Asset Folder Clone Result";
|
||||
const fixture = await createContentModeProject({
|
||||
const projectId = await createProjectThroughApi({
|
||||
context,
|
||||
email: "asset-folder-clone-e2e@webstudio.test",
|
||||
title: "Asset Folder Clone Source",
|
||||
builderToken: "asset-folder-clone-e2e-builder-token",
|
||||
});
|
||||
const builderToken = randomUUID();
|
||||
const parentId = randomUUID();
|
||||
const childId = randomUUID();
|
||||
const createdAt = new Date().toISOString();
|
||||
// This hierarchy is the starting point for the drag and clone checks.
|
||||
await Promise.all([
|
||||
insertAuthorizationToken({
|
||||
token: builderToken,
|
||||
projectId,
|
||||
name: "E2E asset folder builder",
|
||||
relation: "builders",
|
||||
}),
|
||||
insertAssetFolders(
|
||||
[
|
||||
{ id: parentId, name: "Parent", parentId: null },
|
||||
{ id: childId, name: "Child", parentId },
|
||||
].map((folder) => ({ ...folder, projectId, createdAt }))
|
||||
),
|
||||
]);
|
||||
const openSource = () =>
|
||||
openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
openProjectBuilder({ page, projectId, authToken: builderToken });
|
||||
|
||||
await openSource();
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
await openAssetsPanel({ page });
|
||||
|
||||
const parent = await createAssetFolder({ page, name: "Parent" });
|
||||
await parent.dblclick();
|
||||
const child = await createAssetFolder({ page, name: "Child" });
|
||||
const child = page.getByRole("button", { name: "Folder Child", exact: true });
|
||||
await page
|
||||
.getByRole("button", { name: "Folder Parent", exact: true })
|
||||
.dblclick();
|
||||
await child.dblclick();
|
||||
const grandchild = await createAssetFolder({ page, name: "Grandchild" });
|
||||
await grandchild.dblclick();
|
||||
@@ -114,7 +131,7 @@ test("Asset folder moves survive Builder reload and project cloning", async ({
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
|
||||
const cloneUrl = new URL("/dashboard", dashboardUrl);
|
||||
cloneUrl.searchParams.set("projectToCloneAuthToken", fixture.builderToken);
|
||||
cloneUrl.searchParams.set("projectToCloneAuthToken", builderToken);
|
||||
await page.goto(cloneUrl.href);
|
||||
const cloneDialog = page.getByRole("dialog", { name: "Clone project" });
|
||||
await cloneDialog.locator('input[name="title"]').fill(cloneTitle);
|
||||
|
||||
+116
-88
@@ -16,7 +16,8 @@ import {
|
||||
openShareDialog,
|
||||
updateShareLinkRole,
|
||||
} from "../flows/share-dialog";
|
||||
import { waitForSyncStatus } from "../flows/sync-status";
|
||||
import { waitForSyncComplete } from "../flows/sync-status";
|
||||
import { insertTemplateAfterCanvasText } from "../flows/template-insertion";
|
||||
import { createContentModeProject } from "../fixtures/content-mode-suite";
|
||||
import { newIsolatedPage, test } from "../test";
|
||||
import { measure } from "../perf";
|
||||
@@ -129,8 +130,8 @@ test("Share links enforce viewer, editor, builder, admin, and owner permissions"
|
||||
const editor = await newIsolatedPage(browser);
|
||||
const builderPage = await newIsolatedPage(browser);
|
||||
const admin = await newIsolatedPage(browser);
|
||||
const visitor = await newIsolatedPage(browser);
|
||||
const editedText = "Share-link editor text";
|
||||
const collaborativeText = "Collaborative editor text";
|
||||
|
||||
try {
|
||||
expectLinkMode({ link: viewerUrl, mode: "preview" });
|
||||
@@ -139,13 +140,7 @@ test("Share links enforce viewer, editor, builder, admin, and owner permissions"
|
||||
expectLinkMode({ link: adminUrl, mode: "design" });
|
||||
|
||||
await Promise.all([
|
||||
(async () => {
|
||||
await openBuilderUrl({ page: editor.page, url: editorUrl });
|
||||
await waitForCanvasText({ page: editor.page, text: baselineText });
|
||||
await waitForSyncStatus({ page: editor.page, status: "idle" });
|
||||
expectCurrentMode({ pageUrl: editor.page.url(), mode: "content" });
|
||||
})(),
|
||||
(async () => {
|
||||
test.step("Viewer can view and gains design controls after the owner changes the same link", async () => {
|
||||
await openBuilderUrl({ page: viewer.page, url: viewerUrl });
|
||||
await waitForCanvasText({ page: viewer.page, text: baselineText });
|
||||
await expectShareUnavailable({ page: viewer.page });
|
||||
@@ -157,28 +152,32 @@ test("Share links enforce viewer, editor, builder, admin, and owner permissions"
|
||||
locator: viewer.page.getByRole("tab", { name: "Style" }),
|
||||
message: "Expected Style tab to be unavailable for viewer link",
|
||||
});
|
||||
})(),
|
||||
(async () => {
|
||||
await openBuilderUrl({ page: builderPage.page, url: builderUrl });
|
||||
await waitForCanvasText({
|
||||
page: builderPage.page,
|
||||
text: baselineText,
|
||||
await updateShareLinkRole({
|
||||
page: ownerPage,
|
||||
name: "E2E Viewer link",
|
||||
role: "Builder",
|
||||
});
|
||||
await waitForSyncStatus({ page: builderPage.page, status: "idle" });
|
||||
await expectShareUnavailable({ page: builderPage.page });
|
||||
const updatedBuilderUrl = await copyShareLink({
|
||||
page: ownerPage,
|
||||
name: "E2E Viewer link",
|
||||
});
|
||||
expectLinkMode({ link: updatedBuilderUrl, mode: "design" });
|
||||
|
||||
await openBuilderUrl({ page: viewer.page, url: updatedBuilderUrl });
|
||||
await waitForCanvasText({ page: viewer.page, text: baselineText });
|
||||
await expectShareUnavailable({ page: viewer.page });
|
||||
await selectCanvasTextInstance({
|
||||
page: builderPage.page,
|
||||
page: viewer.page,
|
||||
text: baselineText,
|
||||
});
|
||||
await builderPage.page
|
||||
await viewer.page
|
||||
.getByRole("tab", { name: "Style" })
|
||||
.waitFor({ state: "visible", timeout: 10_000 });
|
||||
})(),
|
||||
(async () => {
|
||||
}),
|
||||
test.step("Admin may publish", async () => {
|
||||
await openBuilderUrl({ page: admin.page, url: adminUrl });
|
||||
await waitForCanvasText({ page: admin.page, text: baselineText });
|
||||
await waitForSyncStatus({ page: admin.page, status: "idle" });
|
||||
await waitForSyncComplete({ page: admin.page });
|
||||
await expectShareUnavailable({ page: admin.page });
|
||||
|
||||
const publishButton = admin.page.getByRole("button", {
|
||||
@@ -188,77 +187,106 @@ test("Share links enforce viewer, editor, builder, admin, and owner permissions"
|
||||
if (await publishButton.isDisabled()) {
|
||||
throw new Error("Expected admin share link to allow publishing");
|
||||
}
|
||||
})(),
|
||||
}),
|
||||
test.step("Editor can save content and collaborate with a Builder", async () => {
|
||||
await openBuilderUrl({ page: editor.page, url: editorUrl });
|
||||
await waitForCanvasText({ page: editor.page, text: baselineText });
|
||||
await waitForSyncComplete({ page: editor.page });
|
||||
expectCurrentMode({ pageUrl: editor.page.url(), mode: "content" });
|
||||
|
||||
await insertTemplateAfterCanvasText({
|
||||
page: editor.page,
|
||||
anchorText: baselineText,
|
||||
templateName: fixture.collaborationTemplateName,
|
||||
});
|
||||
await waitForCanvasText({
|
||||
page: editor.page,
|
||||
text: fixture.collaborationTemplateText,
|
||||
});
|
||||
await openBuilderUrl({ page: builderPage.page, url: builderUrl });
|
||||
await waitForCanvasText({
|
||||
page: builderPage.page,
|
||||
text: baselineText,
|
||||
});
|
||||
await waitForSyncComplete({ page: builderPage.page });
|
||||
await expectShareUnavailable({ page: builderPage.page });
|
||||
|
||||
await selectCanvasTextInstance({
|
||||
page: builderPage.page,
|
||||
text: baselineText,
|
||||
});
|
||||
await builderPage.page
|
||||
.getByRole("tab", { name: "Style" })
|
||||
.waitFor({ state: "visible", timeout: 10_000 });
|
||||
|
||||
await waitForCanvasText({
|
||||
page: builderPage.page,
|
||||
text: fixture.collaborationTemplateText,
|
||||
});
|
||||
await waitForCanvasText({
|
||||
page: editor.page,
|
||||
text: fixture.shareLinkEditableText,
|
||||
});
|
||||
await replaceCanvasText({
|
||||
page: editor.page,
|
||||
currentText: fixture.shareLinkEditableText,
|
||||
text: editedText,
|
||||
});
|
||||
|
||||
await replaceCanvasText({
|
||||
page: editor.page,
|
||||
currentText: fixture.collaborationTemplateText,
|
||||
text: collaborativeText,
|
||||
});
|
||||
await selectCanvasTextInstance({
|
||||
page: editor.page,
|
||||
text: collaborativeText,
|
||||
});
|
||||
await expectLocatorHidden({
|
||||
locator: editor.page.getByRole("tab", { name: "Style" }),
|
||||
message:
|
||||
"Expected edit-only collaborator to be blocked from design controls",
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
(async () => {
|
||||
await openBuilderUrl({ page: editor.page, url: editorUrl });
|
||||
await waitForCanvasText({ page: editor.page, text: editedText });
|
||||
await waitForSyncComplete({ page: editor.page });
|
||||
await expectShareUnavailable({ page: editor.page });
|
||||
|
||||
await selectCanvasTextInstanceForProps({
|
||||
page: editor.page,
|
||||
text: "Initial link",
|
||||
propertyLabel: "Href",
|
||||
});
|
||||
await expectLocatorHidden({
|
||||
locator: editor.page.getByRole("tab", { name: "Style" }),
|
||||
message: "Expected Style tab to be unavailable for editor link",
|
||||
});
|
||||
})(),
|
||||
(async () => {
|
||||
await openBuilderUrl({ page: builderPage.page, url: builderUrl });
|
||||
await waitForCanvasText({
|
||||
page: builderPage.page,
|
||||
text: collaborativeText,
|
||||
});
|
||||
await selectCanvasTextInstance({
|
||||
page: builderPage.page,
|
||||
text: collaborativeText,
|
||||
});
|
||||
await builderPage.page
|
||||
.getByRole("tab", { name: "Style" })
|
||||
.waitFor({ state: "visible" });
|
||||
await waitForSyncComplete({ page: builderPage.page });
|
||||
})(),
|
||||
]);
|
||||
}),
|
||||
]);
|
||||
|
||||
await waitForCanvasText({
|
||||
page: editor.page,
|
||||
text: fixture.shareLinkEditableText,
|
||||
});
|
||||
await replaceCanvasText({
|
||||
page: editor.page,
|
||||
currentText: fixture.shareLinkEditableText,
|
||||
text: editedText,
|
||||
});
|
||||
|
||||
await openBuilderUrl({ page: editor.page, url: editorUrl });
|
||||
await waitForCanvasText({ page: editor.page, text: editedText });
|
||||
await waitForSyncStatus({ page: editor.page, status: "idle" });
|
||||
await expectShareUnavailable({ page: editor.page });
|
||||
|
||||
await selectCanvasTextInstanceForProps({
|
||||
page: editor.page,
|
||||
text: "Initial link",
|
||||
propertyLabel: "Href",
|
||||
});
|
||||
await expectLocatorHidden({
|
||||
locator: editor.page.getByRole("tab", { name: "Style" }),
|
||||
message: "Expected Style tab to be unavailable for editor link",
|
||||
});
|
||||
|
||||
await createShareLink({
|
||||
page: ownerPage,
|
||||
name: "E2E Updated link",
|
||||
role: "Viewer",
|
||||
});
|
||||
const updatedViewerUrl = await copyShareLink({
|
||||
page: ownerPage,
|
||||
name: "E2E Updated link",
|
||||
});
|
||||
expectLinkMode({ link: updatedViewerUrl, mode: "preview" });
|
||||
|
||||
await openBuilderUrl({ page: visitor.page, url: updatedViewerUrl });
|
||||
await waitForCanvasText({ page: visitor.page, text: baselineText });
|
||||
await expectLocatorHidden({
|
||||
locator: visitor.page.getByRole("tab", { name: "Style" }),
|
||||
message: "Expected updated link to start as viewer",
|
||||
});
|
||||
|
||||
await updateShareLinkRole({
|
||||
page: ownerPage,
|
||||
name: "E2E Updated link",
|
||||
role: "Builder",
|
||||
});
|
||||
const updatedBuilderUrl = await copyShareLink({
|
||||
page: ownerPage,
|
||||
name: "E2E Updated link",
|
||||
});
|
||||
expectLinkMode({ link: updatedBuilderUrl, mode: "design" });
|
||||
|
||||
await openBuilderUrl({ page: visitor.page, url: updatedBuilderUrl });
|
||||
await waitForCanvasText({ page: visitor.page, text: baselineText });
|
||||
await selectCanvasTextInstance({
|
||||
page: visitor.page,
|
||||
text: baselineText,
|
||||
});
|
||||
await visitor.page
|
||||
.getByRole("tab", { name: "Style" })
|
||||
.waitFor({ state: "visible", timeout: 10_000 });
|
||||
} finally {
|
||||
await viewer.close();
|
||||
await editor.close();
|
||||
await builderPage.close();
|
||||
await admin.close();
|
||||
await visitor.close();
|
||||
}
|
||||
});
|
||||
@@ -153,42 +153,6 @@ test("Content templates persist with styles and assets, including after Builder
|
||||
count: 2,
|
||||
});
|
||||
|
||||
await measure("content mode reload editor for asset template", async () => {
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
});
|
||||
});
|
||||
await waitForCanvasImage({
|
||||
page,
|
||||
alt: fixture.assetTemplateImageAlt,
|
||||
});
|
||||
await waitForCanvasVideoSource({
|
||||
page,
|
||||
sourceName: fixture.assetTemplateVideoName,
|
||||
});
|
||||
await waitForCanvasTextStyle({
|
||||
page,
|
||||
text: fixture.styledHeadingTemplateText,
|
||||
property: "font-size",
|
||||
value: fixture.styledHeadingTemplateFontSize,
|
||||
});
|
||||
await waitForCanvasTextStyle({
|
||||
page,
|
||||
text: fixture.tokenTemplateVisibleText,
|
||||
property: "font-size",
|
||||
value: fixture.tokenTemplateFontSize,
|
||||
});
|
||||
await waitForCanvasTextStyleCount({
|
||||
page,
|
||||
text: fixture.isolatedLocalTemplateText,
|
||||
property: "font-size",
|
||||
value: fixture.isolatedLocalTemplateFontSize,
|
||||
count: 2,
|
||||
});
|
||||
await waitForSyncComplete({ page });
|
||||
await test.step("Builder can copy and paste the inserted image and reload its asset references", async () => {
|
||||
await measure("asset copy open build mode", async () => {
|
||||
await openProjectBuilder({
|
||||
@@ -224,13 +188,41 @@ test("Content templates persist with styles and assets, including after Builder
|
||||
);
|
||||
}
|
||||
|
||||
await measure("asset copy reload builder", async () => {
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
await measure(
|
||||
"content mode reload editor after Builder copy and paste",
|
||||
async () => {
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
});
|
||||
}
|
||||
);
|
||||
await waitForCanvasVideoSource({
|
||||
page,
|
||||
sourceName: fixture.assetTemplateVideoName,
|
||||
});
|
||||
await waitForCanvasTextStyle({
|
||||
page,
|
||||
text: fixture.styledHeadingTemplateText,
|
||||
property: "font-size",
|
||||
value: fixture.styledHeadingTemplateFontSize,
|
||||
});
|
||||
await waitForCanvasTextStyle({
|
||||
page,
|
||||
text: fixture.tokenTemplateVisibleText,
|
||||
property: "font-size",
|
||||
value: fixture.tokenTemplateFontSize,
|
||||
});
|
||||
await waitForCanvasTextStyleCount({
|
||||
page,
|
||||
text: fixture.isolatedLocalTemplateText,
|
||||
property: "font-size",
|
||||
value: fixture.isolatedLocalTemplateFontSize,
|
||||
count: 2,
|
||||
});
|
||||
await waitForSyncComplete({ page });
|
||||
await waitForCanvasImageCount({
|
||||
page,
|
||||
alt: fixture.assetTemplateImageAlt,
|
||||
@@ -245,82 +237,18 @@ test("Content templates persist with styles and assets, including after Builder
|
||||
});
|
||||
});
|
||||
|
||||
test("Editor can manage assets and create an ordinary folder in content mode", async ({
|
||||
test("Editor can save assets, folders, and collection entries in content mode", async ({
|
||||
page,
|
||||
}) => {
|
||||
const folderName = "Editor ordinary assets";
|
||||
const uploadFilename = "upload-image.svg";
|
||||
const uploadFilename = "large-image.svg";
|
||||
const replacementFilename = "replacement-image.svg";
|
||||
|
||||
await measure("content mode open editor for asset workflows", async () => {
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
});
|
||||
});
|
||||
await waitForCanvasText({ page, text: "Initial content" });
|
||||
await waitForSyncComplete({ page });
|
||||
|
||||
let uploadedAssetTitle = "";
|
||||
await measure("content mode upload asset", async () => {
|
||||
await openAssetsPanel({ page });
|
||||
uploadedAssetTitle = await uploadAsset({
|
||||
page,
|
||||
filename: uploadFilename,
|
||||
});
|
||||
});
|
||||
|
||||
let replacementAssetTitle = "";
|
||||
await measure("content mode replace asset", async () => {
|
||||
await openAssetSettings({ page, filename: uploadedAssetTitle });
|
||||
const assetId = await page.locator("#asset-manager-id").inputValue();
|
||||
if (assetId.length === 0) {
|
||||
throw new Error(
|
||||
"Expected Asset settings to expose the uploaded asset id"
|
||||
);
|
||||
}
|
||||
await page.getByText("0 uses", { exact: true }).waitFor();
|
||||
replacementAssetTitle = await replaceSelectedAsset({
|
||||
page,
|
||||
filename: replacementFilename,
|
||||
});
|
||||
});
|
||||
|
||||
await measure("content mode delete asset", async () => {
|
||||
await openAssetSettings({ page, filename: replacementAssetTitle });
|
||||
await deleteSelectedAsset({
|
||||
page,
|
||||
filename: replacementAssetTitle,
|
||||
});
|
||||
});
|
||||
|
||||
await createAssetFolder({ page, name: folderName });
|
||||
|
||||
await measure("content mode reload editor for asset workflows", async () => {
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
});
|
||||
});
|
||||
await openAssetsPanel({ page });
|
||||
await page.getByTitle(uploadedAssetTitle).waitFor({ state: "hidden" });
|
||||
await page.getByTitle(replacementAssetTitle).waitFor({ state: "hidden" });
|
||||
await page
|
||||
.getByRole("button", { name: `Folder ${folderName}`, exact: true })
|
||||
.waitFor();
|
||||
await waitForSyncComplete({ page });
|
||||
});
|
||||
|
||||
test("Editor can create and reload a content collection entry", async ({
|
||||
page,
|
||||
}) => {
|
||||
const folderName = "Content collection entries";
|
||||
const collectionName = "Content collection entries";
|
||||
const folderName = "Editor ordinary assets";
|
||||
const entryTitle = "Content collection entry";
|
||||
const entryFilename = "content-collection-entry.mdx";
|
||||
const assetsPanel = page.getByRole("tabpanel", { name: "Assets" });
|
||||
const browseRoot = () =>
|
||||
assetsPanel.getByRole("button", { name: "Root", exact: true }).click();
|
||||
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
@@ -329,12 +257,12 @@ test("Editor can create and reload a content collection entry", async ({
|
||||
});
|
||||
await waitForSyncComplete({ page });
|
||||
await openAssetsPanel({ page });
|
||||
const folder = await createAssetFolder({
|
||||
const collection = await createAssetFolder({
|
||||
page,
|
||||
name: folderName,
|
||||
name: collectionName,
|
||||
useAsContentCollection: true,
|
||||
});
|
||||
await folder.dblclick();
|
||||
await collection.dblclick();
|
||||
await page.getByRole("button", { name: "Collection settings" }).waitFor();
|
||||
|
||||
await openProjectBuilder({
|
||||
@@ -359,38 +287,7 @@ test("Editor can create and reload a content collection entry", async ({
|
||||
await page.getByTitle("collection.json").waitFor({ state: "visible" });
|
||||
await page.getByTitle("template.mdx").waitFor({ state: "visible" });
|
||||
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
});
|
||||
await openAssetsPanel({ page });
|
||||
await waitForAsset({ page, filename: entryFilename });
|
||||
await page.getByTitle("collection.json").waitFor({ state: "visible" });
|
||||
await page.getByTitle("template.mdx").waitFor({ state: "visible" });
|
||||
});
|
||||
|
||||
test("Editor can replace image source with asset in content mode", async ({
|
||||
page,
|
||||
}) => {
|
||||
const uploadFilename = "large-image.svg";
|
||||
const replacementFilename = "replacement-image.svg";
|
||||
|
||||
await measure(
|
||||
"content mode open editor for image source asset replacement",
|
||||
async () => {
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
});
|
||||
}
|
||||
);
|
||||
await waitForCanvasText({ page, text: "Initial content" });
|
||||
await waitForSyncComplete({ page });
|
||||
|
||||
await browseRoot();
|
||||
await insertTemplateAfterCanvasText({
|
||||
page,
|
||||
anchorText: "Initial content",
|
||||
@@ -445,22 +342,74 @@ test("Editor can replace image source with asset in content mode", async ({
|
||||
});
|
||||
await waitForSyncComplete({ page });
|
||||
|
||||
await measure(
|
||||
"content mode reload editor for image source asset replacement",
|
||||
async () => {
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
const folder = await createAssetFolder({ page, name: folderName });
|
||||
await folder.dblclick();
|
||||
|
||||
const deletedAsset =
|
||||
await test.step("Upload, replace and delete an unused asset in the ordinary folder", async () => {
|
||||
const uploadFilename = "upload-image.svg";
|
||||
const replacementFilename = "large-image.svg";
|
||||
let uploadedAssetTitle = "";
|
||||
await measure("content mode upload asset", async () => {
|
||||
uploadedAssetTitle = await uploadAsset({
|
||||
page,
|
||||
filename: uploadFilename,
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
let replacementAssetTitle = "";
|
||||
await measure("content mode replace asset", async () => {
|
||||
await openAssetSettings({ page, filename: uploadedAssetTitle });
|
||||
const assetId = await page.locator("#asset-manager-id").inputValue();
|
||||
if (assetId.length === 0) {
|
||||
throw new Error(
|
||||
"Expected Asset settings to expose the uploaded asset id"
|
||||
);
|
||||
}
|
||||
await page.getByText("0 uses", { exact: true }).waitFor();
|
||||
replacementAssetTitle = await replaceSelectedAsset({
|
||||
page,
|
||||
filename: replacementFilename,
|
||||
});
|
||||
});
|
||||
|
||||
await measure("content mode delete asset", async () => {
|
||||
await openAssetSettings({ page, filename: replacementAssetTitle });
|
||||
await deleteSelectedAsset({
|
||||
page,
|
||||
filename: replacementAssetTitle,
|
||||
});
|
||||
});
|
||||
|
||||
return { uploadedAssetTitle, replacementAssetTitle };
|
||||
});
|
||||
|
||||
await browseRoot();
|
||||
await collection.dblclick();
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
});
|
||||
await openAssetsPanel({ page });
|
||||
await waitForAsset({ page, filename: entryFilename });
|
||||
await page.getByTitle("collection.json").waitFor({ state: "visible" });
|
||||
await page.getByTitle("template.mdx").waitFor({ state: "visible" });
|
||||
await browseRoot();
|
||||
const expectDeletedAssetAbsent = async () => {
|
||||
await expect(
|
||||
assetsPanel.getByTitle(deletedAsset.uploadedAssetTitle)
|
||||
).toHaveCount(0);
|
||||
await expect(
|
||||
assetsPanel.getByTitle(deletedAsset.replacementAssetTitle)
|
||||
).toHaveCount(0);
|
||||
};
|
||||
await expectDeletedAssetAbsent();
|
||||
await waitForCanvasImageSourceName({
|
||||
page,
|
||||
sourceName: "replacement-image_",
|
||||
});
|
||||
await openAssetsPanel({ page });
|
||||
await page.getByTitle(replacementAssetTitle).waitFor();
|
||||
await waitForSyncComplete({ page });
|
||||
const reloadedCanvas = await waitForCanvasFrame({ page });
|
||||
@@ -469,4 +418,6 @@ test("Editor can replace image source with asset in content mode", async ({
|
||||
);
|
||||
await expect(replacementImage).toHaveAttribute("width", "120");
|
||||
await expect(replacementImage).toHaveAttribute("height", "80");
|
||||
await folder.dblclick();
|
||||
await expectDeletedAssetAbsent();
|
||||
});
|
||||
@@ -1,9 +1,6 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { openProjectBuilder, waitForCanvasText } from "../flows/builder";
|
||||
import { selectCanvasTextInstance } from "../flows/canvas-selection";
|
||||
import { expectLocatorHidden } from "../flows/assertions";
|
||||
import { waitForCanvasTextStyle } from "../flows/canvas-style";
|
||||
import { replaceCanvasText } from "../flows/content-editing";
|
||||
import {
|
||||
choosePageSettingsSocialImageAsset,
|
||||
createPageFromTemplate,
|
||||
@@ -17,17 +14,14 @@ import {
|
||||
openPageSettings,
|
||||
} from "../flows/pages-panel";
|
||||
import { waitForSyncComplete } from "../flows/sync-status";
|
||||
import { insertTemplateAfterCanvasText } from "../flows/template-insertion";
|
||||
import { createContentModeProject } from "../fixtures/content-mode-suite";
|
||||
import type { SeededContentModeProject } from "../fixtures/content-mode-project";
|
||||
import { newIsolatedPage, test } from "../test";
|
||||
import { test } from "../test";
|
||||
import { measure } from "../perf";
|
||||
import { e2ePaidPlanName } from "../plans";
|
||||
|
||||
let fixture: SeededContentModeProject;
|
||||
|
||||
test.describe.configure({ mode: "parallel" });
|
||||
|
||||
test.beforeEach(async ({ context }) => {
|
||||
fixture = await createContentModeProject({
|
||||
context,
|
||||
@@ -195,93 +189,3 @@ test("Editor can create a styled page, edit allowed settings, and reload it in c
|
||||
});
|
||||
await waitForSyncComplete({ page });
|
||||
});
|
||||
|
||||
test("Edit-only and build-capable users can collaborate in content mode", async ({
|
||||
browser,
|
||||
}) => {
|
||||
const editor = await newIsolatedPage(browser);
|
||||
const builder = await newIsolatedPage(browser);
|
||||
|
||||
try {
|
||||
await measure("open editor and builder sessions", async () => {
|
||||
await Promise.all([
|
||||
openProjectBuilder({
|
||||
page: editor.page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
}),
|
||||
openProjectBuilder({
|
||||
page: builder.page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
await waitForCanvasText({ page: editor.page, text: "Initial content" });
|
||||
await waitForCanvasText({ page: builder.page, text: "Initial content" });
|
||||
await waitForSyncComplete({ page: editor.page });
|
||||
await waitForSyncComplete({ page: builder.page });
|
||||
|
||||
await insertTemplateAfterCanvasText({
|
||||
page: editor.page,
|
||||
anchorText: "Initial content",
|
||||
templateName: fixture.collaborationTemplateName,
|
||||
});
|
||||
await waitForCanvasText({
|
||||
page: editor.page,
|
||||
text: fixture.collaborationTemplateText,
|
||||
});
|
||||
await waitForSyncComplete({ page: editor.page });
|
||||
|
||||
await openProjectBuilder({
|
||||
page: builder.page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
await waitForCanvasText({
|
||||
page: builder.page,
|
||||
text: fixture.collaborationTemplateText,
|
||||
});
|
||||
|
||||
await replaceCanvasText({
|
||||
page: editor.page,
|
||||
currentText: fixture.collaborationTemplateText,
|
||||
text: "Collaborative editor text",
|
||||
});
|
||||
await waitForSyncComplete({ page: editor.page });
|
||||
|
||||
await selectCanvasTextInstance({
|
||||
page: editor.page,
|
||||
text: "Collaborative editor text",
|
||||
});
|
||||
await expectLocatorHidden({
|
||||
locator: editor.page.getByRole("tab", { name: "Style" }),
|
||||
message:
|
||||
"Expected edit-only collaborator to be blocked from design controls",
|
||||
});
|
||||
|
||||
await openProjectBuilder({
|
||||
page: builder.page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
await waitForCanvasText({
|
||||
page: builder.page,
|
||||
text: "Collaborative editor text",
|
||||
});
|
||||
|
||||
await selectCanvasTextInstance({
|
||||
page: builder.page,
|
||||
text: "Collaborative editor text",
|
||||
});
|
||||
await builder.page
|
||||
.getByRole("tab", { name: "Style" })
|
||||
.waitFor({ state: "visible" });
|
||||
await waitForSyncComplete({ page: editor.page });
|
||||
await waitForSyncComplete({ page: builder.page });
|
||||
} finally {
|
||||
await editor.close();
|
||||
await builder.close();
|
||||
}
|
||||
});
|
||||
@@ -47,7 +47,7 @@ test("Editor MCP saves permitted pages, folders, and assets", async ({
|
||||
viewer: viewerDirectory,
|
||||
builder: builderDirectory,
|
||||
};
|
||||
const clients = new Map<keyof typeof directories, Client>();
|
||||
const clients = new Map<keyof typeof directories, Promise<Client>>();
|
||||
const connect = async (cwd: string, configDirectory: string) => {
|
||||
const client = new Client({
|
||||
name: "mcp-editor-pages-e2e",
|
||||
@@ -71,19 +71,25 @@ test("Editor MCP saves permitted pages, folders, and assets", async ({
|
||||
}
|
||||
return client;
|
||||
};
|
||||
const getClient = (role: keyof typeof directories) => {
|
||||
let client = clients.get(role);
|
||||
if (client === undefined) {
|
||||
client = connect(
|
||||
directories[role],
|
||||
role === "editorRead" ? directories.editor : directories[role]
|
||||
);
|
||||
// A prestarted connection can fail before its first tool call is ready.
|
||||
client.catch(() => undefined);
|
||||
clients.set(role, client);
|
||||
}
|
||||
return client;
|
||||
};
|
||||
const call = async (
|
||||
tool: string,
|
||||
input: Record<string, unknown>,
|
||||
role: keyof typeof directories = "editor"
|
||||
) => {
|
||||
let client = clients.get(role);
|
||||
if (client === undefined) {
|
||||
client = await connect(
|
||||
directories[role],
|
||||
role === "editorRead" ? directories.editor : directories[role]
|
||||
);
|
||||
clients.set(role, client);
|
||||
}
|
||||
const client = await getClient(role);
|
||||
const result = await client.callTool({ name: tool, arguments: input });
|
||||
return JSON.parse(JSON.stringify(result.structuredContent));
|
||||
};
|
||||
@@ -145,6 +151,10 @@ test("Editor MCP saves permitted pages, folders, and assets", async ({
|
||||
expect(updated.ok, updated.error?.message).toBe(true);
|
||||
expect(updated.meta.session.commitStatus).toBe("committed");
|
||||
|
||||
// The remaining CLI processes have separate session directories. Start
|
||||
// the role checks' connections while the fresh editor reads this commit.
|
||||
getClient("viewer");
|
||||
getClient("builder");
|
||||
const reloaded = await call("get-page", { pageId }, "editorRead");
|
||||
expect(reloaded.ok).toBe(true);
|
||||
expect(reloaded.data).toMatchObject({
|
||||
@@ -263,7 +273,12 @@ test("Editor MCP saves permitted pages, folders, and assets", async ({
|
||||
const builderPage = await call("get-page", { pageId }, "builder");
|
||||
expect(builderPage.data.meta.status).toBe("302");
|
||||
} finally {
|
||||
await Promise.all(Array.from(clients.values(), (client) => client.close()));
|
||||
const connections = await Promise.allSettled(clients.values());
|
||||
await Promise.all(
|
||||
connections.flatMap((connection) =>
|
||||
connection.status === "fulfilled" ? [connection.value.close()] : []
|
||||
)
|
||||
);
|
||||
await Promise.all([
|
||||
rm(directory, { recursive: true, force: true }),
|
||||
rm(freshDirectory, { recursive: true, force: true }),
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
import type { Page, Response } from "@playwright/test";
|
||||
import type { Dialog, Page, Request, Response } from "@playwright/test";
|
||||
import { parseMdxDocument } from "@webstudio-is/content-engine/mdx";
|
||||
import {
|
||||
configureDynamicDetailContentBlock,
|
||||
configureEmptyHeadingTemplate,
|
||||
configureNamedTemplateLifecycle,
|
||||
configureRepresentableContentBlockBody,
|
||||
configureRepeatedContentBlock,
|
||||
lifecycleTemplateId,
|
||||
mdxEditorPageNames,
|
||||
prepareMdxEditorPages,
|
||||
} from "../fixtures/mdx-content-block-project";
|
||||
import { createContentModeProject } from "../fixtures/content-mode-suite";
|
||||
import {
|
||||
getAssetIdByFilename,
|
||||
openAssetsPanel,
|
||||
uploadAsset,
|
||||
} from "../flows/assets-panel";
|
||||
import { openAssetsPanel, uploadAsset } from "../flows/assets-panel";
|
||||
import {
|
||||
openProjectBuilder,
|
||||
waitForCanvasFrame,
|
||||
@@ -25,15 +21,18 @@ import {
|
||||
selectContentBlock,
|
||||
confirmContentBlockConnection,
|
||||
} from "../flows/content-block-source";
|
||||
import { replaceCanvasText } from "../flows/content-editing";
|
||||
import { waitForContentEditMode } from "../flows/content-editing";
|
||||
import {
|
||||
replaceCanvasText,
|
||||
waitForContentEditMode,
|
||||
} from "../flows/content-editing";
|
||||
import {
|
||||
waitForChangeToBeSaved,
|
||||
waitForSyncComplete,
|
||||
waitForSyncStatus,
|
||||
} from "../flows/sync-status";
|
||||
import { insertTemplateAfterCanvasText } from "../flows/template-insertion";
|
||||
import { openNavigatorPanel } from "../flows/navigator";
|
||||
import { selectNavigatorItem } from "../flows/navigator";
|
||||
import { openPage } from "../flows/pages-panel";
|
||||
import { selectCanvasTextInstanceForProps } from "../flows/canvas-selection";
|
||||
import { fillSelectedStringProperty } from "../flows/props-panel";
|
||||
import { getProjectBuilderUrl, test } from "../test";
|
||||
@@ -43,7 +42,6 @@ test.describe.configure({ mode: "parallel" });
|
||||
|
||||
const sourceFilename = "content-source.mdx";
|
||||
const alternateFilename = "alternate-source.mdx";
|
||||
const unresolvedFilename = "unresolved-source.mdx";
|
||||
const namedTemplateFilename = "named-template-source.mdx";
|
||||
const emptyFilename = "empty-source.mdx";
|
||||
|
||||
@@ -145,6 +143,16 @@ const expandNavigatorItem = async ({
|
||||
await item.press("ArrowRight");
|
||||
};
|
||||
|
||||
const selectLifecycleTemplate = async (page: Page) => {
|
||||
await expandNavigatorItem({ page, name: "Content Block" });
|
||||
await expandNavigatorItem({ page, name: "Block Template" });
|
||||
const template = page.locator(
|
||||
`[data-navigator-instance-id="${lifecycleTemplateId}"]`
|
||||
);
|
||||
await template.click();
|
||||
await template.click();
|
||||
};
|
||||
|
||||
const insertTemplateIntoEmptyContentBlock = async ({
|
||||
page,
|
||||
templateName,
|
||||
@@ -173,11 +181,11 @@ const openFixture = async ({
|
||||
page: Page;
|
||||
projectId: string;
|
||||
authToken: string;
|
||||
mode?: "content" | "preview";
|
||||
mode?: "content";
|
||||
pageId?: string;
|
||||
}) => {
|
||||
await openProjectBuilder({ page, projectId, authToken, mode, pageId });
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
await waitForSyncComplete({ page });
|
||||
};
|
||||
|
||||
test("Content Block MDX source lifecycle persists edits and resets to empty", async ({
|
||||
@@ -208,7 +216,7 @@ test("Content Block MDX source lifecycle persists edits and resets to empty", as
|
||||
await chooseContentBlockSource({ page, filename: sourceFilename });
|
||||
await confirmContentBlockConnection({ page });
|
||||
await waitForCanvasText({ page, text: sourceHeading });
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
await waitForSyncComplete({ page });
|
||||
await openFixture({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
@@ -441,7 +449,7 @@ test("Content Block MDX source lifecycle persists edits and resets to empty", as
|
||||
}
|
||||
await page.keyboard.press("Escape");
|
||||
await disconnectContentBlockSource({ page });
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
await waitForSyncComplete({ page });
|
||||
await waitForCanvasTextHidden({ page, text: alternateHeading });
|
||||
|
||||
await openFixture({
|
||||
@@ -456,38 +464,28 @@ test("Content Block MDX source lifecycle persists edits and resets to empty", as
|
||||
.waitFor();
|
||||
});
|
||||
|
||||
test("Empty MDX content supports slash menu keyboard and mouse insertion", async ({
|
||||
test("Content editors switch MDX sources, edit isolated scopes, and recover from stale files", async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
const unexpectedDialogs: string[] = [];
|
||||
page.on("dialog", async (dialog) => {
|
||||
if (dialog.type() === "beforeunload") {
|
||||
await dialog.accept();
|
||||
return;
|
||||
}
|
||||
unexpectedDialogs.push(dialog.message());
|
||||
await dialog.dismiss();
|
||||
});
|
||||
const fixture = await createContentModeProject({
|
||||
context: context,
|
||||
context,
|
||||
devPlan: e2ePaidPlanName,
|
||||
email: "empty-mdx-content-source-e2e@webstudio.test",
|
||||
title: "Empty MDX Content Source E2E",
|
||||
email: "mdx-content-editor-e2e@webstudio.test",
|
||||
title: "MDX Content Editor E2E",
|
||||
});
|
||||
await configureEmptyHeadingTemplate(fixture.projectId);
|
||||
|
||||
await openFixture({
|
||||
page,
|
||||
const {
|
||||
homePageName,
|
||||
repeatedPageId,
|
||||
detailSourceAssetId,
|
||||
detailAlternateAssetId,
|
||||
} = await prepareMdxEditorPages({
|
||||
context,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
sourceFilename,
|
||||
alternateFilename,
|
||||
emptyFilename,
|
||||
});
|
||||
await openAssetsPanel({ page });
|
||||
await uploadAsset({ page, filename: emptyFilename });
|
||||
await selectContentBlock({ page });
|
||||
await chooseContentBlockSource({ page, filename: emptyFilename });
|
||||
await confirmContentBlockConnection({ page });
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
|
||||
await openFixture({
|
||||
page,
|
||||
@@ -495,328 +493,304 @@ test("Empty MDX content supports slash menu keyboard and mouse insertion", async
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
});
|
||||
const revisionPatches: string[] = [];
|
||||
page.on("request", (request) => {
|
||||
if (request.url().includes("/trpc/build.patch")) {
|
||||
const body = request.postData() ?? "";
|
||||
if (body.includes('"namespace":"assets"')) {
|
||||
revisionPatches.push(body);
|
||||
await test.step("The empty document supports single keyboard and mouse slash insertions", async () => {
|
||||
const unexpectedDialogs: string[] = [];
|
||||
const recordUnexpectedDialog = async (dialog: Dialog) => {
|
||||
if (dialog.type() === "beforeunload") {
|
||||
await dialog.accept();
|
||||
return;
|
||||
}
|
||||
unexpectedDialogs.push(dialog.message());
|
||||
await dialog.dismiss();
|
||||
};
|
||||
page.on("dialog", recordUnexpectedDialog);
|
||||
const revisionPatches: string[] = [];
|
||||
const recordRevisionPatch = (request: Request) => {
|
||||
if (request.url().includes("/trpc/build.patch")) {
|
||||
const body = request.postData() ?? "";
|
||||
if (body.includes('"namespace":"assets"')) {
|
||||
revisionPatches.push(body);
|
||||
}
|
||||
}
|
||||
};
|
||||
page.on("request", recordRevisionPatch);
|
||||
await insertTemplateIntoEmptyContentBlock({
|
||||
page,
|
||||
templateName: "Empty Heading Template",
|
||||
});
|
||||
const canvas = await waitForCanvasFrame({ page });
|
||||
await canvas.locator("h1").waitFor({ state: "visible" });
|
||||
const headingEditor = canvas.locator("h1[contenteditable]");
|
||||
await headingEditor.waitFor({ state: "visible" });
|
||||
await page.keyboard.type("First heading");
|
||||
await headingEditor.getByText("First heading", { exact: true }).waitFor();
|
||||
await page.keyboard.press("Enter");
|
||||
|
||||
const keyboardAnchorEditor = canvas.locator("p[contenteditable]").last();
|
||||
await keyboardAnchorEditor.waitFor({ state: "visible" });
|
||||
await page.keyboard.type("Keyboard anchor");
|
||||
await page.keyboard.type("/Empty");
|
||||
const keyboardTemplateItem = page
|
||||
.getByRole("menuitemradio", { name: "Empty Heading Template" })
|
||||
.last();
|
||||
await keyboardTemplateItem.waitFor({ state: "visible" });
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await page.keyboard.press("Enter");
|
||||
await keyboardTemplateItem.waitFor({ state: "detached" });
|
||||
await canvas.locator("h1").nth(1).waitFor({ state: "visible" });
|
||||
await page.waitForTimeout(100);
|
||||
const headingCount = await canvas.locator("h1").count();
|
||||
if (headingCount !== 2) {
|
||||
throw new Error(
|
||||
`Expected one keyboard insertion, found ${headingCount - 1}`
|
||||
);
|
||||
}
|
||||
const keyboardHeadingEditor = canvas.locator("h1[contenteditable]").last();
|
||||
await page.keyboard.type("Keyboard heading");
|
||||
await keyboardHeadingEditor
|
||||
.getByText("Keyboard heading", { exact: true })
|
||||
.waitFor();
|
||||
await page.keyboard.press("Enter");
|
||||
|
||||
const emptyParagraphEditor = canvas.locator("p[contenteditable]").last();
|
||||
await emptyParagraphEditor.waitFor({ state: "visible" });
|
||||
const replacedParagraphId =
|
||||
await emptyParagraphEditor.getAttribute("data-ws-id");
|
||||
if (replacedParagraphId === null) {
|
||||
throw new Error("Expected the paragraph instance being replaced");
|
||||
}
|
||||
await page.keyboard.press("/");
|
||||
const templateItem = page
|
||||
.getByRole("menuitemradio", {
|
||||
name: fixture.editableTextTemplateName,
|
||||
})
|
||||
.last();
|
||||
await templateItem.waitFor({ state: "visible" });
|
||||
await templateItem.click();
|
||||
await canvas
|
||||
.locator(`[data-ws-id="${replacedParagraphId}"]`)
|
||||
.waitFor({ state: "detached" });
|
||||
await waitForCanvasText({ page, text: fixture.editableTextTemplateText });
|
||||
if (
|
||||
(await canvas
|
||||
.getByText(fixture.editableTextTemplateText, { exact: true })
|
||||
.count()) !== 1
|
||||
) {
|
||||
throw new Error("Expected one live slash menu insertion on the canvas");
|
||||
}
|
||||
const paragraphEditor = canvas
|
||||
.locator("p[contenteditable]")
|
||||
.filter({ hasText: fixture.editableTextTemplateText });
|
||||
await paragraphEditor.waitFor({ state: "visible" });
|
||||
const paragraphId = await paragraphEditor.getAttribute("data-ws-id");
|
||||
if (paragraphId === null) {
|
||||
throw new Error("Expected the focused paragraph instance id");
|
||||
}
|
||||
const paragraphWrite = waitForAssetWrite(page, (source) =>
|
||||
source.includes("Focused paragraph")
|
||||
);
|
||||
await page.keyboard.press("ControlOrMeta+A");
|
||||
await page.keyboard.type("Focused paragraph");
|
||||
await page.keyboard.press("Enter");
|
||||
const nextEmptyParagraphEditor = canvas.locator(
|
||||
`p[contenteditable]:not([data-ws-id="${paragraphId}"])`
|
||||
);
|
||||
await nextEmptyParagraphEditor.waitFor({ state: "visible" });
|
||||
await paragraphWrite;
|
||||
const emptyParagraphId =
|
||||
await nextEmptyParagraphEditor.getAttribute("data-ws-id");
|
||||
if (emptyParagraphId === null) {
|
||||
throw new Error("Expected the new paragraph instance id");
|
||||
}
|
||||
const finalWrite = waitForAssetWrite(
|
||||
page,
|
||||
(source) =>
|
||||
source.includes("# First heading") &&
|
||||
source.includes("Keyboard anchor") &&
|
||||
source.includes("# Keyboard heading") &&
|
||||
source.includes("Focused paragraph") &&
|
||||
source.includes('ws:tag="p"') === false
|
||||
);
|
||||
await page.keyboard.press("ControlOrMeta+A");
|
||||
await page.keyboard.press("Backspace");
|
||||
await page.keyboard.press("Backspace");
|
||||
await canvas
|
||||
.locator(`p[data-ws-id="${emptyParagraphId}"]`)
|
||||
.waitFor({ state: "detached" });
|
||||
if (
|
||||
(await canvas
|
||||
.locator(`p[data-ws-id="${paragraphId}"]`)
|
||||
.evaluate(
|
||||
(element) =>
|
||||
element === document.activeElement ||
|
||||
element.contains(document.activeElement)
|
||||
)) === false
|
||||
) {
|
||||
throw new Error("Expected the previous paragraph to regain focus");
|
||||
}
|
||||
await canvas.locator("body").click({ position: { x: 1, y: 1 } });
|
||||
const finalSource = (await finalWrite).request().postData() ?? "";
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
page.off("request", recordRevisionPatch);
|
||||
if (revisionPatches.length > 0) {
|
||||
throw new Error(
|
||||
"Saved MDX revisions must not be persisted again by build.patch"
|
||||
);
|
||||
}
|
||||
const expectedContentOrder = [
|
||||
"# First heading",
|
||||
"Keyboard anchor",
|
||||
"# Keyboard heading",
|
||||
"Focused paragraph",
|
||||
];
|
||||
let previousIndex = -1;
|
||||
for (const content of expectedContentOrder) {
|
||||
const index = finalSource.indexOf(content);
|
||||
if (
|
||||
index <= previousIndex ||
|
||||
finalSource.indexOf(content, index + 1) !== -1
|
||||
) {
|
||||
throw new Error(`Unexpected final MDX source: ${finalSource}`);
|
||||
}
|
||||
previousIndex = index;
|
||||
}
|
||||
if (finalSource.includes("/Empty") || finalSource.includes('ws:tag="p"')) {
|
||||
throw new Error(`Unexpected final MDX source: ${finalSource}`);
|
||||
}
|
||||
|
||||
page.off("dialog", recordUnexpectedDialog);
|
||||
if (unexpectedDialogs.length > 0) {
|
||||
throw new Error(
|
||||
`Normal Content Block edits opened dialogs: ${unexpectedDialogs.join(", ")}`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
await test.step("Editing a repeated Content Block only changes its source file", async () => {
|
||||
await openFixture({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
pageId: repeatedPageId,
|
||||
});
|
||||
await waitForCanvasText({ page, text: sourceHeading });
|
||||
await waitForCanvasText({ page, text: alternateHeading });
|
||||
|
||||
const write = waitForAssetWrite(page);
|
||||
await replaceCanvasText({
|
||||
page,
|
||||
currentText: sourceHeading,
|
||||
text: editedHeading,
|
||||
waitForProjectSync: false,
|
||||
});
|
||||
await write;
|
||||
await waitForCanvasText({ page, text: editedHeading });
|
||||
await waitForCanvasText({ page, text: alternateHeading });
|
||||
});
|
||||
|
||||
await test.step("A stale write pauses sync until reload and leaves the saved source intact", async () => {
|
||||
await page.route("**/rest/assets/*/content?*", async (route) => {
|
||||
if (route.request().method() === "PUT") {
|
||||
await route.fulfill({
|
||||
status: 409,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({ message: "Asset revision conflict" }),
|
||||
});
|
||||
return;
|
||||
}
|
||||
await route.continue();
|
||||
});
|
||||
|
||||
const reloadPrompt = page.waitForEvent("dialog").then(async (dialog) => {
|
||||
const message = dialog.message();
|
||||
await dialog.dismiss();
|
||||
return message;
|
||||
});
|
||||
await replaceCanvasText({
|
||||
page,
|
||||
currentText: editedHeading,
|
||||
text: "Unsaved conflict heading",
|
||||
waitForProjectSync: false,
|
||||
});
|
||||
const reloadPromptMessage = await reloadPrompt;
|
||||
if (
|
||||
reloadPromptMessage !==
|
||||
"This file changed since it was opened. Reload it before saving again."
|
||||
) {
|
||||
throw new Error(
|
||||
`Expected stale revision reload prompt: ${reloadPromptMessage}`
|
||||
);
|
||||
}
|
||||
await page
|
||||
.getByRole("status")
|
||||
.filter({
|
||||
hasText: "Synchronization has been paused. Please reload to continue.",
|
||||
})
|
||||
.first()
|
||||
.waitFor();
|
||||
|
||||
await page.unroute("**/rest/assets/*/content?*");
|
||||
await page.reload();
|
||||
await waitForCanvasText({ page, text: editedHeading });
|
||||
await waitForCanvasText({ page, text: alternateHeading });
|
||||
await waitForCanvasTextHidden({ page, text: "Unsaved conflict heading" });
|
||||
await waitForSyncComplete({ page });
|
||||
});
|
||||
|
||||
await test.step("All slash inserts are present once after the same reload", async () => {
|
||||
await openPage({
|
||||
page,
|
||||
pageName: homePageName,
|
||||
canvasText: "First heading",
|
||||
});
|
||||
await waitForCanvasText({ page, text: "Keyboard anchor" });
|
||||
await waitForCanvasText({ page, text: "Keyboard heading" });
|
||||
await waitForCanvasText({ page, text: "Focused paragraph" });
|
||||
const reloadedCanvas = await waitForCanvasFrame({ page });
|
||||
for (const text of [
|
||||
"First heading",
|
||||
"Keyboard anchor",
|
||||
"Keyboard heading",
|
||||
"Focused paragraph",
|
||||
]) {
|
||||
if (
|
||||
(await reloadedCanvas.getByText(text, { exact: true }).count()) !== 1
|
||||
) {
|
||||
throw new Error(`Expected one ${text} block after reload`);
|
||||
}
|
||||
}
|
||||
});
|
||||
await insertTemplateIntoEmptyContentBlock({
|
||||
page,
|
||||
templateName: "Empty Heading Template",
|
||||
});
|
||||
const canvas = await waitForCanvasFrame({ page });
|
||||
await canvas.locator("h1").waitFor({ state: "visible" });
|
||||
const headingEditor = canvas.locator("h1[contenteditable]");
|
||||
await headingEditor.waitFor({ state: "visible" });
|
||||
await page.keyboard.type("First heading");
|
||||
await headingEditor.getByText("First heading", { exact: true }).waitFor();
|
||||
await page.keyboard.press("Enter");
|
||||
|
||||
const keyboardAnchorEditor = canvas.locator("p[contenteditable]").last();
|
||||
await keyboardAnchorEditor.waitFor({ state: "visible" });
|
||||
await page.keyboard.type("Keyboard anchor");
|
||||
await page.keyboard.type("/Empty");
|
||||
const keyboardTemplateItem = page
|
||||
.getByRole("menuitemradio", { name: "Empty Heading Template" })
|
||||
.last();
|
||||
await keyboardTemplateItem.waitFor({ state: "visible" });
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await page.keyboard.press("Enter");
|
||||
await keyboardTemplateItem.waitFor({ state: "detached" });
|
||||
await canvas.locator("h1").nth(1).waitFor({ state: "visible" });
|
||||
await page.waitForTimeout(100);
|
||||
const headingCount = await canvas.locator("h1").count();
|
||||
if (headingCount !== 2) {
|
||||
throw new Error(
|
||||
`Expected one keyboard insertion, found ${headingCount - 1}`
|
||||
);
|
||||
}
|
||||
const keyboardHeadingEditor = canvas.locator("h1[contenteditable]").last();
|
||||
await page.keyboard.type("Keyboard heading");
|
||||
await keyboardHeadingEditor
|
||||
.getByText("Keyboard heading", { exact: true })
|
||||
.waitFor();
|
||||
await page.keyboard.press("Enter");
|
||||
|
||||
const emptyParagraphEditor = canvas.locator("p[contenteditable]").last();
|
||||
await emptyParagraphEditor.waitFor({ state: "visible" });
|
||||
const replacedParagraphId =
|
||||
await emptyParagraphEditor.getAttribute("data-ws-id");
|
||||
if (replacedParagraphId === null) {
|
||||
throw new Error("Expected the paragraph instance being replaced");
|
||||
}
|
||||
await page.keyboard.press("/");
|
||||
const templateItem = page
|
||||
.getByRole("menuitemradio", {
|
||||
name: fixture.editableTextTemplateName,
|
||||
})
|
||||
.last();
|
||||
await templateItem.waitFor({ state: "visible" });
|
||||
await templateItem.click();
|
||||
await canvas
|
||||
.locator(`[data-ws-id="${replacedParagraphId}"]`)
|
||||
.waitFor({ state: "detached" });
|
||||
await waitForCanvasText({ page, text: fixture.editableTextTemplateText });
|
||||
if (
|
||||
(await canvas
|
||||
.getByText(fixture.editableTextTemplateText, { exact: true })
|
||||
.count()) !== 1
|
||||
) {
|
||||
throw new Error("Expected one live slash menu insertion on the canvas");
|
||||
}
|
||||
const paragraphEditor = canvas
|
||||
.locator("p[contenteditable]")
|
||||
.filter({ hasText: fixture.editableTextTemplateText });
|
||||
await paragraphEditor.waitFor({ state: "visible" });
|
||||
const paragraphId = await paragraphEditor.getAttribute("data-ws-id");
|
||||
if (paragraphId === null) {
|
||||
throw new Error("Expected the focused paragraph instance id");
|
||||
}
|
||||
const paragraphWrite = waitForAssetWrite(page, (source) =>
|
||||
source.includes("Focused paragraph")
|
||||
);
|
||||
await page.keyboard.press("ControlOrMeta+A");
|
||||
await page.keyboard.type("Focused paragraph");
|
||||
await page.keyboard.press("Enter");
|
||||
const nextEmptyParagraphEditor = canvas.locator(
|
||||
`p[contenteditable]:not([data-ws-id="${paragraphId}"])`
|
||||
);
|
||||
await nextEmptyParagraphEditor.waitFor({ state: "visible" });
|
||||
await paragraphWrite;
|
||||
const emptyParagraphId =
|
||||
await nextEmptyParagraphEditor.getAttribute("data-ws-id");
|
||||
if (emptyParagraphId === null) {
|
||||
throw new Error("Expected the new paragraph instance id");
|
||||
}
|
||||
const finalWrite = waitForAssetWrite(
|
||||
page,
|
||||
(source) =>
|
||||
source.includes("# First heading") &&
|
||||
source.includes("Keyboard anchor") &&
|
||||
source.includes("# Keyboard heading") &&
|
||||
source.includes("Focused paragraph") &&
|
||||
source.includes('ws:tag="p"') === false
|
||||
);
|
||||
await page.keyboard.press("ControlOrMeta+A");
|
||||
await page.keyboard.press("Backspace");
|
||||
await page.keyboard.press("Backspace");
|
||||
await canvas
|
||||
.locator(`p[data-ws-id="${emptyParagraphId}"]`)
|
||||
.waitFor({ state: "detached" });
|
||||
if (
|
||||
(await canvas
|
||||
.locator(`p[data-ws-id="${paragraphId}"]`)
|
||||
.evaluate(
|
||||
(element) =>
|
||||
element === document.activeElement ||
|
||||
element.contains(document.activeElement)
|
||||
)) === false
|
||||
) {
|
||||
throw new Error("Expected the previous paragraph to regain focus");
|
||||
}
|
||||
await page.mouse.click(5, 5);
|
||||
const finalSource = (await finalWrite).request().postData() ?? "";
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
if (revisionPatches.length > 0) {
|
||||
throw new Error(
|
||||
"Saved MDX revisions must not be persisted again by build.patch"
|
||||
);
|
||||
}
|
||||
const expectedContentOrder = [
|
||||
"# First heading",
|
||||
"Keyboard anchor",
|
||||
"# Keyboard heading",
|
||||
"Focused paragraph",
|
||||
];
|
||||
let previousIndex = -1;
|
||||
for (const content of expectedContentOrder) {
|
||||
const index = finalSource.indexOf(content);
|
||||
if (
|
||||
index <= previousIndex ||
|
||||
finalSource.indexOf(content, index + 1) !== -1
|
||||
) {
|
||||
throw new Error(`Unexpected final MDX source: ${finalSource}`);
|
||||
}
|
||||
previousIndex = index;
|
||||
}
|
||||
if (finalSource.includes("/Empty") || finalSource.includes('ws:tag="p"')) {
|
||||
throw new Error(`Unexpected final MDX source: ${finalSource}`);
|
||||
}
|
||||
|
||||
await openFixture({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
});
|
||||
await waitForCanvasText({ page, text: "First heading" });
|
||||
await waitForCanvasText({ page, text: "Keyboard anchor" });
|
||||
await waitForCanvasText({ page, text: "Keyboard heading" });
|
||||
await waitForCanvasText({ page, text: "Focused paragraph" });
|
||||
const reloadedCanvas = await waitForCanvasFrame({ page });
|
||||
for (const text of [
|
||||
"First heading",
|
||||
"Keyboard anchor",
|
||||
"Keyboard heading",
|
||||
"Focused paragraph",
|
||||
]) {
|
||||
if ((await reloadedCanvas.getByText(text, { exact: true }).count()) !== 1) {
|
||||
throw new Error(`Expected one ${text} block after reload`);
|
||||
}
|
||||
}
|
||||
if (unexpectedDialogs.length > 0) {
|
||||
throw new Error(
|
||||
`Normal Content Block edits opened dialogs: ${unexpectedDialogs.join(", ")}`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("Content Block requires a Builder reload after a stale file revision", async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
const fixture = await createContentModeProject({
|
||||
context: context,
|
||||
devPlan: e2ePaidPlanName,
|
||||
email: "mdx-content-conflict-e2e@webstudio.test",
|
||||
title: "MDX Content Conflict E2E",
|
||||
});
|
||||
|
||||
await openFixture({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
await openAssetsPanel({ page });
|
||||
await uploadAsset({ page, filename: sourceFilename });
|
||||
await selectContentBlock({ page });
|
||||
await chooseContentBlockSource({ page, filename: sourceFilename });
|
||||
await confirmContentBlockConnection({ page });
|
||||
await waitForCanvasText({ page, text: sourceHeading });
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
await openFixture({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
});
|
||||
|
||||
await page.route("**/rest/assets/*/content?*", async (route) => {
|
||||
if (route.request().method() === "PUT") {
|
||||
await route.fulfill({
|
||||
status: 409,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({ message: "Asset revision conflict" }),
|
||||
});
|
||||
return;
|
||||
}
|
||||
await route.continue();
|
||||
});
|
||||
|
||||
let reloadPromptMessage: string | undefined;
|
||||
const reloadPromptHandled = new Promise<void>((resolve) => {
|
||||
page.once("dialog", (dialog) => {
|
||||
reloadPromptMessage = dialog.message();
|
||||
void dialog.dismiss().then(resolve);
|
||||
// Using the dynamic page address can pause project sync for editor links
|
||||
// when saving recent addresses. Check it after the persisted content flows.
|
||||
await test.step("The dynamic detail page follows its selected route parameter", async () => {
|
||||
await openPage({
|
||||
page,
|
||||
pageName: mdxEditorPageNames.detail,
|
||||
canvasText: sourceHeading,
|
||||
});
|
||||
});
|
||||
await replaceCanvasText({
|
||||
page,
|
||||
currentText: sourceHeading,
|
||||
text: "Unsaved conflict heading",
|
||||
waitForProjectSync: false,
|
||||
});
|
||||
await reloadPromptHandled;
|
||||
if (
|
||||
reloadPromptMessage !==
|
||||
"This file changed since it was opened. Reload it before saving again."
|
||||
) {
|
||||
throw new Error(
|
||||
`Expected stale revision reload prompt: ${reloadPromptMessage}`
|
||||
);
|
||||
}
|
||||
await page
|
||||
.getByRole("status")
|
||||
.filter({
|
||||
hasText: "Synchronization has been paused. Please reload to continue.",
|
||||
})
|
||||
.first()
|
||||
.waitFor();
|
||||
|
||||
await page.unroute("**/rest/assets/*/content?*");
|
||||
await openFixture({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
await page
|
||||
.getByRole("button", { name: "Toggle dynamic page address" })
|
||||
.click();
|
||||
const parameter = page.getByPlaceholder("assetid");
|
||||
await parameter.fill(detailAlternateAssetId);
|
||||
await parameter.press("Enter");
|
||||
await waitForCanvasText({ page, text: alternateHeading });
|
||||
await waitForCanvasTextHidden({ page, text: sourceHeading });
|
||||
|
||||
await page
|
||||
.getByRole("button", { name: "Toggle dynamic page address" })
|
||||
.click();
|
||||
await page.getByPlaceholder("assetid").fill(detailSourceAssetId);
|
||||
await page.getByPlaceholder("assetid").press("Enter");
|
||||
await waitForCanvasText({ page, text: sourceHeading });
|
||||
await waitForCanvasTextHidden({ page, text: alternateHeading });
|
||||
});
|
||||
await waitForCanvasText({ page, text: sourceHeading });
|
||||
});
|
||||
|
||||
test("Unresolved MDX templates are selectable only in the Builder canvas", async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
const fixture = await createContentModeProject({
|
||||
context: context,
|
||||
email: "mdx-content-warning-e2e@webstudio.test",
|
||||
title: "MDX Content Warning E2E",
|
||||
});
|
||||
|
||||
await openFixture({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
await openAssetsPanel({ page });
|
||||
await uploadAsset({ page, filename: unresolvedFilename });
|
||||
await selectContentBlock({ page });
|
||||
await chooseContentBlockSource({ page, filename: unresolvedFilename });
|
||||
await confirmContentBlockConnection({ page });
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
|
||||
await waitForCanvasText({ page, text: "Valid MDX sibling" });
|
||||
await waitForCanvasText({
|
||||
page,
|
||||
text: "Valid content after the missing template.",
|
||||
});
|
||||
const canvas = await waitForCanvasFrame({ page });
|
||||
const warning = canvas.getByText("Missing template: MissingE2ETemplate", {
|
||||
exact: true,
|
||||
});
|
||||
await warning.waitFor();
|
||||
await warning.click();
|
||||
await selectContentBlock({ page });
|
||||
await page.getByRole("img", { name: /^MDX source warning:/ }).waitFor();
|
||||
const openButton = page.getByRole("button", { name: "Open", exact: true });
|
||||
await openButton.click();
|
||||
await page
|
||||
.locator(".cm-lintRange-error")
|
||||
.filter({ hasText: "MissingE2ETemplate" })
|
||||
.waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
const previewUrl = getProjectBuilderUrl({
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "preview",
|
||||
});
|
||||
await page.goto(previewUrl);
|
||||
await waitForCanvasText({ page, text: "Valid MDX sibling" });
|
||||
await waitForCanvasText({
|
||||
page,
|
||||
text: "Valid content after the missing template.",
|
||||
});
|
||||
const previewCanvas = await waitForCanvasFrame({ page });
|
||||
await previewCanvas
|
||||
.getByText("Missing template: MissingE2ETemplate", { exact: true })
|
||||
.waitFor({ state: "hidden" });
|
||||
});
|
||||
|
||||
test("Named MDX templates re-resolve after rename, reload, and removal", async ({
|
||||
test("MDX template warnings and renamed templates resolve in the right modes", async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
@@ -840,9 +814,28 @@ test("Named MDX templates re-resolve after rename, reload, and removal", async (
|
||||
await waitForCanvasText({ page, text: "Authored lifecycle card" });
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
|
||||
await expandNavigatorItem({ page, name: "Content Block" });
|
||||
await expandNavigatorItem({ page, name: "Block Template" });
|
||||
await selectNavigatorItem({ page, name: "Lifecycle Card" });
|
||||
await waitForCanvasText({ page, text: "Valid MDX sibling" });
|
||||
await waitForCanvasText({
|
||||
page,
|
||||
text: "Valid content after the missing template.",
|
||||
});
|
||||
const canvas = await waitForCanvasFrame({ page });
|
||||
const warning = canvas.getByText("Missing template: MissingE2ETemplate", {
|
||||
exact: true,
|
||||
});
|
||||
await warning.waitFor();
|
||||
await warning.click();
|
||||
await selectContentBlock({ page });
|
||||
await page.getByRole("img", { name: /^MDX source warning:/ }).waitFor();
|
||||
const openButton = page.getByRole("button", { name: "Open", exact: true });
|
||||
await openButton.click();
|
||||
await page
|
||||
.locator(".cm-lintRange-error")
|
||||
.filter({ hasText: "MissingE2ETemplate" })
|
||||
.waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
await selectLifecycleTemplate(page);
|
||||
await page.getByRole("tab", { name: "Settings" }).click();
|
||||
const nameInput = page.getByLabel("Name", { exact: true });
|
||||
await nameInput.fill("RenamedLifecycleCard");
|
||||
@@ -860,9 +853,7 @@ test("Named MDX templates re-resolve after rename, reload, and removal", async (
|
||||
});
|
||||
await waitForCanvasText({ page, text: "Missing template: LifecycleCard" });
|
||||
|
||||
await expandNavigatorItem({ page, name: "Content Block" });
|
||||
await expandNavigatorItem({ page, name: "Block Template" });
|
||||
await selectNavigatorItem({ page, name: "Lifecycle Card" });
|
||||
await selectLifecycleTemplate(page);
|
||||
await page.getByRole("tab", { name: "Settings" }).click();
|
||||
await page.getByLabel("Name", { exact: true }).fill("LifecycleCard");
|
||||
await page.getByLabel("Name", { exact: true }).press("Tab");
|
||||
@@ -872,9 +863,7 @@ test("Named MDX templates re-resolve after rename, reload, and removal", async (
|
||||
await selectContentBlock({ page });
|
||||
await waitForCanvasText({ page, text: "Authored lifecycle card" });
|
||||
|
||||
await expandNavigatorItem({ page, name: "Content Block" });
|
||||
await expandNavigatorItem({ page, name: "Block Template" });
|
||||
await selectNavigatorItem({ page, name: "Lifecycle Card" });
|
||||
await selectLifecycleTemplate(page);
|
||||
await page.keyboard.press("Delete");
|
||||
const deleteSaved = waitForChangeToBeSaved({ page });
|
||||
await page.getByRole("button", { name: "Delete", exact: true }).click();
|
||||
@@ -889,6 +878,14 @@ test("Named MDX templates re-resolve after rename, reload, and removal", async (
|
||||
});
|
||||
await page.goto(previewUrl);
|
||||
const previewCanvas = await waitForCanvasFrame({ page });
|
||||
await waitForCanvasText({ page, text: "Valid MDX sibling" });
|
||||
await waitForCanvasText({
|
||||
page,
|
||||
text: "Valid content after the missing template.",
|
||||
});
|
||||
await previewCanvas
|
||||
.getByText("Missing template: MissingE2ETemplate", { exact: true })
|
||||
.waitFor({ state: "hidden" });
|
||||
await previewCanvas
|
||||
.getByText("Missing template: LifecycleCard", { exact: true })
|
||||
.waitFor({ state: "hidden" });
|
||||
@@ -896,124 +893,3 @@ test("Named MDX templates re-resolve after rename, reload, and removal", async (
|
||||
.getByText("Authored lifecycle card", { exact: true })
|
||||
.waitFor({ state: "hidden" });
|
||||
});
|
||||
|
||||
test("Dynamic detail source follows the selected route parameter", async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
const fixture = await createContentModeProject({
|
||||
context: context,
|
||||
devPlan: e2ePaidPlanName,
|
||||
email: "mdx-content-detail-e2e@webstudio.test",
|
||||
title: "MDX Content Detail E2E",
|
||||
});
|
||||
|
||||
await openFixture({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
await openAssetsPanel({ page });
|
||||
await uploadAsset({ page, filename: sourceFilename });
|
||||
await uploadAsset({ page, filename: alternateFilename });
|
||||
const sourceAssetId = await getAssetIdByFilename({
|
||||
page,
|
||||
filename: sourceFilename,
|
||||
});
|
||||
const alternateAssetId = await getAssetIdByFilename({
|
||||
page,
|
||||
filename: alternateFilename,
|
||||
});
|
||||
const detailPageId = await configureDynamicDetailContentBlock({
|
||||
projectId: fixture.projectId,
|
||||
initialAssetId: sourceAssetId,
|
||||
});
|
||||
|
||||
await openFixture({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
pageId: detailPageId,
|
||||
mode: "content",
|
||||
});
|
||||
await waitForCanvasText({ page, text: sourceHeading });
|
||||
|
||||
await page
|
||||
.getByRole("button", { name: "Toggle dynamic page address" })
|
||||
.click();
|
||||
const parameter = page.getByPlaceholder("assetid");
|
||||
await parameter.fill(alternateAssetId);
|
||||
await parameter.press("Enter");
|
||||
await waitForCanvasText({ page, text: alternateHeading });
|
||||
await waitForCanvasTextHidden({ page, text: sourceHeading });
|
||||
|
||||
await page
|
||||
.getByRole("button", { name: "Toggle dynamic page address" })
|
||||
.click();
|
||||
await page.getByPlaceholder("assetid").fill(sourceAssetId);
|
||||
await page.getByPlaceholder("assetid").press("Enter");
|
||||
await waitForCanvasText({ page, text: sourceHeading });
|
||||
await waitForCanvasTextHidden({ page, text: alternateHeading });
|
||||
});
|
||||
|
||||
test("Repeated Content Block scopes edit distinct MDX files without leakage", async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
const fixture = await createContentModeProject({
|
||||
context: context,
|
||||
devPlan: e2ePaidPlanName,
|
||||
email: "mdx-content-repeated-e2e@webstudio.test",
|
||||
title: "MDX Content Repeated E2E",
|
||||
});
|
||||
|
||||
await openFixture({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
await openAssetsPanel({ page });
|
||||
await uploadAsset({ page, filename: sourceFilename });
|
||||
await uploadAsset({ page, filename: alternateFilename });
|
||||
const sourceAssetId = await getAssetIdByFilename({
|
||||
page,
|
||||
filename: sourceFilename,
|
||||
});
|
||||
const alternateAssetId = await getAssetIdByFilename({
|
||||
page,
|
||||
filename: alternateFilename,
|
||||
});
|
||||
await configureRepeatedContentBlock({
|
||||
projectId: fixture.projectId,
|
||||
assetIds: [sourceAssetId, alternateAssetId],
|
||||
});
|
||||
|
||||
await openFixture({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
});
|
||||
await waitForCanvasText({ page, text: sourceHeading });
|
||||
await waitForCanvasText({ page, text: alternateHeading });
|
||||
|
||||
const write = waitForAssetWrite(page);
|
||||
await replaceCanvasText({
|
||||
page,
|
||||
currentText: sourceHeading,
|
||||
text: editedHeading,
|
||||
waitForProjectSync: false,
|
||||
});
|
||||
await write;
|
||||
await waitForCanvasText({ page, text: editedHeading });
|
||||
await waitForCanvasText({ page, text: alternateHeading });
|
||||
|
||||
await openFixture({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.editorToken,
|
||||
mode: "content",
|
||||
});
|
||||
await waitForCanvasText({ page, text: editedHeading });
|
||||
await waitForCanvasText({ page, text: alternateHeading });
|
||||
});
|
||||
@@ -252,52 +252,11 @@ test("Builder can insert through the engine bridge, undo, redo, and reload", asy
|
||||
});
|
||||
});
|
||||
|
||||
test("Builder Components panel filters catalog-only entries and inserts a persisted component", async ({
|
||||
page,
|
||||
}) => {
|
||||
const insertedButtonText = "Button";
|
||||
|
||||
await measure("pages actions open builder for components panel", async () => {
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
});
|
||||
await waitForCanvasText({ page, text: "Initial content" });
|
||||
|
||||
await measure(
|
||||
"pages actions verify components panel catalog filters",
|
||||
async () => {
|
||||
await openComponentsPanel({ page });
|
||||
await expectComponentPanelOptionHidden({ page, name: "Body" });
|
||||
}
|
||||
);
|
||||
|
||||
await selectCanvasTextInstance({ page, text: "Initial content" });
|
||||
await measure(
|
||||
"pages actions insert component from components panel",
|
||||
async () => {
|
||||
await openComponentsPanel({ page });
|
||||
await insertComponentPanelOption({ page, name: "Button" });
|
||||
}
|
||||
);
|
||||
await waitForCanvasText({ page, text: insertedButtonText });
|
||||
|
||||
await measure("pages actions reload components panel insert", async () => {
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
});
|
||||
await waitForCanvasText({ page, text: insertedButtonText });
|
||||
});
|
||||
|
||||
test("Builder can duplicate a component through the engine bridge, undo, redo, and reload", async ({
|
||||
test("Builder filters the catalog and persists component actions from shortcuts and Navigator", async ({
|
||||
page,
|
||||
}) => {
|
||||
const componentName = "Image";
|
||||
const insertedButtonText = "Button";
|
||||
|
||||
await measure("pages actions open builder for command panel", async () => {
|
||||
await openProjectBuilder({
|
||||
@@ -309,6 +268,14 @@ test("Builder can duplicate a component through the engine bridge, undo, redo, a
|
||||
await waitForCanvasText({ page, text: "Initial content" });
|
||||
await selectCanvasTextInstance({ page, text: "Initial content" });
|
||||
|
||||
await test.step("filter the components catalog and insert a Button", async () => {
|
||||
await openComponentsPanel({ page });
|
||||
await expectComponentPanelOptionHidden({ page, name: "Body" });
|
||||
await insertComponentPanelOption({ page, name: "Button" });
|
||||
await waitForCanvasText({ page, text: insertedButtonText });
|
||||
});
|
||||
await selectCanvasTextInstance({ page, text: "Initial content" });
|
||||
|
||||
const initialCount = await getInstanceComponentCount({
|
||||
fixture,
|
||||
component: componentName,
|
||||
@@ -373,64 +340,6 @@ test("Builder can duplicate a component through the engine bridge, undo, redo, a
|
||||
);
|
||||
}
|
||||
|
||||
await measure("pages actions reload duplicate command", async () => {
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
});
|
||||
const reloadedCount = await getInstanceComponentCount({
|
||||
fixture,
|
||||
component: componentName,
|
||||
});
|
||||
if (reloadedCount !== initialCount + 2) {
|
||||
throw new Error(
|
||||
`Expected reloaded project to keep duplicated ${componentName}. Before ${initialCount}, after ${reloadedCount}`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("Builder can duplicate and delete a component from Navigator context menu", async ({
|
||||
page,
|
||||
}) => {
|
||||
const componentName = "Image";
|
||||
|
||||
await measure(
|
||||
"pages actions open builder for navigator context menu",
|
||||
async () => {
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
}
|
||||
);
|
||||
await waitForCanvasText({ page, text: "Initial content" });
|
||||
await selectCanvasTextInstance({ page, text: "Initial content" });
|
||||
|
||||
const initialCount = await getInstanceComponentCount({
|
||||
fixture,
|
||||
component: componentName,
|
||||
});
|
||||
|
||||
await measure(
|
||||
"pages actions insert component before navigator actions",
|
||||
async () => {
|
||||
await openComponentsPanel({ page });
|
||||
await insertComponentPanelOption({ page, name: componentName });
|
||||
}
|
||||
);
|
||||
const insertedCount = await getInstanceComponentCount({
|
||||
fixture,
|
||||
component: componentName,
|
||||
});
|
||||
if (insertedCount !== initialCount + 1) {
|
||||
throw new Error(
|
||||
`Expected components panel to insert one ${componentName}. Before ${initialCount}, after ${insertedCount}. Components: ${await getInstanceComponentCountSummary(fixture)}`
|
||||
);
|
||||
}
|
||||
|
||||
await measure(
|
||||
"pages actions duplicate component from navigator",
|
||||
async () => {
|
||||
@@ -442,13 +351,13 @@ test("Builder can duplicate and delete a component from Navigator context menu",
|
||||
});
|
||||
}
|
||||
);
|
||||
const duplicatedCount = await getInstanceComponentCount({
|
||||
const navigatorDuplicateCount = await getInstanceComponentCount({
|
||||
fixture,
|
||||
component: componentName,
|
||||
});
|
||||
if (duplicatedCount !== initialCount + 2) {
|
||||
if (navigatorDuplicateCount !== redoCount + 1) {
|
||||
throw new Error(
|
||||
`Expected Navigator duplicate to add one ${componentName}. Before ${initialCount}, after ${duplicatedCount}. Components: ${await getInstanceComponentCountSummary(fixture)}. Navigator: ${JSON.stringify(await getNavigatorButtonSummary({ page, text: componentName }))}`
|
||||
`Expected Navigator duplicate to add one ${componentName}. Before ${redoCount}, after ${navigatorDuplicateCount}. Components: ${await getInstanceComponentCountSummary(fixture)}. Navigator: ${JSON.stringify(await getNavigatorButtonSummary({ page, text: componentName }))}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -459,9 +368,9 @@ test("Builder can duplicate and delete a component from Navigator context menu",
|
||||
fixture,
|
||||
component: componentName,
|
||||
});
|
||||
if (undoDuplicateCount !== initialCount + 1) {
|
||||
if (undoDuplicateCount !== redoCount) {
|
||||
throw new Error(
|
||||
`Expected undo to remove Navigator duplicate ${componentName}. Before ${initialCount}, after ${undoDuplicateCount}`
|
||||
`Expected undo to remove Navigator duplicate ${componentName}. Before ${redoCount}, after ${undoDuplicateCount}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -472,9 +381,9 @@ test("Builder can duplicate and delete a component from Navigator context menu",
|
||||
fixture,
|
||||
component: componentName,
|
||||
});
|
||||
if (redoDuplicateCount !== initialCount + 2) {
|
||||
if (redoDuplicateCount !== redoCount + 1) {
|
||||
throw new Error(
|
||||
`Expected redo to restore Navigator duplicate ${componentName}. Before ${initialCount}, after ${redoDuplicateCount}`
|
||||
`Expected redo to restore Navigator duplicate ${componentName}. Before ${redoCount}, after ${redoDuplicateCount}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -490,9 +399,9 @@ test("Builder can duplicate and delete a component from Navigator context menu",
|
||||
fixture,
|
||||
component: componentName,
|
||||
});
|
||||
if (deletedCount !== initialCount + 1) {
|
||||
if (deletedCount !== redoCount) {
|
||||
throw new Error(
|
||||
`Expected Navigator delete to remove one ${componentName}. Before ${initialCount}, after ${deletedCount}`
|
||||
`Expected Navigator delete to remove one ${componentName}. Before ${redoCount}, after ${deletedCount}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -503,29 +412,27 @@ test("Builder can duplicate and delete a component from Navigator context menu",
|
||||
fixture,
|
||||
component: componentName,
|
||||
});
|
||||
if (undoDeleteCount !== initialCount + 2) {
|
||||
if (undoDeleteCount !== redoCount + 1) {
|
||||
throw new Error(
|
||||
`Expected undo to restore Navigator-deleted ${componentName}. Before ${initialCount}, after ${undoDeleteCount}`
|
||||
`Expected undo to restore Navigator-deleted ${componentName}. Before ${redoCount}, after ${undoDeleteCount}`
|
||||
);
|
||||
}
|
||||
|
||||
await measure(
|
||||
"pages actions reload navigator context menu mutations",
|
||||
async () => {
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
}
|
||||
);
|
||||
await measure("pages actions reload component mutations", async () => {
|
||||
await openProjectBuilder({
|
||||
page,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
});
|
||||
await waitForCanvasText({ page, text: insertedButtonText });
|
||||
const reloadedCount = await getInstanceComponentCount({
|
||||
fixture,
|
||||
component: componentName,
|
||||
});
|
||||
if (reloadedCount !== initialCount + 2) {
|
||||
if (reloadedCount !== initialCount + 3) {
|
||||
throw new Error(
|
||||
`Expected reload to preserve Navigator mutations for ${componentName}. Before ${initialCount}, after ${reloadedCount}`
|
||||
`Expected reload to preserve component actions for ${componentName}. Before ${initialCount}, after ${reloadedCount}`
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -5,10 +5,7 @@ import {
|
||||
waitForCanvasTextStyle,
|
||||
waitForHoveredCanvasTextStyle,
|
||||
} from "../flows/canvas-style";
|
||||
import {
|
||||
waitForChangeToBeSaved,
|
||||
waitForSyncStatus,
|
||||
} from "../flows/sync-status";
|
||||
import { waitForChangeToBeSaved } from "../flows/sync-status";
|
||||
import { createContentModeProject } from "../fixtures/content-mode-suite";
|
||||
import type { SeededContentModeProject } from "../fixtures/content-mode-project";
|
||||
import { test } from "../test";
|
||||
@@ -45,9 +42,6 @@ const setCssValue = async ({
|
||||
const save = waitForSave ? waitForChangeToBeSaved({ page }) : undefined;
|
||||
await input.press("Enter");
|
||||
await save;
|
||||
if (waitForSave) {
|
||||
await waitForSyncStatus({ page, status: "idle" });
|
||||
}
|
||||
};
|
||||
|
||||
const resetCssValue = async ({
|
||||
|
||||
Reference in new issue
Block a user