@@ -150,6 +150,45 @@ describe('DataTable', () => {
150
150
const ageGroupSortState = table . getSortState ( 'ageGroup' ) ;
151
151
expect ( ageSortState ) . not . toBe ( ageGroupSortState ) ;
152
152
} ) ;
153
+
154
+ it ( 'should handle sorting with custom getValue returning undefined' , ( ) => {
155
+ const customColumns : ColumnDef < any > [ ] = [
156
+ {
157
+ id : 'customSort' ,
158
+ key : 'value' ,
159
+ name : 'Custom Sort' ,
160
+ sortable : true ,
161
+ getValue : ( row ) => ( row . value === 3 ? undefined : row . value )
162
+ }
163
+ ] ;
164
+ const customData = [
165
+ { id : 1 , value : 3 } ,
166
+ { id : 2 , value : 1 } ,
167
+ { id : 3 , value : 2 }
168
+ ] ;
169
+ const table = new DataTable ( { data : customData , columns : customColumns } ) ;
170
+ table . toggleSort ( 'customSort' ) ;
171
+ expect ( table . rows [ 0 ] . value ) . toBe ( 1 ) ;
172
+ expect ( table . rows [ 1 ] . value ) . toBe ( 2 ) ;
173
+ expect ( table . rows [ 2 ] . value ) . toBe ( 3 ) ;
174
+ } ) ;
175
+
176
+ it ( 'should maintain sort stability for equal elements' , ( ) => {
177
+ const data = [
178
+ { id : 1 , value : 'A' , order : 1 } ,
179
+ { id : 2 , value : 'B' , order : 2 } ,
180
+ { id : 3 , value : 'A' , order : 3 } ,
181
+ { id : 4 , value : 'C' , order : 4 } ,
182
+ { id : 5 , value : 'B' , order : 5 }
183
+ ] ;
184
+ const columns : ColumnDef < ( typeof data ) [ 0 ] > [ ] = [
185
+ { id : 'value' , key : 'value' , name : 'Value' , sortable : true } ,
186
+ { id : 'order' , key : 'order' , name : 'Order' , sortable : true }
187
+ ] ;
188
+ const table = new DataTable ( { data, columns } ) ;
189
+ table . toggleSort ( 'value' ) ;
190
+ expect ( table . rows . map ( ( r ) => r . id ) ) . toEqual ( [ 1 , 3 , 2 , 5 , 4 ] ) ;
191
+ } ) ;
153
192
} ) ;
154
193
155
194
describe ( 'Enhanced Sorting' , ( ) => {
@@ -332,6 +371,48 @@ describe('DataTable', () => {
332
371
table . setFilter ( 'ageGroup' , [ 'Young' ] ) ;
333
372
expect ( table . rows ) . toHaveLength ( 0 ) ; // No rows match both filters
334
373
} ) ;
374
+
375
+ it ( 'should handle filtering with complex custom filter function' , ( ) => {
376
+ const customColumns : ColumnDef < any > [ ] = [
377
+ {
378
+ id : 'complexFilter' ,
379
+ key : 'value' ,
380
+ name : 'Complex Filter' ,
381
+ filter : ( value , filterValue , row ) => {
382
+ return value > filterValue && row . id % 2 === 0 ;
383
+ }
384
+ }
385
+ ] ;
386
+ const customData = [
387
+ { id : 1 , value : 10 } ,
388
+ { id : 2 , value : 20 } ,
389
+ { id : 3 , value : 30 } ,
390
+ { id : 4 , value : 40 }
391
+ ] ;
392
+ const table = new DataTable ( { data : customData , columns : customColumns } ) ;
393
+ table . setFilter ( 'complexFilter' , [ 15 ] ) ;
394
+ expect ( table . rows ) . toHaveLength ( 2 ) ;
395
+ expect ( table . rows [ 0 ] . id ) . toBe ( 2 ) ;
396
+ expect ( table . rows [ 1 ] . id ) . toBe ( 4 ) ;
397
+ } ) ;
398
+
399
+ it ( 'should handle filtering with extremely long filter lists' , ( ) => {
400
+ const longFilterList = Array . from ( { length : 10000 } , ( _ , i ) => i ) ;
401
+ const table = new DataTable ( { data : sampleData , columns } ) ;
402
+ table . setFilter ( 'age' , longFilterList ) ;
403
+ expect ( table . rows ) . toHaveLength ( 5 ) ; // All rows should match
404
+ } ) ;
405
+
406
+ it ( 'should handle global filter with special regex characters' , ( ) => {
407
+ const data = [
408
+ { id : 1 , name : 'Alice (Manager)' } ,
409
+ { id : 2 , name : 'Bob [Developer]' }
410
+ ] as any ;
411
+ const table = new DataTable ( { data, columns } ) ;
412
+ table . globalFilter = '(Manager)' ;
413
+ expect ( table . rows ) . toHaveLength ( 1 ) ;
414
+ expect ( table . rows [ 0 ] . name ) . toBe ( 'Alice (Manager)' ) ;
415
+ } ) ;
335
416
} ) ;
336
417
337
418
describe ( 'Pagination' , ( ) => {
@@ -375,6 +456,21 @@ describe('DataTable', () => {
375
456
expect ( table . rows ) . toHaveLength ( 5 ) ;
376
457
expect ( table . totalPages ) . toBe ( 1 ) ;
377
458
} ) ;
459
+
460
+ it ( 'should handle setting page size to 0' , ( ) => {
461
+ const table = new DataTable ( { data : sampleData , columns, pageSize : 0 } ) ;
462
+ expect ( table . rows ) . toHaveLength ( 5 ) ; // Should default to showing all rows
463
+ } ) ;
464
+
465
+ it ( 'should handle navigation near total page count' , ( ) => {
466
+ const table = new DataTable ( { data : sampleData , columns, pageSize : 2 } ) ;
467
+ table . currentPage = 3 ;
468
+ expect ( table . canGoForward ) . toBe ( false ) ;
469
+ expect ( table . canGoBack ) . toBe ( true ) ;
470
+ table . currentPage = 2 ;
471
+ expect ( table . canGoForward ) . toBe ( true ) ;
472
+ expect ( table . canGoBack ) . toBe ( true ) ;
473
+ } ) ;
378
474
} ) ;
379
475
380
476
describe ( 'baseRows' , ( ) => {
0 commit comments