@@ -565,4 +565,77 @@ describe('<DataTable />', () => {
565565 expect ( threeSpanCells ) . toHaveLength ( 1 ) ;
566566 } ) ;
567567 } ) ;
568+
569+ describe ( 'fixedFirstColumns' , ( ) => {
570+ const headings = [ 'Product' , 'Price' , 'Order Number' ] ;
571+ const rows = [
572+ [
573+ 'Navy Merino Wool Blazer with khaki chinos and yellow belt' ,
574+ '$875.00' ,
575+ 124518 ,
576+ 83 ,
577+ '$122,500.00' ,
578+ ] ,
579+ ] ;
580+
581+ const columnContentTypes : DataTableProps [ 'columnContentTypes' ] = [
582+ 'text' ,
583+ 'numeric' ,
584+ 'numeric' ,
585+ ] ;
586+
587+ const fixedFirstColumnsProps = {
588+ headings,
589+ rows,
590+ columnContentTypes,
591+ } ;
592+
593+ it ( 'sets fixed first columns' , async ( ) => {
594+ const dataTable = mountWithApp (
595+ < DataTable { ...fixedFirstColumnsProps } fixedFirstColumns = { 2 } /> ,
596+ ) ;
597+
598+ const table = dataTable . find ( 'table' ) ! . domNode ;
599+
600+ Object . defineProperty ( table , 'scrollWidth' , {
601+ value : 100 ,
602+ writable : true ,
603+ configurable : true ,
604+ } ) ;
605+
606+ window . dispatchEvent ( new Event ( 'resize' ) ) ;
607+ timer . runAllTimers ( ) ;
608+
609+ dataTable . forceUpdate ( ) ;
610+
611+ const separateTable = dataTable . findAll ( 'table' ) [ 0 ] ;
612+ const separateTableHeadingGroup = separateTable . find ( 'thead' ) ;
613+ const separateTableHeaders = separateTableHeadingGroup ?. findAll ( 'th' ) ;
614+
615+ expect ( separateTableHeaders ) . toHaveLength ( 2 ) ;
616+ } ) ;
617+
618+ it ( 'sets "fixedFirstColumns" to 0 if it exceeds or is equal to columns amount' , ( ) => {
619+ const dataTable = mountWithApp (
620+ < DataTable { ...fixedFirstColumnsProps } fixedFirstColumns = { 3 } /> ,
621+ ) ;
622+
623+ const table = dataTable . find ( 'table' ) ! . domNode ;
624+
625+ Object . defineProperty ( table , 'scrollWidth' , {
626+ value : 100 ,
627+ writable : true ,
628+ configurable : true ,
629+ } ) ;
630+
631+ window . dispatchEvent ( new Event ( 'resize' ) ) ;
632+ timer . runAllTimers ( ) ;
633+
634+ dataTable . forceUpdate ( ) ;
635+
636+ const tables = dataTable . findAll ( 'table' ) ;
637+
638+ expect ( tables ) . toHaveLength ( 1 ) ;
639+ } ) ;
640+ } ) ;
568641} ) ;
0 commit comments