@@ -126,6 +126,7 @@ describe('gridMenuExtension', () => {
126126 CLEAR_ALL_SORTING : 'Supprimer tous les tris' ,
127127 EXPORT_TO_CSV : 'Exporter en format CSV' ,
128128 EXPORT_TO_TAB_DELIMITED : 'Exporter en format texte (délimité par tabulation)' ,
129+ HELP : 'Aide' ,
129130 COMMANDS : 'Commandes' ,
130131 COLUMNS : 'Colonnes' ,
131132 FORCE_FIT_COLUMNS : 'Ajustement forcé des colonnes' ,
@@ -294,6 +295,7 @@ describe('gridMenuExtension', () => {
294295 const copyGridOptionsMock = { ...gridOptionsMock , enableFiltering : true } as unknown as GridOption ;
295296 jest . spyOn ( SharedService . prototype , 'gridOptions' , 'get' ) . mockReturnValue ( copyGridOptionsMock ) ;
296297 extension . register ( ) ;
298+ extension . register ( ) ; // calling 2x register to make sure it doesn't duplicate commands
297299 expect ( SharedService . prototype . gridOptions . gridMenu . customItems ) . toEqual ( [
298300 { iconCssClass : 'fa fa-filter text-danger' , title : 'Supprimer tous les filtres' , disabled : false , command : 'clear-filter' , positionOrder : 50 } ,
299301 { iconCssClass : 'fa fa-random' , title : 'Basculer la ligne des filtres' , disabled : false , command : 'toggle-filter' , positionOrder : 52 } ,
@@ -305,6 +307,7 @@ describe('gridMenuExtension', () => {
305307 const copyGridOptionsMock = { ...gridOptionsMock , enableFiltering : true , gridMenu : { hideToggleFilterCommand : true , hideRefreshDatasetCommand : true } } as unknown as GridOption ;
306308 jest . spyOn ( SharedService . prototype , 'gridOptions' , 'get' ) . mockReturnValue ( copyGridOptionsMock ) ;
307309 extension . register ( ) ;
310+ extension . register ( ) ; // calling 2x register to make sure it doesn't duplicate commands
308311 expect ( SharedService . prototype . gridOptions . gridMenu . customItems ) . toEqual ( [
309312 { iconCssClass : 'fa fa-filter text-danger' , title : 'Supprimer tous les filtres' , disabled : false , command : 'clear-filter' , positionOrder : 50 }
310313 ] ) ;
@@ -314,6 +317,7 @@ describe('gridMenuExtension', () => {
314317 const copyGridOptionsMock = { ...gridOptionsMock , enableFiltering : true , gridMenu : { hideClearAllFiltersCommand : true , hideRefreshDatasetCommand : true } } as unknown as GridOption ;
315318 jest . spyOn ( SharedService . prototype , 'gridOptions' , 'get' ) . mockReturnValue ( copyGridOptionsMock ) ;
316319 extension . register ( ) ;
320+ extension . register ( ) ; // calling 2x register to make sure it doesn't duplicate commands
317321 expect ( SharedService . prototype . gridOptions . gridMenu . customItems ) . toEqual ( [
318322 { iconCssClass : 'fa fa-random' , title : 'Basculer la ligne des filtres' , disabled : false , command : 'toggle-filter' , positionOrder : 52 } ,
319323 ] ) ;
@@ -323,6 +327,7 @@ describe('gridMenuExtension', () => {
323327 const copyGridOptionsMock = { ...gridOptionsMock , enableFiltering : true , gridMenu : { hideClearAllFiltersCommand : true , hideToggleFilterCommand : true } } as unknown as GridOption ;
324328 jest . spyOn ( SharedService . prototype , 'gridOptions' , 'get' ) . mockReturnValue ( copyGridOptionsMock ) ;
325329 extension . register ( ) ;
330+ extension . register ( ) ; // calling 2x register to make sure it doesn't duplicate commands
326331 expect ( SharedService . prototype . gridOptions . gridMenu . customItems ) . toEqual ( [
327332 { iconCssClass : 'fa fa-refresh' , title : 'Rafraîchir les données' , disabled : false , command : 'refresh-dataset' , positionOrder : 54 }
328333 ] ) ;
@@ -332,6 +337,7 @@ describe('gridMenuExtension', () => {
332337 const copyGridOptionsMock = { ...gridOptionsMock , showPreHeaderPanel : true } as unknown as GridOption ;
333338 jest . spyOn ( SharedService . prototype , 'gridOptions' , 'get' ) . mockReturnValue ( copyGridOptionsMock ) ;
334339 extension . register ( ) ;
340+ extension . register ( ) ; // calling 2x register to make sure it doesn't duplicate commands
335341 expect ( SharedService . prototype . gridOptions . gridMenu . customItems ) . toEqual ( [
336342 { iconCssClass : 'fa fa-random' , title : 'Basculer la ligne de pré-en-tête' , disabled : false , command : 'toggle-preheader' , positionOrder : 52 }
337343 ] ) ;
@@ -348,6 +354,7 @@ describe('gridMenuExtension', () => {
348354 const copyGridOptionsMock = { ...gridOptionsMock , enableSorting : true } as unknown as GridOption ;
349355 jest . spyOn ( SharedService . prototype , 'gridOptions' , 'get' ) . mockReturnValue ( copyGridOptionsMock ) ;
350356 extension . register ( ) ;
357+ extension . register ( ) ; // calling 2x register to make sure it doesn't duplicate commands
351358 expect ( SharedService . prototype . gridOptions . gridMenu . customItems ) . toEqual ( [
352359 { iconCssClass : 'fa fa-unsorted text-danger' , title : 'Supprimer tous les tris' , disabled : false , command : 'clear-sorting' , positionOrder : 51 }
353360 ] ) ;
@@ -364,6 +371,7 @@ describe('gridMenuExtension', () => {
364371 const copyGridOptionsMock = { ...gridOptionsMock , enableExport : true , gridMenu : { hideExportTextDelimitedCommand : true } } as unknown as GridOption ;
365372 jest . spyOn ( SharedService . prototype , 'gridOptions' , 'get' ) . mockReturnValue ( copyGridOptionsMock ) ;
366373 extension . register ( ) ;
374+ extension . register ( ) ; // calling 2x register to make sure it doesn't duplicate commands
367375 expect ( SharedService . prototype . gridOptions . gridMenu . customItems ) . toEqual ( [
368376 { iconCssClass : 'fa fa-download' , title : 'Exporter en format CSV' , disabled : false , command : 'export-csv' , positionOrder : 53 }
369377 ] ) ;
@@ -380,6 +388,7 @@ describe('gridMenuExtension', () => {
380388 const copyGridOptionsMock = { ...gridOptionsMock , enableExport : true , gridMenu : { hideExportCsvCommand : true } } as unknown as GridOption ;
381389 jest . spyOn ( SharedService . prototype , 'gridOptions' , 'get' ) . mockReturnValue ( copyGridOptionsMock ) ;
382390 extension . register ( ) ;
391+ extension . register ( ) ; // calling 2x register to make sure it doesn't duplicate commands
383392 expect ( SharedService . prototype . gridOptions . gridMenu . customItems ) . toEqual ( [
384393 { iconCssClass : 'fa fa-download' , title : 'Exporter en format texte (délimité par tabulation)' , disabled : false , command : 'export-text-delimited' , positionOrder : 54 }
385394 ] ) ;
@@ -393,6 +402,61 @@ describe('gridMenuExtension', () => {
393402 } ) ;
394403 } ) ;
395404
405+ describe ( 'adding Grid Menu Custom Items' , ( ) => {
406+ const customItemsMock = [ {
407+ iconCssClass : 'fa fa-question-circle' ,
408+ titleKey : 'HELP' ,
409+ disabled : false ,
410+ command : 'help' ,
411+ positionOrder : 99
412+ } ] ;
413+
414+ beforeEach ( ( ) => {
415+ const copyGridOptionsMock = {
416+ ...gridOptionsMock ,
417+ enableExport : true ,
418+ gridMenu : {
419+ customItems : customItemsMock ,
420+ hideExportCsvCommand : false ,
421+ hideExportTextDelimitedCommand : true ,
422+ hideRefreshDatasetCommand : true ,
423+ hideSyncResizeButton : true ,
424+ hideToggleFilterCommand : true ,
425+ hideTogglePreHeaderCommand : true
426+ }
427+ } as unknown as GridOption ;
428+
429+ jest . spyOn ( SharedService . prototype , 'dataView' , 'get' ) . mockReturnValue ( dataViewStub ) ;
430+ jest . spyOn ( SharedService . prototype , 'grid' , 'get' ) . mockReturnValue ( gridStub ) ;
431+ jest . spyOn ( SharedService . prototype , 'gridOptions' , 'get' ) . mockReturnValue ( gridOptionsMock ) ;
432+ jest . spyOn ( SharedService . prototype , 'allColumns' , 'get' ) . mockReturnValue ( columnsMock ) ;
433+ jest . spyOn ( SharedService . prototype , 'visibleColumns' , 'get' ) . mockReturnValue ( columnsMock ) ;
434+ jest . spyOn ( SharedService . prototype , 'columnDefinitions' , 'get' ) . mockReturnValue ( columnsMock ) ;
435+ jest . spyOn ( SharedService . prototype , 'gridOptions' , 'get' ) . mockReturnValue ( copyGridOptionsMock ) ;
436+ } ) ;
437+
438+ afterEach ( ( ) => {
439+ extension . dispose ( ) ;
440+ } ) ;
441+
442+ it ( 'should have user grid menu custom items' , ( ) => {
443+ extension . register ( ) ;
444+ expect ( SharedService . prototype . gridOptions . gridMenu . customItems ) . toEqual ( [
445+ { command : 'export-csv' , disabled : false , iconCssClass : 'fa fa-download' , positionOrder : 53 , title : 'Exporter en format CSV' } ,
446+ { command : 'help' , disabled : false , iconCssClass : 'fa fa-question-circle' , positionOrder : 99 , title : 'Aide' , titleKey : 'HELP' } ,
447+ ] ) ;
448+ } ) ;
449+
450+ it ( 'should have same user grid menu custom items even when grid menu extension is registered multiple times' , ( ) => {
451+ extension . register ( ) ;
452+ extension . register ( ) ;
453+ expect ( SharedService . prototype . gridOptions . gridMenu . customItems ) . toEqual ( [
454+ { command : 'export-csv' , disabled : false , iconCssClass : 'fa fa-download' , positionOrder : 53 , title : 'Exporter en format CSV' } ,
455+ { command : 'help' , disabled : false , iconCssClass : 'fa fa-question-circle' , positionOrder : 99 , title : 'Aide' , titleKey : 'HELP' } ,
456+ ] ) ;
457+ } ) ;
458+ } ) ;
459+
396460 describe ( 'refreshBackendDataset method' , ( ) => {
397461 afterEach ( ( ) => {
398462 jest . spyOn ( SharedService . prototype , 'gridOptions' , 'get' ) . mockReturnValue ( gridOptionsMock ) ;
0 commit comments