11import { expectDefined } from "@openclaw/normalization-core" ;
22import { afterEach , beforeAll , describe , expect , it , vi } from "vitest" ;
33import "../../../styles.css" ;
4+ import "../../../styles/chat.css" ;
45import "./chat-sidebar.ts" ;
56
67// The root jsdom ui shard also collects *.browser.test.ts files; CodeMirror
@@ -42,13 +43,23 @@ type DetailPanel = HTMLElement & {
4243 updateComplete : Promise < unknown > ;
4344} ;
4445
45- const mounted : DetailPanel [ ] = [ ] ;
46+ const mounted : HTMLElement [ ] = [ ] ;
4647
47- async function mountFile ( content : FileSidebarContent ) : Promise < DetailPanel > {
48+ async function mountFile ( content : FileSidebarContent , width ?: number ) : Promise < DetailPanel > {
4849 const panel = document . createElement ( "openclaw-chat-detail-panel" ) as DetailPanel ;
4950 panel . content = content ;
50- document . body . append ( panel ) ;
51- mounted . push ( panel ) ;
51+ if ( width === undefined ) {
52+ document . body . append ( panel ) ;
53+ mounted . push ( panel ) ;
54+ } else {
55+ const container = document . createElement ( "div" ) ;
56+ container . className = "side-panel__panel" ;
57+ container . style . cssText = `display:flex;width:${ width } px;height:320px;` ;
58+ panel . className = "chat-sidebar" ;
59+ container . append ( panel ) ;
60+ document . body . append ( container ) ;
61+ mounted . push ( container ) ;
62+ }
5263 await panel . updateComplete ;
5364 await expect . poll ( ( ) => panel . querySelector ( ".cm-editor" ) , { timeout : 5_000 } ) . not . toBeNull ( ) ;
5465 return panel ;
@@ -73,18 +84,20 @@ afterEach(() => {
7384
7485describe . runIf ( browserMode ) ( "chat file editor" , ( ) => {
7586 it ( "keeps long lines inside Review and gives horizontal scroll to the editor" , async ( ) => {
76- const panel = await mountFile ( {
77- kind : "file" ,
78- path : "src/long-line.ts" ,
79- name : "long-line.ts" ,
80- content : `export const value = "${ "long-content-" . repeat ( 80 ) } ";` ,
81- } ) ;
82- panel . style . width = "320px" ;
87+ const panel = await mountFile (
88+ {
89+ kind : "file" ,
90+ path : "src/long-line.ts" ,
91+ name : "long-line.ts" ,
92+ content : `export const value = "${ "long-content-" . repeat ( 80 ) } ";` ,
93+ } ,
94+ 320 ,
95+ ) ;
8396
8497 const fileView = panel . querySelector < HTMLElement > ( ".file-view" ) ! ;
8598 const scroller = panel . querySelector < HTMLElement > ( ".cm-scroller" ) ! ;
8699 await expect . poll ( ( ) => fileView . clientWidth ) . toBeGreaterThan ( 0 ) ;
87- expect ( fileView . clientWidth ) . toBeLessThanOrEqual ( panel . clientWidth ) ;
100+ expect ( fileView . clientWidth ) . toBeLessThanOrEqual ( panel . parentElement ! . clientWidth ) ;
88101 expect ( fileView . scrollWidth ) . toBe ( fileView . clientWidth ) ;
89102 expect ( scroller . scrollWidth ) . toBeGreaterThan ( scroller . clientWidth ) ;
90103 expect ( getComputedStyle ( scroller ) . overflowX ) . toBe ( "auto" ) ;
0 commit comments