@@ -786,6 +786,7 @@ describe('DatatableComponent With Ghost Loading', () => {
786786 imports : [ DatatableComponent ] ,
787787 template : `
788788 <ngx-datatable
789+ style="block-size: 100%"
789790 columnMode="force"
790791 [rows]="rows()"
791792 [columns]="columns()"
@@ -821,17 +822,25 @@ describe('DatatableComponent With Ghost Loading', () => {
821822 datatable = fixture . debugElement . query ( By . directive ( DatatableComponent ) ) . componentInstance ;
822823 } ) ;
823824
824- it ( 'should push enough undefined rows to fill pageSize when ghost loading with no data' , async ( ) => {
825+ /** Waits for the body to be measured and returns the number of rows fitting into it completely. */
826+ const fullyVisibleRowCount = async ( ) => {
827+ await expect . poll ( ( ) => datatable . bodyHeight ( ) ) . toBeGreaterThan ( 0 ) ;
828+ await fixture . whenStable ( ) ;
829+ return Math . floor ( datatable . bodyHeight ( ) / component . rowHeight ( ) ) ;
830+ } ;
831+
832+ it ( 'should push enough undefined rows to fill the body when ghost loading with no data' , async ( ) => {
825833 component . ghostLoadingIndicator . set ( true ) ;
826834 component . scrollbarV . set ( true ) ;
827835 component . rows . set ( [ ] ) ;
828- await fixture . whenStable ( ) ;
836+ const rowCount = await fullyVisibleRowCount ( ) ;
829837
830838 const internalRows = datatable . _internalRows ( ) ;
831- const pageSize = datatable . pageSize ( ) ;
832839 const undefinedCount = internalRows . filter ( r => r === undefined ) . length ;
840+ const grid = fixture . nativeElement . querySelector ( '.datatable-grid' ) as HTMLElement ;
833841
834- expect ( undefinedCount ) . toBe ( Math . max ( pageSize , 1 ) ) ;
842+ expect ( undefinedCount ) . toBe ( rowCount ) ;
843+ expect ( grid . scrollHeight ) . toBe ( grid . clientHeight ) ;
835844 } ) ;
836845
837846 it ( 'should push only one undefined row when data already fills the viewport' , async ( ) => {
@@ -852,17 +861,16 @@ describe('DatatableComponent With Ghost Loading', () => {
852861 it ( 'should push enough undefined rows to fill remaining viewport when partial data is loaded' , async ( ) => {
853862 component . ghostLoadingIndicator . set ( true ) ;
854863 component . scrollbarV . set ( true ) ;
855- await fixture . whenStable ( ) ;
864+ const rowCount = await fullyVisibleRowCount ( ) ;
856865
857- const pageSize = datatable . pageSize ( ) ;
858866 const partialRows = Array . from ( { length : 3 } , ( _ , i ) => ( { name : `Row ${ i } ` } ) ) ;
859867 component . rows . set ( partialRows ) ;
860868 await fixture . whenStable ( ) ;
861869
862870 const internalRows = datatable . _internalRows ( ) ;
863871 const undefinedCount = internalRows . filter ( r => r === undefined ) . length ;
864872
865- expect ( undefinedCount ) . toBe ( Math . max ( pageSize - partialRows . length , 1 ) ) ;
873+ expect ( undefinedCount ) . toBe ( rowCount - partialRows . length ) ;
866874 expect ( internalRows . length ) . toBe ( partialRows . length + undefinedCount ) ;
867875 } ) ;
868876
0 commit comments