Skip to content

Commit

Permalink
Added UI tests sandbox and graph-based tool (#15908)
Browse files Browse the repository at this point in the history
* Added sandbox tests

* Added tests for the 4 graph editors as well (initial tests)
  • Loading branch information
RaananW authored Nov 29, 2024
1 parent 5a111d8 commit fe7ee12
Show file tree
Hide file tree
Showing 11 changed files with 538 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test, expect } from "@playwright/test";
import { getGlobalConfig } from "@tools/test-tools";

const url = process.env.PLAYGROUND_BASE_URL || "https://playground.babylonjs.com/";
const url = process.env.PLAYGROUND_BASE_URL || getGlobalConfig().baseUrl.replace(":1337", process.env.PLAYGROUND_PORT || ":1338");

test("Playground is loaded (Desktop)", async ({ page }) => {
await page.goto(url, {
Expand Down
Binary file added packages/tools/sandbox/test/LogoSandbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions packages/tools/sandbox/test/interaction.sandbox.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { test, expect } from "@playwright/test";
import { readFileSync } from "fs";
import { getGlobalConfig } from "@tools/test-tools";

const url = process.env.SANDBOX_BASE_URL || getGlobalConfig().baseUrl.replace(":1337", process.env.SANDBOX_PORT || ":1339");

test("Sandbox is loaded (Desktop)", async ({ page }) => {
await page.goto(url, {
waitUntil: "networkidle",
});
await page.setViewportSize({
width: 1920,
height: 1080,
});
// check visibility of both canvas AND the editor
await expect(page.locator("#canvasZone")).toBeVisible();
// check snapshot of the page
const snapshot = await page.screenshot();
expect(snapshot).toMatchSnapshot();
});

test("dropping an image to the sandbox", async ({ page }) => {
await page.goto(url, {
waitUntil: "networkidle",
});
await page.setViewportSize({
width: 1920,
height: 1080,
});

// Read your file into a buffer.
const buffer = readFileSync(__dirname + "/LogoSandbox.png");

// Create the DataTransfer and File
const dataTransfer = await page.evaluateHandle((data) => {
const dt = new DataTransfer();
const file = new File([new Uint8Array(data)], "file.png", { type: "image/png" });
dt.items.add(file);
return dt;
}, buffer.toJSON().data);

// Now dispatch
await page.dispatchEvent("#renderCanvas", "drop", { dataTransfer });
// wait for #babylonjsLoadingDiv to be hidden
await page.waitForSelector("#babylonjsLoadingDiv", { state: "hidden" });
await page.waitForSelector("#babylonjsLoadingDiv", { state: "detached" });
// check snapshot of the page
const snapshot = await page.screenshot();
expect(snapshot).toMatchSnapshot();
});

test("loading a model using query parameters", async ({ page }) => {
await page.goto(url + "?assetUrl=https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/main/2.0/Box/glTF-Binary/Box.glb", {
waitUntil: "networkidle",
});
await page.setViewportSize({
width: 1920,
height: 1080,
});
// wait for #babylonjsLoadingDiv to be hidden
await page.waitForSelector("#babylonjsLoadingDiv", { state: "hidden" });
await page.waitForSelector("#babylonjsLoadingDiv", { state: "detached" });
// check snapshot of the page
const snapshot = await page.screenshot();
expect(snapshot).toMatchSnapshot();
});

test("inspector is opened when clicking on the button", async ({ page }) => {
await page.goto(url + "?assetUrl=https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/main/2.0/Box/glTF-Binary/Box.glb", {
waitUntil: "networkidle",
});
await page.setViewportSize({
width: 1920,
height: 1080,
});

// wait for #babylonjsLoadingDiv to be hidden
await page.waitForSelector("#babylonjsLoadingDiv", { state: "hidden" });
await page.waitForSelector("#babylonjsLoadingDiv", { state: "detached" });

// click the "Inspector" button
await page.getByTitle("Display inspector").click();
await expect(page.locator("#inspector-host")).toBeVisible();
await expect(page.locator("#scene-explorer-host")).toBeVisible();
// check snapshot of the page
const snapshot = await page.screenshot();
expect(snapshot).toMatchSnapshot();
});
Loading

0 comments on commit fe7ee12

Please sign in to comment.