@@ -340,31 +340,52 @@ describe('TableWidget', () => {
340340 * Tests that the widget correctly renders HTML with truncated columns (ellipsis)
341341 * and ensures that the ellipsis column is not treated as a sortable column.
342342 */
343- it ( 'should have a fixed height for the table container' , ( ) => {
344- // Mock the initial state
343+ it ( 'should set height dynamically on first load and remain fixed' , ( ) => {
344+ jest . useFakeTimers ( ) ;
345+
346+ // Mock the table's offsetHeight
347+ let mockHeight = 150 ;
348+ Object . defineProperty ( HTMLElement . prototype , 'offsetHeight' , {
349+ configurable : true ,
350+ get : ( ) => mockHeight ,
351+ } ) ;
352+
353+ // Mock model properties
345354 model . get . mockImplementation ( ( property ) => {
346355 if ( property === 'table_html' ) {
347356 return '<table>...</table>' ;
348357 }
349358 return null ;
350359 } ) ;
351360
352- // Load the CSS
353- const fs = require ( 'fs' ) ;
354- const path = require ( 'path' ) ;
355- const css = fs . readFileSync (
356- path . resolve ( __dirname , '../../bigframes/display/table_widget.css' ) ,
357- 'utf8' ,
358- ) ;
359- const style = document . createElement ( 'style' ) ;
360- style . textContent = css ;
361- document . head . appendChild ( style ) ;
362-
363361 render ( { model, el } ) ;
364362
365363 const tableContainer = el . querySelector ( '.table-container' ) ;
366- const styles = window . getComputedStyle ( tableContainer ) ;
367- expect ( styles . height ) . toBe ( '400px' ) ;
364+
365+ // --- First render ---
366+ const tableHtmlChangeHandler = model . on . mock . calls . find (
367+ ( call ) => call [ 0 ] === 'change:table_html' ,
368+ ) [ 1 ] ;
369+ tableHtmlChangeHandler ( ) ;
370+ jest . runAllTimers ( ) ;
371+
372+ // Height should be set to the mocked offsetHeight + 2px buffer
373+ expect ( tableContainer . style . height ) . toBe ( '152px' ) ;
374+
375+ // --- Second render (e.g., page size change) ---
376+ // Simulate the new content being taller
377+ mockHeight = 350 ;
378+ tableHtmlChangeHandler ( ) ;
379+ jest . runAllTimers ( ) ;
380+
381+ // Height should NOT change
382+ expect ( tableContainer . style . height ) . toBe ( '152px' ) ;
383+
384+ // Restore original implementation
385+ Object . defineProperty ( HTMLElement . prototype , 'offsetHeight' , {
386+ value : 0 ,
387+ } ) ;
388+ jest . useRealTimers ( ) ;
368389 } ) ;
369390
370391 it ( 'should render truncated columns with ellipsis and not make ellipsis sortable' , ( ) => {
0 commit comments