@@ -5,7 +5,7 @@ describe('Datatable component', () => {
55
66 beforeEach ( ( ) => {
77 TestBed . configureTestingModule ( {
8- imports : [ NgxDatatableModule ]
8+ imports : [ NgxDatatableModule ]
99 } ) ;
1010 } ) ;
1111
@@ -18,9 +18,9 @@ describe('Datatable component', () => {
1818 it ( 'should return a new array' , ( ) => {
1919 let fixture = TestBed . createComponent ( DatatableComponent ) ;
2020 let initialRows = [
21- { id : 1 } ,
22- { id : 2 } ,
23- { id : 3 }
21+ { id : 1 } ,
22+ { id : 2 } ,
23+ { id : 3 }
2424 ] ;
2525
2626 let columns = [
@@ -41,16 +41,42 @@ describe('Datatable component', () => {
4141 expect ( fixture . componentInstance . rows ) . toBe ( initialRows ) ;
4242
4343 fixture . componentInstance . onColumnSort ( {
44- sorts : [ { prop : 'foo' , dir : 'desc' } ]
44+ sorts : [ { prop : 'foo' , dir : 'desc' } ]
4545 } ) ;
4646
4747 fixture . componentInstance . sort
4848 . subscribe ( ( ) => {
49- console . log ( 'sorted event' ) ;
5049 } ) ;
5150
5251 expect ( fixture . componentInstance . rows ) . not . toBe ( initialRows ) ;
5352 } ) ;
5453 } ) ;
5554
55+ it ( 'should set offset to 0 when sorting by a column' , ( ) => {
56+ let fixture = TestBed . createComponent ( DatatableComponent ) ;
57+ let initialRows = [
58+ { id : 1 } ,
59+ { id : 2 } ,
60+ { id : 3 }
61+ ] ;
62+
63+ let columns = [
64+ {
65+ prop : 'id'
66+ }
67+ ] ;
68+
69+ fixture . componentInstance . rows = initialRows ;
70+ fixture . componentInstance . columns = columns ;
71+ fixture . componentInstance . offset = 1 ;
72+
73+ fixture . detectChanges ( ) ;
74+
75+ fixture . componentInstance . onColumnSort ( {
76+ sorts : [ { prop : 'id' , dir : 'desc' } ]
77+ } ) ;
78+
79+ expect ( fixture . componentInstance . offset ) . toBe ( 0 ) ;
80+ } ) ;
81+
5682} ) ;
0 commit comments