@@ -7,6 +7,8 @@ import { createRoot, type Root } from "react-dom/client";
77import { afterEach , beforeEach , describe , expect , it , vi } from "vite-plus/test" ;
88import { page , userEvent } from "vite-plus/test/browser" ;
99
10+ import "../index.css" ;
11+
1012import { filesystemEnvironment } from "../state/filesystem" ;
1113import { useRightPanelStore } from "../rightPanelStore" ;
1214import { getSyntaxHighlighterPromise } from "../lib/syntaxHighlighting" ;
@@ -129,6 +131,64 @@ function fileOptions(container: HTMLElement) {
129131 . filter ( ( label ) => label ?. startsWith ( "File options for " ) ) ;
130132}
131133
134+ describe ( "ChatMarkdown table layout" , ( ) => {
135+ it . each ( [
136+ { width : 36 , timeline : true , fits : true } ,
137+ { width : 48 , timeline : true , fits : true } ,
138+ { width : 35 , timeline : true , fits : false } ,
139+ { width : 48 , timeline : false , fits : false } ,
140+ ] ) (
141+ "wraps expanded cells with fit=$fits in a $width rem container (timeline=$timeline)" ,
142+ async ( { width, timeline, fits } ) => {
143+ const { container } = await render (
144+ < div style = { { width : `${ width } rem` } } >
145+ < div className = { timeline ? "@container/chat-lane chat-content-lane overflow-x-clip" : "" } >
146+ < ChatMarkdown
147+ cwd = { undefined }
148+ text = { [
149+ "| Change summary | Reason details | Verification status | Release impact | Followup actions |" ,
150+ "| --- | --- | --- | --- | --- |" ,
151+ "| Keep the complete explanation readable when the table is expanded in the conversation. | Allow each column to wrap its prose within the available space in the current chat lane. | Collapse and expand the table again to check that the text still fits and remains readable. | Keep the existing layout for narrow chat lanes and file previews. | Check the table again after resizing the conversation lane. |" ,
152+ ] . join ( "\n" ) }
153+ />
154+ </ div >
155+ </ div > ,
156+ ) ;
157+ const table = container . querySelector ( "table" ) ! ;
158+ const viewport = table . closest < HTMLElement > ( '[data-slot="scroll-area-viewport"]' ) ! ;
159+ const cell = table . tBodies [ 0 ] ! . rows [ 0 ] ! . cells [ 0 ] ! ;
160+ const collapse = ( ) => buttonsLabelled ( container , "Collapse table cells" ) [ 0 ] ;
161+ if ( collapse ( ) ) await act ( async ( ) => collapse ( ) ! . click ( ) ) ;
162+
163+ const collapsedWidth = table . getBoundingClientRect ( ) . width ;
164+ const collapsedHeight = cell . getBoundingClientRect ( ) . height ;
165+ expect ( viewport . clientWidth ) . toBeGreaterThan ( 0 ) ;
166+ expect ( viewport . scrollWidth ) . toBeGreaterThan ( viewport . clientWidth ) ;
167+ expect ( cell . scrollWidth ) . toBeGreaterThan ( cell . clientWidth ) ;
168+
169+ await act ( async ( ) => buttonsLabelled ( container , "Expand table cells" ) [ 0 ] ! . click ( ) ) ;
170+ const expandedWidth = table . getBoundingClientRect ( ) . width ;
171+ const expandedHeight = cell . getBoundingClientRect ( ) . height ;
172+ if ( fits ) {
173+ expect ( viewport . scrollWidth ) . toBeLessThanOrEqual ( viewport . clientWidth + 1 ) ;
174+ expect ( expandedWidth ) . toBeLessThanOrEqual ( viewport . clientWidth + 1 ) ;
175+ } else {
176+ expect ( viewport . scrollWidth ) . toBeGreaterThan ( viewport . clientWidth ) ;
177+ viewport . scrollLeft = 100 ;
178+ expect ( viewport . scrollLeft ) . toBeGreaterThan ( 0 ) ;
179+ }
180+ expect ( expandedHeight ) . toBeGreaterThan ( collapsedHeight ) ;
181+
182+ await act ( async ( ) => collapse ( ) ! . click ( ) ) ;
183+ expect ( table . getBoundingClientRect ( ) . width ) . toBeCloseTo ( collapsedWidth , 0 ) ;
184+ expect ( cell . getBoundingClientRect ( ) . height ) . toBeCloseTo ( collapsedHeight , 0 ) ;
185+ await act ( async ( ) => buttonsLabelled ( container , "Expand table cells" ) [ 0 ] ! . click ( ) ) ;
186+ expect ( table . getBoundingClientRect ( ) . width ) . toBeCloseTo ( expandedWidth , 0 ) ;
187+ expect ( cell . getBoundingClientRect ( ) . height ) . toBeCloseTo ( expandedHeight , 0 ) ;
188+ } ,
189+ ) ;
190+ } ) ;
191+
132192describe ( "ChatMarkdown bare anchor placeholders" , ( ) => {
133193 it . each ( [ "<A>" , "<a>" , "<a >" , "<a/>" , "<A/>" , "<a />" ] ) (
134194 "preserves unmatched %s without linking later blocks" ,
0 commit comments