@@ -10,9 +10,11 @@ declare const Slick: any;
1010
1111const gridStub = {
1212 getOptions : jest . fn ( ) ,
13+ getSelectedRows : jest . fn ( ) ,
1314 registerPlugin : jest . fn ( ) ,
1415 setColumns : jest . fn ( ) ,
1516 setOptions : jest . fn ( ) ,
17+ setSelectedRows : jest . fn ( ) ,
1618} ;
1719
1820const mockAddon = jest . fn ( ) . mockImplementation ( ( ) => ( {
@@ -71,7 +73,7 @@ describe('columnPickerExtension', () => {
7173 } ) ;
7274
7375 it ( 'should register the addon' , ( ) => {
74- const onRegisteredSpy = jest . spyOn ( SharedService . prototype . gridOptions . columnPicker , 'onExtensionRegistered' ) ;
76+ const onRegisteredSpy = jest . spyOn ( SharedService . prototype . gridOptions . columnPicker ! , 'onExtensionRegistered' ) ;
7577
7678 const instance = extension . register ( ) ;
7779 const addonInstance = extension . getAddonInstance ( ) ;
@@ -84,7 +86,7 @@ describe('columnPickerExtension', () => {
8486
8587 it ( 'should call internal event handler subscribe and expect the "onColumnsChanged" grid option to be called when addon notify is called' , ( ) => {
8688 const handlerSpy = jest . spyOn ( extension . eventHandler , 'subscribe' ) ;
87- const onColumnSpy = jest . spyOn ( SharedService . prototype . gridOptions . columnPicker , 'onColumnsChanged' ) ;
89+ const onColumnSpy = jest . spyOn ( SharedService . prototype . gridOptions . columnPicker ! , 'onColumnsChanged' ) ;
8890 const visibleColsSpy = jest . spyOn ( SharedService . prototype , 'visibleColumns' , 'set' ) ;
8991 const readjustSpy = jest . spyOn ( extensionUtility , 'readjustFrozenColumnIndexWhenNeeded' ) ;
9092
@@ -104,7 +106,7 @@ describe('columnPickerExtension', () => {
104106 it ( `should call internal event handler subscribe and expect the "onColumnsChanged" grid option to be called when addon notify is called
105107 and it should override "visibleColumns" when array passed as arguments is bigger than previous visible columns` , ( ) => {
106108 const handlerSpy = jest . spyOn ( extension . eventHandler , 'subscribe' ) ;
107- const onColumnSpy = jest . spyOn ( SharedService . prototype . gridOptions . columnPicker , 'onColumnsChanged' ) ;
109+ const onColumnSpy = jest . spyOn ( SharedService . prototype . gridOptions . columnPicker ! , 'onColumnsChanged' ) ;
108110 const visibleColsSpy = jest . spyOn ( SharedService . prototype , 'visibleColumns' , 'set' ) ;
109111
110112 const instance = extension . register ( ) ;
@@ -119,6 +121,25 @@ describe('columnPickerExtension', () => {
119121 expect ( visibleColsSpy ) . toHaveBeenCalledWith ( columnsMock ) ;
120122 } ) ;
121123
124+ it ( 'should call internal "onColumnsChanged" event and expect "setSelectedRows" method to be called using Row Selection is enabled' , ( ) => {
125+ const mockRowSelection = [ 0 , 3 , 5 ] ;
126+
127+ const handlerSpy = jest . spyOn ( extension . eventHandler , 'subscribe' ) ;
128+ jest . spyOn ( gridStub , 'getSelectedRows' ) . mockReturnValue ( mockRowSelection ) ;
129+ const setSelectionSpy = jest . spyOn ( gridStub , 'setSelectedRows' ) ;
130+
131+ gridOptionsMock . enableRowSelection = true ;
132+ const instance = extension . register ( ) ;
133+ instance . onColumnsChanged . notify ( { columnId : 'field1' , showing : true , allColumns : columnsMock , columns : columnsMock . slice ( 0 , 1 ) , grid : gridStub } , new Slick . EventData ( ) , gridStub ) ;
134+
135+ expect ( handlerSpy ) . toHaveBeenCalledTimes ( 1 ) ;
136+ expect ( handlerSpy ) . toHaveBeenCalledWith (
137+ { notify : expect . anything ( ) , subscribe : expect . anything ( ) , unsubscribe : expect . anything ( ) , } ,
138+ expect . anything ( )
139+ ) ;
140+ expect ( setSelectionSpy ) . toHaveBeenCalledWith ( mockRowSelection ) ;
141+ } ) ;
142+
122143 it ( 'should call internal "onColumnsChanged" event and expect "readjustFrozenColumnIndexWhenNeeded" method to be called when the grid is detected to be a frozen grid' , ( ) => {
123144 gridOptionsMock . frozenColumn = 0 ;
124145 const handlerSpy = jest . spyOn ( extension . eventHandler , 'subscribe' ) ;
@@ -157,9 +178,9 @@ describe('columnPickerExtension', () => {
157178 expect ( utilitySpy ) . toHaveBeenCalled ( ) ;
158179 expect ( translateSpy ) . toHaveBeenCalled ( ) ;
159180 expect ( updateColsSpy ) . toHaveBeenCalledWith ( SharedService . prototype . gridOptions . columnPicker ) ;
160- expect ( SharedService . prototype . gridOptions . columnPicker . columnTitle ) . toBe ( 'Colonnes' ) ;
161- expect ( SharedService . prototype . gridOptions . columnPicker . forceFitTitle ) . toBe ( 'Ajustement forcé des colonnes' ) ;
162- expect ( SharedService . prototype . gridOptions . columnPicker . syncResizeTitle ) . toBe ( 'Redimension synchrone' ) ;
181+ expect ( SharedService . prototype . gridOptions . columnPicker ! . columnTitle ) . toBe ( 'Colonnes' ) ;
182+ expect ( SharedService . prototype . gridOptions . columnPicker ! . forceFitTitle ) . toBe ( 'Ajustement forcé des colonnes' ) ;
183+ expect ( SharedService . prototype . gridOptions . columnPicker ! . syncResizeTitle ) . toBe ( 'Redimension synchrone' ) ;
163184 expect ( columnsMock ) . toEqual ( [
164185 { id : 'field1' , field : 'field1' , width : 100 , name : 'Titre' , nameKey : 'TITLE' } ,
165186 { id : 'field2' , field : 'field2' , width : 75 }
0 commit comments