@@ -404,4 +404,80 @@ describe('TableWidget', () => {
404404 const col10Indicator = col10Header . querySelector ( '.sort-indicator' ) ;
405405 expect ( col10Indicator ) . not . toBeNull ( ) ;
406406 } ) ;
407+
408+ describe ( 'Max columns' , ( ) => {
409+ /*
410+ * Tests for the max columns dropdown functionality.
411+ */
412+
413+ it ( 'should render the max columns dropdown' , ( ) => {
414+ // Mock basic state
415+ model . get . mockImplementation ( ( property ) => {
416+ if ( property === 'max_columns' ) {
417+ return 7 ;
418+ }
419+ return null ;
420+ } ) ;
421+
422+ render ( { model, el } ) ;
423+
424+ const maxColumnsContainer = el . querySelector ( '.max-columns' ) ;
425+ expect ( maxColumnsContainer ) . not . toBeNull ( ) ;
426+ const label = maxColumnsContainer . querySelector ( 'label' ) ;
427+ expect ( label . textContent ) . toBe ( 'Max columns:' ) ;
428+ const select = maxColumnsContainer . querySelector ( 'select' ) ;
429+ expect ( select ) . not . toBeNull ( ) ;
430+ } ) ;
431+
432+ it ( 'should select the correct initial value' , ( ) => {
433+ const initialMaxColumns = 20 ;
434+ model . get . mockImplementation ( ( property ) => {
435+ if ( property === 'max_columns' ) {
436+ return initialMaxColumns ;
437+ }
438+ return null ;
439+ } ) ;
440+
441+ render ( { model, el } ) ;
442+
443+ const select = el . querySelector ( '.max-columns select' ) ;
444+ expect ( Number ( select . value ) ) . toBe ( initialMaxColumns ) ;
445+ } ) ;
446+
447+ it ( 'should handle None/null initial value as 0 (All)' , ( ) => {
448+ model . get . mockImplementation ( ( property ) => {
449+ if ( property === 'max_columns' ) {
450+ return null ; // Python None is null in JS
451+ }
452+ return null ;
453+ } ) ;
454+
455+ render ( { model, el } ) ;
456+
457+ const select = el . querySelector ( '.max-columns select' ) ;
458+ expect ( Number ( select . value ) ) . toBe ( 0 ) ;
459+ expect ( select . options [ select . selectedIndex ] . textContent ) . toBe ( 'All' ) ;
460+ } ) ;
461+
462+ it ( 'should update model when value changes' , ( ) => {
463+ model . get . mockImplementation ( ( property ) => {
464+ if ( property === 'max_columns' ) {
465+ return 7 ;
466+ }
467+ return null ;
468+ } ) ;
469+
470+ render ( { model, el } ) ;
471+
472+ const select = el . querySelector ( '.max-columns select' ) ;
473+
474+ // Change to 20
475+ select . value = '20' ;
476+ const event = new Event ( 'change' ) ;
477+ select . dispatchEvent ( event ) ;
478+
479+ expect ( model . set ) . toHaveBeenCalledWith ( 'max_columns' , 20 ) ;
480+ expect ( model . save_changes ) . toHaveBeenCalled ( ) ;
481+ } ) ;
482+ } ) ;
407483} ) ;
0 commit comments