11// Control UI tests cover control ui e2e behavior.
2- import { describe , expect , it } from "vitest" ;
2+ import type { Page } from "playwright" ;
3+ import { afterEach , describe , expect , it , vi } from "vitest" ;
34import {
45 resolvePlaywrightChromiumExecutablePath ,
56 systemChromiumExecutableCandidates ,
7+ waitForControlUiRoute ,
68} from "./control-ui-e2e.ts" ;
79
810describe ( "resolvePlaywrightChromiumExecutablePath" , ( ) => {
@@ -28,3 +30,54 @@ describe("resolvePlaywrightChromiumExecutablePath", () => {
2830 ) . toBe ( "/custom/chromium" ) ;
2931 } ) ;
3032} ) ;
33+
34+ describe ( "waitForControlUiRoute" , ( ) => {
35+ afterEach ( ( ) => {
36+ document . body . replaceChildren ( ) ;
37+ } ) ;
38+
39+ it ( "keeps polling while a new tab has no app element" , async ( ) => {
40+ // SAFETY: this fixture implements the Page methods used by the route helper.
41+ const page = {
42+ async waitForFunction (
43+ predicate : ( target : { routeId : string } ) => boolean ,
44+ target : { routeId : string } ,
45+ ) {
46+ expect ( predicate ( target ) ) . toBe ( false ) ;
47+ const app = document . createElement ( "openclaw-app" ) ;
48+ Object . assign ( app , {
49+ runtime : {
50+ router : {
51+ getState : ( ) => ( {
52+ status : "success" ,
53+ resolvedLocation : { pathname : window . location . pathname } ,
54+ matches : [ { routeId : "chat" } ] ,
55+ pendingMatches : [ ] ,
56+ } ) ,
57+ } ,
58+ } ,
59+ } ) ;
60+ document . body . append ( app ) ;
61+ expect ( predicate ( target ) ) . toBe ( true ) ;
62+ return { dispose : vi . fn ( ) } ;
63+ } ,
64+ evaluate : ( read : ( ) => unknown ) => read ( ) ,
65+ } as unknown as Page ;
66+
67+ await waitForControlUiRoute ( page , { routeId : "chat" } ) ;
68+ } ) ;
69+
70+ it ( "preserves readiness failures when the app is still absent" , async ( ) => {
71+ const cause = new Error ( "Route readiness failed" ) ;
72+ // SAFETY: this fixture implements the Page methods used by the route helper.
73+ const page = {
74+ waitForFunction : vi . fn ( ) . mockRejectedValue ( cause ) ,
75+ evaluate : ( read : ( ) => unknown ) => read ( ) ,
76+ } as unknown as Page ;
77+
78+ await expect ( waitForControlUiRoute ( page , { routeId : "chat" } ) ) . rejects . toMatchObject ( {
79+ cause,
80+ message : expect . stringContaining ( '"router":null' ) ,
81+ } ) ;
82+ } ) ;
83+ } ) ;
0 commit comments