#!/usr/bin/env node /** * Focused case: create a child collection, set it active, delete it. * * node tools/web/complete/probe-collection.mjs --base-url http://127.0.0.1:5176 */ import { ASSETS, parseArgs, launchBrowser, newPage, openFile, waitScene } from "../course/lib/lesson-recorder.mjs"; const args = parseArgs(); const BASE = args.baseUrl || "http://127.0.0.1:5176"; const browser = await launchBrowser(args.gpu); const { context, page, consoleErrors } = await newPage(browser, { baseUrl: BASE }); page.setDefaultTimeout(90_000); const log = (...parts) => console.log(new Date().toISOString().slice(11, 19), ...parts); const state = async () => page.evaluate(() => ({ status: document.querySelector('[data-testid="engine-status"]')?.textContent ?? "", alerts: Array.from(document.querySelectorAll('[role="alert"]')).map((node) => node.textContent).slice(0, 3), cards: Array.from(document.querySelectorAll('[data-testid="collection-visibility-workbench"] input[aria-label^="集合名称"]')).map((input) => input.value), outliner: document.querySelector('.outliner-tree, [aria-label="Outliner"]')?.textContent?.slice(0, 200) ?? "", })); try { await openFile(page, ASSETS.studio); await waitScene(page, { objects: 6, timeout: 240_000 }); const panel = page.locator('[data-testid="collection-visibility-workbench"]'); await panel.waitFor({ timeout: 30_000 }); log("start", JSON.stringify(await state())); await page.getByRole("button", { name: "New Collection", exact: true }).click(); await page.waitForTimeout(1500); log("created", JSON.stringify(await state())); const card = panel.locator('fieldset').filter({ has: page.locator('legend', { hasText: "Collection 2" }) }).first(); await card.waitFor({ timeout: 30_000 }); await card.getByRole("button", { name: "新建子集合", exact: true }).click(); await page.waitForTimeout(1200); await card.getByRole("button", { name: "设为活动集合", exact: true }).click(); await page.waitForTimeout(1000); log("active", JSON.stringify(await state())); await card.getByRole("button", { name: "删除层级", exact: true }).click(); await page.waitForTimeout(1500); log("deleted", JSON.stringify(await state())); } catch (error) { log("probe error", error instanceof Error ? error.message : String(error)); log("state", JSON.stringify(await state().catch(() => null))); } finally { log("consoleErrors", JSON.stringify(consoleErrors.slice(-10))); await context.close(); await browser.close(); }