Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: Center empty asset folder drop state (#5911)

Oleg Isonen7d7c23d30a1f
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 0695465fa4..ce28b752b3 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -182,7 +182,7 @@ jobs:
# into same-base files with different shard tags, such as
# `pages-actions.[shard-1].e2e.ts` and
# `pages-actions.[shard-2].e2e.ts`.
- shard: [shard-1, shard-2, shard-3]
+ shard: [shard-1, shard-2, shard-3, shard-4]
environment:
name: development
diff --git a/apps/builder/app/builder/shared/assets/asset-panel-state.tsx b/apps/builder/app/builder/shared/assets/asset-panel-state.tsx
index be7b300ee5..beee0c6c05 100644
--- a/apps/builder/app/builder/shared/assets/asset-panel-state.tsx
+++ b/apps/builder/app/builder/shared/assets/asset-panel-state.tsx
@@ -5,18 +5,24 @@ export const AssetPanelState = ({
message,
description,
active = false,
+ overlay = false,
}: {
message: string;
description?: string;
active?: boolean;
+ overlay?: boolean;
}) => (
<Flex
+ data-asset-panel-state-overlay={overlay ? "" : undefined}
align="center"
justify="center"
direction="column"
css={{
flex: 1,
minHeight: 0,
+ ...(overlay
+ ? { position: "absolute", inset: 0, pointerEvents: "none" }
+ : {}),
margin: theme.spacing[4],
color: active
? theme.colors.foregroundMain
diff --git a/apps/builder/app/builder/shared/assets/assets-shell.test.tsx b/apps/builder/app/builder/shared/assets/assets-shell.test.tsx
index d39c786d92..899a2a31f5 100644
--- a/apps/builder/app/builder/shared/assets/assets-shell.test.tsx
+++ b/apps/builder/app/builder/shared/assets/assets-shell.test.tsx
@@ -27,6 +27,28 @@ const renderer = createAssetManagerTestRenderer();
afterEach(renderer.cleanup);
describe("AssetsShell", () => {
+ test("centers the empty state independently from empty folder content", () => {
+ const container = renderer.render(
+ <AssetsShell
+ searchProps={{}}
+ isEmpty
+ type="file"
+ emptyContent={<button type="button">Back</button>}
+ >
+ <div />
+ </AssetsShell>
+ );
+
+ expect(
+ container.querySelector("[data-asset-panel-state-overlay]")
+ ).not.toBeNull();
+ expect(
+ Array.from(container.querySelectorAll("button")).some(
+ (button) => button.textContent === "Back"
+ )
+ ).toBe(true);
+ });
+
test("opens its context menu from panel chrome outside the asset list", () => {
const container = renderer.render(
<AssetsShell
diff --git a/apps/builder/app/builder/shared/assets/assets-shell.tsx b/apps/builder/app/builder/shared/assets/assets-shell.tsx
index 5d2c18a009..0324e1fed4 100644
--- a/apps/builder/app/builder/shared/assets/assets-shell.tsx
+++ b/apps/builder/app/builder/shared/assets/assets-shell.tsx
@@ -237,9 +237,13 @@ export const AssetsShell = ({
</Flex>
<Separator />
{isEmpty ? (
- <Flex direction="column" css={{ flex: 1, minHeight: 0 }}>
+ <Flex
+ direction="column"
+ css={{ flex: 1, minHeight: 0, position: "relative" }}
+ >
{emptyContent}
<AssetPanelState
+ overlay={emptyContent !== undefined}
message={emptyMessage}
active={dragState === OVER}
description={
diff --git a/apps/builder/e2e/test-modules.test.ts b/apps/builder/e2e/test-modules.test.ts
index 6d5a1921f1..d2b9994052 100644
--- a/apps/builder/e2e/test-modules.test.ts
+++ b/apps/builder/e2e/test-modules.test.ts
@@ -3,16 +3,21 @@ import { getE2eTestModules } from "./test-modules";
test("discovers every e2e module and filters ownership by shard tag", () => {
const files = [
+ "asset-folders-selection-actions.[shard-4].e2e.ts",
"pages-drag.[shard-3].e2e.ts",
"navigator-drag.[shard-1].e2e.ts",
"helper.ts",
];
expect(getE2eTestModules(files)).toEqual([
+ "./tests/asset-folders-selection-actions.[shard-4].e2e.ts",
"./tests/navigator-drag.[shard-1].e2e.ts",
"./tests/pages-drag.[shard-3].e2e.ts",
]);
expect(getE2eTestModules(files, "shard-3")).toEqual([
"./tests/pages-drag.[shard-3].e2e.ts",
]);
+ expect(getE2eTestModules(files, "shard-4")).toEqual([
+ "./tests/asset-folders-selection-actions.[shard-4].e2e.ts",
+ ]);
});
diff --git a/apps/builder/e2e/tests/asset-folders-selection-actions.[shard-4].e2e.ts b/apps/builder/e2e/tests/asset-folders-selection-actions.[shard-4].e2e.ts
new file mode 100644
index 0000000000..6e8beb1fd7
--- /dev/null
+++ b/apps/builder/e2e/tests/asset-folders-selection-actions.[shard-4].e2e.ts
@@ -0,0 +1,403 @@
+import {
+ createAssetFolder,
+ openAssetsPanel,
+ uploadAsset,
+} from "../flows/assets-panel";
+import { openProjectBuilder } from "../flows/builder";
+import { dragPointer } from "../flows/drag";
+import {
+ waitForChangeToBeSaved,
+ waitForSyncStatus,
+} from "../flows/sync-status";
+import { createContentModeProject } from "../fixtures/content-mode-suite";
+import { newIsolatedPage, test } from "../harness";
+
+test("Assets can be selected by dragging across the panel", async () => {
+ const fixture = await createContentModeProject({
+ email: "[email protected]",
+ title: "Asset Folder Lasso Select E2E",
+ builderToken: "asset-folder-lasso-select-e2e-builder-token",
+ });
+ const { page, close } = await newIsolatedPage();
+
+ try {
+ await openProjectBuilder({
+ page,
+ projectId: fixture.projectId,
+ authToken: fixture.builderToken,
+ });
+ await waitForSyncStatus({ page, status: "idle" });
+ await openAssetsPanel({ page });
+ 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);
+ const firstBounds = await firstAsset.boundingBox();
+ const secondBounds = await secondAsset.boundingBox();
+ const viewport = firstAsset.locator(
+ "xpath=ancestor::*[@data-asset-manager-scroll-area]"
+ );
+ const viewportBounds = await viewport.boundingBox();
+ if (
+ firstBounds === null ||
+ secondBounds === null ||
+ viewportBounds === null
+ ) {
+ throw new Error("Expected visible assets and asset-list viewport");
+ }
+
+ const start = {
+ x: viewportBounds.x + viewportBounds.width - 2,
+ y: viewportBounds.y + viewportBounds.height - 2,
+ };
+ const end = {
+ x: Math.min(firstBounds.x, secondBounds.x) - 2,
+ y: Math.min(firstBounds.y, secondBounds.y) - 2,
+ };
+ await page.mouse.move(start.x, start.y);
+ await page.mouse.down();
+ try {
+ await page.mouse.move(end.x, end.y, { steps: 10 });
+ await page.locator("[data-asset-manager-marquee]").waitFor();
+ } finally {
+ await page.mouse.up();
+ }
+
+ for (const asset of [firstAsset, secondAsset]) {
+ const option = asset.locator("xpath=ancestor::*[@role='option']");
+ if ((await option.getAttribute("aria-selected")) !== "true") {
+ throw new Error(
+ "Expected dragging across the panel to select both assets"
+ );
+ }
+ }
+ } finally {
+ await close();
+ }
+});
+
+test("Multiselected folders can be dragged into a folder", async () => {
+ const fixture = await createContentModeProject({
+ email: "[email protected]",
+ title: "Asset Folder Multifolder Drag E2E",
+ builderToken: "asset-folder-multifolder-drag-e2e-builder-token",
+ });
+ const { page, close } = await newIsolatedPage();
+
+ try {
+ 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();
+ } finally {
+ await close();
+ }
+});
+
+test("Dragging an asset auto-scrolls a long folder list", async () => {
+ const fixture = await createContentModeProject({
+ email: "[email protected]",
+ title: "Asset Folder Autoscroll E2E",
+ builderToken: "asset-folder-autoscroll-e2e-builder-token",
+ });
+ const { page, close } = await newIsolatedPage();
+
+ try {
+ 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",
+ });
+ const scrollArea = page.locator("[data-asset-manager-scroll-area]");
+ for (let index = 0; index < 24; index += 1) {
+ await createAssetFolder({
+ page,
+ name: `Filler ${String(index).padStart(2, "0")}`,
+ });
+ const overflows = await scrollArea.evaluate(
+ (element) => element.scrollHeight > element.clientHeight + 80
+ );
+ if (overflows) {
+ break;
+ }
+ }
+ const destination = await createAssetFolder({
+ page,
+ name: "Destination",
+ });
+ const asset = page.getByTitle(assetTitle);
+ await asset.scrollIntoViewIfNeeded();
+ if ((await scrollArea.evaluate((element) => element.scrollTop)) === 0) {
+ throw new Error("Expected the long asset list to be scrolled");
+ }
+
+ const assetBounds = await asset.boundingBox();
+ const scrollBounds = await scrollArea.boundingBox();
+ if (assetBounds === null || scrollBounds === null) {
+ throw new Error("Expected visible asset and native scroll area");
+ }
+ const from = {
+ x: assetBounds.x + assetBounds.width / 2,
+ y: assetBounds.y + assetBounds.height / 2,
+ };
+ await page.mouse.move(from.x, from.y);
+ await page.mouse.down();
+ try {
+ await page.mouse.move(from.x + 8, from.y + 8, { steps: 4 });
+ const deadline = Date.now() + 10_000;
+ let destinationBounds = await destination.boundingBox();
+ while (
+ Date.now() < deadline &&
+ (destinationBounds === null ||
+ destinationBounds.y < scrollBounds.y ||
+ destinationBounds.y + destinationBounds.height >
+ scrollBounds.y + scrollBounds.height)
+ ) {
+ await page.mouse.move(
+ scrollBounds.x + scrollBounds.width / 2,
+ scrollBounds.y + 4,
+ { steps: 2 }
+ );
+ await page.waitForTimeout(120);
+ destinationBounds = await destination.boundingBox();
+ }
+ if (
+ destinationBounds === null ||
+ destinationBounds.y < scrollBounds.y ||
+ destinationBounds.y + destinationBounds.height >
+ scrollBounds.y + scrollBounds.height
+ ) {
+ throw new Error(
+ "Expected auto-scroll to reveal the destination folder"
+ );
+ }
+ await page.mouse.move(
+ destinationBounds.x + destinationBounds.width / 2,
+ destinationBounds.y + destinationBounds.height / 2,
+ { steps: 4 }
+ );
+ const dropDeadline = Date.now() + 5_000;
+ while (
+ Date.now() < dropDeadline &&
+ (await destination.getAttribute("data-is-drop-over")) !== "true"
+ ) {
+ await page.mouse.move(
+ destinationBounds.x + destinationBounds.width / 2 + 1,
+ destinationBounds.y + destinationBounds.height / 2,
+ { steps: 2 }
+ );
+ await page.waitForTimeout(100);
+ }
+ if ((await destination.getAttribute("data-is-drop-over")) !== "true") {
+ throw new Error("Expected the destination folder to accept the drop");
+ }
+ const save = waitForChangeToBeSaved({ page, timeout: 30_000 });
+ await page.mouse.up();
+ await save;
+ } catch (error) {
+ await page.mouse.up();
+ throw error;
+ }
+
+ await asset.waitFor({ state: "hidden" });
+ await destination.dblclick();
+ await page.getByTitle(assetTitle).waitFor();
+ } finally {
+ await close();
+ }
+});
+
+test("Multiselected assets can be moved from the context menu", async () => {
+ const fixture = await createContentModeProject({
+ email: "[email protected]",
+ title: "Asset Folder Menu Move E2E",
+ builderToken: "asset-folder-menu-move-e2e-builder-token",
+ });
+ const { page, close } = await newIsolatedPage();
+
+ try {
+ 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();
+ } finally {
+ await close();
+ }
+});
+
+test("Folders can be multiselected and deleted as one operation", async () => {
+ const fixture = await createContentModeProject({
+ email: "[email protected]",
+ title: "Asset Folder Multiselect E2E",
+ builderToken: "asset-folder-multiselect-e2e-builder-token",
+ });
+ const { page, close } = await newIsolatedPage();
+ const folderNames = ["Alpha", "Bravo", "Charlie"];
+
+ try {
+ await openProjectBuilder({
+ page,
+ projectId: fixture.projectId,
+ authToken: fixture.builderToken,
+ });
+ await waitForSyncStatus({ page, status: "idle" });
+ await openAssetsPanel({ page });
+ const folders = [];
+ for (const name of folderNames) {
+ folders.push(await createAssetFolder({ page, name }));
+ }
+
+ await folders[1]!.click({ button: "right" });
+ await page.getByRole("menuitem", { name: "Settings" }).waitFor();
+ await page.keyboard.press("Escape");
+
+ await folders[0]!.click();
+ await folders[2]!.click({ modifiers: ["Shift"] });
+ const options = page.getByRole("option");
+ for (const folder of folders) {
+ const option = options.filter({ has: folder });
+ if ((await option.getAttribute("aria-selected")) !== "true") {
+ throw new Error("Expected Shift + Click to select the folder range");
+ }
+ }
+
+ await page.keyboard.press("Escape");
+ await folders[0]!.click();
+ await folders[2]!.click({
+ modifiers: [process.platform === "darwin" ? "Meta" : "Control"],
+ });
+ const selectedOptions = page.locator(
+ '[role="option"][aria-selected="true"]'
+ );
+ if ((await selectedOptions.count()) !== 2) {
+ throw new Error("Expected Cmd/Ctrl + Click to select two folders");
+ }
+
+ await folders[0]!.click({ button: "right" });
+ await page.getByRole("menuitem", { name: "Delete" }).click();
+ const deleteDialog = page
+ .getByRole("dialog")
+ .filter({ hasText: "Delete selected items" });
+ await deleteDialog.waitFor();
+ await Promise.all([
+ waitForChangeToBeSaved({ page }),
+ deleteDialog.getByRole("button", { name: "Delete" }).click(),
+ ]);
+
+ await folders[0]!.waitFor({ state: "hidden" });
+ await folders[2]!.waitFor({ state: "hidden" });
+ await folders[1]!.waitFor({ state: "visible" });
+
+ await openProjectBuilder({
+ page,
+ projectId: fixture.projectId,
+ authToken: fixture.builderToken,
+ });
+ await openAssetsPanel({ page });
+ await page
+ .getByRole("button", { name: "Folder Bravo", exact: true })
+ .waitFor();
+ for (const deletedName of ["Alpha", "Charlie"]) {
+ if (
+ await page
+ .getByRole("button", { name: `Folder ${deletedName}`, exact: true })
+ .isVisible()
+ ) {
+ throw new Error(`Expected ${deletedName} to stay deleted after reload`);
+ }
+ }
+ } finally {
+ await close();
+ }
+});
diff --git a/apps/builder/e2e/tests/asset-folders.[shard-1].e2e.ts b/apps/builder/e2e/tests/asset-folders.[shard-1].e2e.ts
index d7be7dbd25..48f1420afe 100644
--- a/apps/builder/e2e/tests/asset-folders.[shard-1].e2e.ts
+++ b/apps/builder/e2e/tests/asset-folders.[shard-1].e2e.ts
@@ -7,7 +7,6 @@ import {
} from "../flows/assets-panel";
import { openProjectBuilder } from "../flows/builder";
import { loginWithSecret } from "../flows/dashboard";
-import { dragPointer } from "../flows/drag";
import {
waitForChangeToBeSaved,
waitForSyncStatus,
@@ -320,393 +319,3 @@ test("Multiselected assets can be dragged into a folder", async () => {
await close();
}
});
-
-test("Assets can be selected by dragging across the panel", async () => {
- const fixture = await createContentModeProject({
- email: "[email protected]",
- title: "Asset Folder Lasso Select E2E",
- builderToken: "asset-folder-lasso-select-e2e-builder-token",
- });
- const { page, close } = await newIsolatedPage();
-
- try {
- await openProjectBuilder({
- page,
- projectId: fixture.projectId,
- authToken: fixture.builderToken,
- });
- await waitForSyncStatus({ page, status: "idle" });
- await openAssetsPanel({ page });
- 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);
- const firstBounds = await firstAsset.boundingBox();
- const secondBounds = await secondAsset.boundingBox();
- const viewport = firstAsset.locator(
- "xpath=ancestor::*[@data-asset-manager-scroll-area]"
- );
- const viewportBounds = await viewport.boundingBox();
- if (
- firstBounds === null ||
- secondBounds === null ||
- viewportBounds === null
- ) {
- throw new Error("Expected visible assets and asset-list viewport");
- }
-
- const start = {
- x: viewportBounds.x + viewportBounds.width - 2,
- y: viewportBounds.y + viewportBounds.height - 2,
- };
- const end = {
- x: Math.min(firstBounds.x, secondBounds.x) - 2,
- y: Math.min(firstBounds.y, secondBounds.y) - 2,
- };
- await page.mouse.move(start.x, start.y);
- await page.mouse.down();
- try {
- await page.mouse.move(end.x, end.y, { steps: 10 });
- await page.locator("[data-asset-manager-marquee]").waitFor();
- } finally {
- await page.mouse.up();
- }
-
- for (const asset of [firstAsset, secondAsset]) {
- const option = asset.locator("xpath=ancestor::*[@role='option']");
- if ((await option.getAttribute("aria-selected")) !== "true") {
- throw new Error(
- "Expected dragging across the panel to select both assets"
- );
- }
- }
- } finally {
- await close();
- }
-});
-
-test("Multiselected folders can be dragged into a folder", async () => {
- const fixture = await createContentModeProject({
- email: "[email protected]",
- title: "Asset Folder Multifolder Drag E2E",
- builderToken: "asset-folder-multifolder-drag-e2e-builder-token",
- });
- const { page, close } = await newIsolatedPage();
-
- try {
- 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();
- } finally {
- await close();
- }
-});
-
-test("Dragging an asset auto-scrolls a long folder list", async () => {
- const fixture = await createContentModeProject({
- email: "[email protected]",
- title: "Asset Folder Autoscroll E2E",
- builderToken: "asset-folder-autoscroll-e2e-builder-token",
- });
- const { page, close } = await newIsolatedPage();
-
- try {
- 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",
- });
- const scrollArea = page.locator("[data-asset-manager-scroll-area]");
- for (let index = 0; index < 24; index += 1) {
- await createAssetFolder({
- page,
- name: `Filler ${String(index).padStart(2, "0")}`,
- });
- const overflows = await scrollArea.evaluate(
- (element) => element.scrollHeight > element.clientHeight + 80
- );
- if (overflows) {
- break;
- }
- }
- const destination = await createAssetFolder({
- page,
- name: "Destination",
- });
- const asset = page.getByTitle(assetTitle);
- await asset.scrollIntoViewIfNeeded();
- if ((await scrollArea.evaluate((element) => element.scrollTop)) === 0) {
- throw new Error("Expected the long asset list to be scrolled");
- }
-
- const assetBounds = await asset.boundingBox();
- const scrollBounds = await scrollArea.boundingBox();
- if (assetBounds === null || scrollBounds === null) {
- throw new Error("Expected visible asset and native scroll area");
- }
- const from = {
- x: assetBounds.x + assetBounds.width / 2,
- y: assetBounds.y + assetBounds.height / 2,
- };
- await page.mouse.move(from.x, from.y);
- await page.mouse.down();
- try {
- await page.mouse.move(from.x + 8, from.y + 8, { steps: 4 });
- const deadline = Date.now() + 10_000;
- let destinationBounds = await destination.boundingBox();
- while (
- Date.now() < deadline &&
- (destinationBounds === null ||
- destinationBounds.y < scrollBounds.y ||
- destinationBounds.y + destinationBounds.height >
- scrollBounds.y + scrollBounds.height)
- ) {
- await page.mouse.move(
- scrollBounds.x + scrollBounds.width / 2,
- scrollBounds.y + 4,
- { steps: 2 }
- );
- await page.waitForTimeout(120);
- destinationBounds = await destination.boundingBox();
- }
- if (
- destinationBounds === null ||
- destinationBounds.y < scrollBounds.y ||
- destinationBounds.y + destinationBounds.height >
- scrollBounds.y + scrollBounds.height
- ) {
- throw new Error(
- "Expected auto-scroll to reveal the destination folder"
- );
- }
- await page.mouse.move(
- destinationBounds.x + destinationBounds.width / 2,
- destinationBounds.y + destinationBounds.height / 2,
- { steps: 4 }
- );
- const dropDeadline = Date.now() + 5_000;
- while (
- Date.now() < dropDeadline &&
- (await destination.getAttribute("data-is-drop-over")) !== "true"
- ) {
- await page.mouse.move(
- destinationBounds.x + destinationBounds.width / 2 + 1,
- destinationBounds.y + destinationBounds.height / 2,
- { steps: 2 }
- );
- await page.waitForTimeout(100);
- }
- if ((await destination.getAttribute("data-is-drop-over")) !== "true") {
- throw new Error("Expected the destination folder to accept the drop");
- }
- const save = waitForChangeToBeSaved({ page, timeout: 30_000 });
- await page.mouse.up();
- await save;
- } catch (error) {
- await page.mouse.up();
- throw error;
- }
-
- await asset.waitFor({ state: "hidden" });
- await destination.dblclick();
- await page.getByTitle(assetTitle).waitFor();
- } finally {
- await close();
- }
-});
-
-test("Multiselected assets can be moved from the context menu", async () => {
- const fixture = await createContentModeProject({
- email: "[email protected]",
- title: "Asset Folder Menu Move E2E",
- builderToken: "asset-folder-menu-move-e2e-builder-token",
- });
- const { page, close } = await newIsolatedPage();
-
- try {
- 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();
- } finally {
- await close();
- }
-});
-
-test("Folders can be multiselected and deleted as one operation", async () => {
- const fixture = await createContentModeProject({
- email: "[email protected]",
- title: "Asset Folder Multiselect E2E",
- builderToken: "asset-folder-multiselect-e2e-builder-token",
- });
- const { page, close } = await newIsolatedPage();
- const folderNames = ["Alpha", "Bravo", "Charlie"];
-
- try {
- await openProjectBuilder({
- page,
- projectId: fixture.projectId,
- authToken: fixture.builderToken,
- });
- await waitForSyncStatus({ page, status: "idle" });
- await openAssetsPanel({ page });
- const folders = [];
- for (const name of folderNames) {
- folders.push(await createAssetFolder({ page, name }));
- }
-
- await folders[1]!.click({ button: "right" });
- await page.getByRole("menuitem", { name: "Settings" }).waitFor();
- await page.keyboard.press("Escape");
-
- await folders[0]!.click();
- await folders[2]!.click({ modifiers: ["Shift"] });
- const options = page.getByRole("option");
- for (const folder of folders) {
- const option = options.filter({ has: folder });
- if ((await option.getAttribute("aria-selected")) !== "true") {
- throw new Error("Expected Shift + Click to select the folder range");
- }
- }
-
- await page.keyboard.press("Escape");
- await folders[0]!.click();
- await folders[2]!.click({
- modifiers: [process.platform === "darwin" ? "Meta" : "Control"],
- });
- const selectedOptions = page.locator(
- '[role="option"][aria-selected="true"]'
- );
- if ((await selectedOptions.count()) !== 2) {
- throw new Error("Expected Cmd/Ctrl + Click to select two folders");
- }
-
- await folders[0]!.click({ button: "right" });
- await page.getByRole("menuitem", { name: "Delete" }).click();
- const deleteDialog = page
- .getByRole("dialog")
- .filter({ hasText: "Delete selected items" });
- await deleteDialog.waitFor();
- await Promise.all([
- waitForChangeToBeSaved({ page }),
- deleteDialog.getByRole("button", { name: "Delete" }).click(),
- ]);
-
- await folders[0]!.waitFor({ state: "hidden" });
- await folders[2]!.waitFor({ state: "hidden" });
- await folders[1]!.waitFor({ state: "visible" });
-
- await openProjectBuilder({
- page,
- projectId: fixture.projectId,
- authToken: fixture.builderToken,
- });
- await openAssetsPanel({ page });
- await page
- .getByRole("button", { name: "Folder Bravo", exact: true })
- .waitFor();
- for (const deletedName of ["Alpha", "Charlie"]) {
- if (
- await page
- .getByRole("button", { name: `Folder ${deletedName}`, exact: true })
- .isVisible()
- ) {
- throw new Error(`Expected ${deletedName} to stay deleted after reload`);
- }
- }
- } finally {
- await close();
- }
-});