@@ -4,6 +4,7 @@ import { GridService, ExtensionService, FilterService, GridStateService, SortSer
44import { CellArgs , Column , OnEventArgs , GridOption } from './../../models' ;
55
66declare const Slick : any ;
7+ jest . useFakeTimers ( ) ;
78
89const mockSelectionModel = {
910 init : jest . fn ( ) ,
@@ -39,6 +40,7 @@ const dataviewStub = {
3940 deleteItem : jest . fn ( ) ,
4041 deleteItems : jest . fn ( ) ,
4142 getIdxById : jest . fn ( ) ,
43+ getItemMetadata : jest . fn ( ) ,
4244 getItem : jest . fn ( ) ,
4345 getRowById : jest . fn ( ) ,
4446 insertItem : jest . fn ( ) ,
@@ -1079,23 +1081,21 @@ describe('Grid Service', () => {
10791081 } ) ;
10801082
10811083 describe ( 'highlightRowByMetadata method' , ( ) => {
1082- it ( 'should hightlight a row with a fading start & end delay' , ( done ) => {
1084+ it ( 'should hightlight a row with a fading start & end delay' , ( ) => {
10831085 const mockColumn = { id : 'field2' , field : 'field2' , width : 150 , rowClass : 'red' } as Column ;
10841086 const getItemSpy = jest . spyOn ( dataviewStub , 'getItem' ) . mockReturnValue ( mockColumn ) ;
10851087 const getIndexSpy = jest . spyOn ( dataviewStub , 'getIdxById' ) . mockReturnValue ( 0 ) ;
10861088 const updateSpy = jest . spyOn ( dataviewStub , 'updateItem' ) ;
10871089 const renderSpy = jest . spyOn ( service , 'renderGrid' ) ;
10881090
10891091 service . highlightRowByMetadata ( 2 , 1 , 1 ) ;
1092+ jest . runAllTimers ( ) ; // fast-forward timer
10901093
1091- setTimeout ( ( ) => {
1092- expect ( getItemSpy ) . toHaveBeenCalledWith ( 2 ) ;
1093- expect ( updateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
1094- expect ( updateSpy ) . toHaveBeenCalledWith ( mockColumn . id , mockColumn ) ;
1095- expect ( renderSpy ) . toHaveBeenCalled ( ) ;
1096- expect ( getIndexSpy ) . toHaveBeenCalled ( ) ;
1097- done ( ) ;
1098- } , 5 ) ;
1094+ expect ( getItemSpy ) . toHaveBeenCalledWith ( 2 ) ;
1095+ expect ( updateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
1096+ expect ( updateSpy ) . toHaveBeenCalledWith ( mockColumn . id , mockColumn ) ;
1097+ expect ( renderSpy ) . toHaveBeenCalled ( ) ;
1098+ expect ( getIndexSpy ) . toHaveBeenCalled ( ) ;
10991099 } ) ;
11001100 } ) ;
11011101
@@ -1492,6 +1492,28 @@ describe('Grid Service', () => {
14921492 } ) ;
14931493 } ) ;
14941494
1495+ describe ( 'highlightRow method' , ( ) => {
1496+ afterEach ( ( ) => {
1497+ jest . clearAllMocks ( ) ;
1498+ } ) ;
1499+
1500+ it ( 'should be able to highlight first row at zero index' , ( ) => {
1501+ const mockRowMetadata = ( rowNumber ) => ( { cssClasses : `row-${ rowNumber } ` } ) ;
1502+ const mockItem = { id : 0 , firstName : 'John' , lastName : 'Doe' } ;
1503+ jest . spyOn ( service , 'getItemRowMetadataToHighlight' ) . mockReturnValue ( mockRowMetadata ) ;
1504+ jest . spyOn ( dataviewStub , 'getItem' ) . mockReturnValue ( mockItem ) ;
1505+ jest . spyOn ( dataviewStub , 'getIdxById' ) . mockReturnValue ( 0 ) ;
1506+ const updateSpy = jest . spyOn ( dataviewStub , 'updateItem' ) ;
1507+ const renderSpy = jest . spyOn ( service , 'renderGrid' ) ;
1508+
1509+ service . highlightRow ( 0 , 10 , 15 ) ;
1510+ jest . runAllTimers ( ) ; // fast-forward timer
1511+
1512+ expect ( updateSpy ) . toHaveBeenCalledWith ( 0 , mockItem )
1513+ expect ( renderSpy ) . toHaveBeenCalledTimes ( 3 ) ;
1514+ } ) ;
1515+ } ) ;
1516+
14951517 // --
14961518 // DEPRECATED methods, to be removed eventually
14971519 // ----------------------
0 commit comments