@@ -103,7 +103,7 @@ describe('GridMenuControl', () => {
103
103
let translateService : TranslateServiceStub ;
104
104
let sharedService : SharedService ;
105
105
106
- const gridMenuOptionsMock = {
106
+ const gridMenuOptionsMock : GridMenu = {
107
107
commandLabels : {
108
108
clearAllFiltersCommandKey : 'CLEAR_ALL_FILTERS' ,
109
109
clearAllSortingCommandKey : 'CLEAR_ALL_SORTING' ,
@@ -1156,6 +1156,7 @@ describe('GridMenuControl', () => {
1156
1156
control . init ( ) ;
1157
1157
expect ( SharedService . prototype . gridOptions . gridMenu ! . commandItems ) . toEqual ( [
1158
1158
{
1159
+ _orgTitle : '' ,
1159
1160
iconCssClass : 'mdi mdi-pin-off-outline' ,
1160
1161
titleKey : 'CLEAR_PINNING' ,
1161
1162
title : 'Dégeler les colonnes/rangées' ,
@@ -1175,6 +1176,7 @@ describe('GridMenuControl', () => {
1175
1176
control . init ( ) ; // calling 2x register to make sure it doesn't duplicate commands
1176
1177
expect ( SharedService . prototype . gridOptions . gridMenu ! . commandItems ) . toEqual ( [
1177
1178
{
1179
+ _orgTitle : '' ,
1178
1180
iconCssClass : 'mdi mdi-filter-remove-outline' ,
1179
1181
titleKey : 'CLEAR_ALL_FILTERS' ,
1180
1182
title : 'Supprimer tous les filtres' ,
@@ -1183,6 +1185,7 @@ describe('GridMenuControl', () => {
1183
1185
positionOrder : 50 ,
1184
1186
} ,
1185
1187
{
1188
+ _orgTitle : '' ,
1186
1189
iconCssClass : 'mdi mdi-flip-vertical' ,
1187
1190
titleKey : 'TOGGLE_FILTER_ROW' ,
1188
1191
title : 'Basculer la ligne des filtres' ,
@@ -1191,6 +1194,7 @@ describe('GridMenuControl', () => {
1191
1194
positionOrder : 53 ,
1192
1195
} ,
1193
1196
{
1197
+ _orgTitle : '' ,
1194
1198
iconCssClass : 'mdi mdi-sync' ,
1195
1199
titleKey : 'REFRESH_DATASET' ,
1196
1200
title : 'Rafraîchir les données' ,
@@ -1221,6 +1225,7 @@ describe('GridMenuControl', () => {
1221
1225
control . init ( ) ; // calling 2x register to make sure it doesn't duplicate commands
1222
1226
expect ( SharedService . prototype . gridOptions . gridMenu ! . commandItems ) . toEqual ( [
1223
1227
{
1228
+ _orgTitle : '' ,
1224
1229
iconCssClass : 'mdi mdi-filter-remove-outline' ,
1225
1230
titleKey : 'CLEAR_ALL_FILTERS' ,
1226
1231
title : 'Supprimer tous les filtres' ,
@@ -1251,6 +1256,7 @@ describe('GridMenuControl', () => {
1251
1256
control . init ( ) ; // calling 2x register to make sure it doesn't duplicate commands
1252
1257
expect ( SharedService . prototype . gridOptions . gridMenu ! . commandItems ) . toEqual ( [
1253
1258
{
1259
+ _orgTitle : '' ,
1254
1260
iconCssClass : 'mdi mdi-flip-vertical' ,
1255
1261
titleKey : 'TOGGLE_FILTER_ROW' ,
1256
1262
title : 'Basculer la ligne des filtres' ,
@@ -1280,6 +1286,7 @@ describe('GridMenuControl', () => {
1280
1286
control . init ( ) ; // calling 2x register to make sure it doesn't duplicate commands
1281
1287
expect ( SharedService . prototype . gridOptions . gridMenu ! . commandItems ) . toEqual ( [
1282
1288
{
1289
+ _orgTitle : '' ,
1283
1290
iconCssClass : 'mdi mdi-brightness-4' ,
1284
1291
titleKey : 'TOGGLE_DARK_MODE' ,
1285
1292
title : 'Basculer le mode clair/sombre' ,
@@ -1310,6 +1317,7 @@ describe('GridMenuControl', () => {
1310
1317
control . init ( ) ; // calling 2x register to make sure it doesn't duplicate commands
1311
1318
expect ( SharedService . prototype . gridOptions . gridMenu ! . commandItems ) . toEqual ( [
1312
1319
{
1320
+ _orgTitle : '' ,
1313
1321
iconCssClass : 'mdi mdi-sync' ,
1314
1322
titleKey : 'REFRESH_DATASET' ,
1315
1323
title : 'Rafraîchir les données' ,
@@ -1329,6 +1337,7 @@ describe('GridMenuControl', () => {
1329
1337
control . init ( ) ; // calling 2x register to make sure it doesn't duplicate commands
1330
1338
expect ( SharedService . prototype . gridOptions . gridMenu ! . commandItems ) . toEqual ( [
1331
1339
{
1340
+ _orgTitle : '' ,
1332
1341
iconCssClass : 'mdi mdi-flip-vertical' ,
1333
1342
titleKey : 'TOGGLE_PRE_HEADER_ROW' ,
1334
1343
title : 'Basculer la ligne de pré-en-tête' ,
@@ -1367,6 +1376,7 @@ describe('GridMenuControl', () => {
1367
1376
control . init ( ) ; // calling 2x register to make sure it doesn't duplicate commands
1368
1377
expect ( SharedService . prototype . gridOptions . gridMenu ! . commandItems ) . toEqual ( [
1369
1378
{
1379
+ _orgTitle : '' ,
1370
1380
iconCssClass : 'mdi mdi-sort-variant-off' ,
1371
1381
titleKey : 'CLEAR_ALL_SORTING' ,
1372
1382
title : 'Supprimer tous les tris' ,
@@ -1415,6 +1425,7 @@ describe('GridMenuControl', () => {
1415
1425
control . init ( ) ; // calling 2x register to make sure it doesn't duplicate commands
1416
1426
expect ( SharedService . prototype . gridOptions . gridMenu ! . commandItems ) . toEqual ( [
1417
1427
{
1428
+ _orgTitle : '' ,
1418
1429
iconCssClass : 'mdi mdi-download' ,
1419
1430
titleKey : 'EXPORT_TO_CSV' ,
1420
1431
title : 'Exporter en format CSV' ,
@@ -1466,6 +1477,7 @@ describe('GridMenuControl', () => {
1466
1477
control . init ( ) ; // calling 2x register to make sure it doesn't duplicate commands
1467
1478
expect ( SharedService . prototype . gridOptions . gridMenu ! . commandItems ) . toEqual ( [
1468
1479
{
1480
+ _orgTitle : '' ,
1469
1481
iconCssClass : 'mdi mdi-file-excel-outline text-success' ,
1470
1482
titleKey : 'EXPORT_TO_EXCEL' ,
1471
1483
title : 'Exporter vers Excel' ,
@@ -1495,6 +1507,7 @@ describe('GridMenuControl', () => {
1495
1507
control . init ( ) ; // calling 2x register to make sure it doesn't duplicate commands
1496
1508
expect ( SharedService . prototype . gridOptions . gridMenu ! . commandItems ) . toEqual ( [
1497
1509
{
1510
+ _orgTitle : '' ,
1498
1511
iconCssClass : 'mdi mdi-download' ,
1499
1512
titleKey : 'EXPORT_TO_TAB_DELIMITED' ,
1500
1513
title : 'Exporter en format texte (délimité par tabulation)' ,
@@ -1843,6 +1856,10 @@ describe('GridMenuControl', () => {
1843
1856
. mockReturnValue ( 1 ) ;
1844
1857
1845
1858
translateService . use ( 'fr' ) ;
1859
+ gridOptionsMock . gridMenu ! . commandTitle = '' ;
1860
+ gridOptionsMock . gridMenu ! . columnTitle = '' ;
1861
+ gridOptionsMock . gridMenu ! . forceFitTitle = '' ;
1862
+ gridOptionsMock . gridMenu ! . syncResizeTitle = '' ;
1846
1863
gridOptionsMock . gridMenu ! . hideForceFitButton = false ;
1847
1864
gridOptionsMock . gridMenu ! . hideSyncResizeButton = false ;
1848
1865
gridOptionsMock . syncColumnCellResize = true ;
@@ -1852,8 +1869,8 @@ describe('GridMenuControl', () => {
1852
1869
1853
1870
control . columns = columnsMock ;
1854
1871
control . initEventHandlers ( ) ;
1855
- control . translateGridMenu ( ) ;
1856
1872
control . init ( ) ;
1873
+ control . translateGridMenu ( ) ;
1857
1874
const buttonElm = document . querySelector ( '.slick-grid-menu-button' ) as HTMLDivElement ;
1858
1875
buttonElm . dispatchEvent ( new Event ( 'click' , { bubbles : true , cancelable : true , composed : false } ) ) ;
1859
1876
control . menuElement ! . querySelector ( 'input[type="checkbox"]' ) ! . dispatchEvent ( new Event ( 'click' , { bubbles : true } ) ) ;
@@ -1876,5 +1893,57 @@ describe('GridMenuControl', () => {
1876
1893
expect ( control . getAllColumns ( ) ) . toEqual ( columnsMock ) ;
1877
1894
expect ( control . getVisibleColumns ( ) ) . toEqual ( columnsMock ) ;
1878
1895
} ) ;
1896
+
1897
+ it ( 'should not translate when providing custom titles' , ( ) => {
1898
+ const handlerSpy = vi . spyOn ( control . eventHandler , 'subscribe' ) ;
1899
+ const utilitySpy = vi . spyOn ( extensionUtility , 'getPickerTitleOutputString' ) ;
1900
+ const translateSpy = vi . spyOn ( extensionUtility , 'translateItems' ) ;
1901
+ vi . spyOn ( gridStub , 'getColumnIndex' )
1902
+ . mockReturnValue ( undefined as any )
1903
+ . mockReturnValue ( 1 ) ;
1904
+
1905
+ translateService . use ( 'fr' ) ;
1906
+ gridOptionsMock . gridMenu ! . commandTitle = 'Custom Command Title' ;
1907
+ gridOptionsMock . gridMenu ! . columnTitle = 'Custom Column Title' ;
1908
+ gridOptionsMock . gridMenu ! . forceFitTitle = 'Custom Force Fit Title' ;
1909
+ gridOptionsMock . gridMenu ! . syncResizeTitle = 'Custom Sync Resize Title' ;
1910
+ gridOptionsMock . gridMenu ! . hideForceFitButton = false ;
1911
+ gridOptionsMock . gridMenu ! . hideSyncResizeButton = false ;
1912
+ gridOptionsMock . syncColumnCellResize = true ;
1913
+ gridOptionsMock . forceFitColumns = true ;
1914
+ vi . spyOn ( SharedService . prototype , 'gridOptions' , 'get' ) . mockReturnValue ( gridOptionsMock ) ;
1915
+ vi . spyOn ( gridStub , 'getOptions' ) . mockReturnValue ( gridOptionsMock ) ;
1916
+
1917
+ control . columns = columnsMock ;
1918
+ control . initEventHandlers ( ) ;
1919
+ control . init ( ) ;
1920
+ control . translateGridMenu ( ) ;
1921
+ const buttonElm = document . querySelector ( '.slick-grid-menu-button' ) as HTMLDivElement ;
1922
+ buttonElm . dispatchEvent ( new Event ( 'click' , { bubbles : true , cancelable : true , composed : false } ) ) ;
1923
+ control . menuElement ! . querySelector ( 'input[type="checkbox"]' ) ! . dispatchEvent ( new Event ( 'click' , { bubbles : true } ) ) ;
1924
+ // const commandTitleElm = control.menuElement!.querySelectorAll('.slickgrid_124343 .slick-menu-command-list .slick-menu-title')[0] as HTMLSpanElement;
1925
+ const columnTitleElm = control . menuElement ! . querySelector ( '.slickgrid_124343 .slick-menu-title' ) as HTMLSpanElement ;
1926
+ const labelForcefitElm = control . menuElement ! . querySelector ( 'label[for=slickgrid_124343-gridmenu-colpicker-forcefit]' ) as HTMLLabelElement ;
1927
+ const labelSyncElm = control . menuElement ! . querySelector ( 'label[for=slickgrid_124343-gridmenu-colpicker-syncresize]' ) as HTMLLabelElement ;
1928
+
1929
+ expect ( handlerSpy ) . toHaveBeenCalledTimes ( 4 ) ;
1930
+ // expect(commandTitleElm.textContent).toBe('Custom Command Title');
1931
+ expect ( columnTitleElm . textContent ) . toBe ( 'Custom Column Title' ) ;
1932
+ expect ( labelForcefitElm . textContent ) . toBe ( 'Custom Force Fit Title' ) ;
1933
+ expect ( labelSyncElm . textContent ) . toBe ( 'Custom Sync Resize Title' ) ;
1934
+ expect ( utilitySpy ) . toHaveBeenCalled ( ) ;
1935
+ expect ( translateSpy ) . toHaveBeenCalled ( ) ;
1936
+ // expect((SharedService.prototype.gridOptions.gridMenu as GridMenu).commandTitle).toBe('Custom Command Title');
1937
+ expect ( ( SharedService . prototype . gridOptions . gridMenu as GridMenu ) . columnTitle ) . toBe ( 'Custom Column Title' ) ;
1938
+ expect ( ( SharedService . prototype . gridOptions . gridMenu as GridMenu ) . forceFitTitle ) . toBe ( 'Custom Force Fit Title' ) ;
1939
+ expect ( ( SharedService . prototype . gridOptions . gridMenu as GridMenu ) . syncResizeTitle ) . toBe ( 'Custom Sync Resize Title' ) ;
1940
+ expect ( columnsMock ) . toEqual ( [
1941
+ { id : 'field1' , field : 'field1' , name : 'Titre' , width : 100 , nameKey : 'TITLE' } ,
1942
+ { id : 'field2' , field : 'field2' , name : 'Field 2' , width : 75 } ,
1943
+ { id : 'field3' , field : 'field3' , name : 'Field 3' , columnGroup : 'Billing' , width : 75 , excludeFromGridMenu : true } ,
1944
+ ] ) ;
1945
+ expect ( control . getAllColumns ( ) ) . toEqual ( columnsMock ) ;
1946
+ expect ( control . getVisibleColumns ( ) ) . toEqual ( columnsMock ) ;
1947
+ } ) ;
1879
1948
} ) ;
1880
1949
} ) ;
0 commit comments