Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ describe('contextMenuExtension', () => {
describe('adding Context Menu Command Items', () => {
const commandItemsMock = [{
iconCssClass: 'fa fa-question-circle',
title: 'Help',
titleKey: 'HELP',
disabled: false,
command: 'help',
Expand All @@ -560,7 +561,6 @@ describe('contextMenuExtension', () => {

jest.spyOn(SharedService.prototype, 'dataView', 'get').mockReturnValue(dataViewStub);
jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub);
jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock);
jest.spyOn(SharedService.prototype, 'allColumns', 'get').mockReturnValue(columnsMock);
jest.spyOn(SharedService.prototype, 'visibleColumns', 'get').mockReturnValue(columnsMock);
jest.spyOn(SharedService.prototype, 'columnDefinitions', 'get').mockReturnValue(columnsMock);
Expand All @@ -571,7 +571,30 @@ describe('contextMenuExtension', () => {
extension.dispose();
});

it('should have user Context Menu Command items', () => {
it('should have user Context Menu Command items when "enableTranslate" is disabled', () => {
const copyGridOptionsMock = {
...gridOptionsMock, enableTranslate: false, enableExport: true,
contextMenu: {
commandItems: commandItemsMock,
hideCopyCellValueCommand: true,
hideExportCsvCommand: false,
hideExportExcelCommand: true,
hideExportTextDelimitedCommand: true,
hideClearAllGrouping: true,
hideCollapseAllGroups: true,
hideExpandAllGroups: true,
}
} as GridOption;
jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(copyGridOptionsMock);
extension.register();
expect(SharedService.prototype.gridOptions.contextMenu.commandItems).toEqual([
{ action: expect.anything(), command: 'export-csv', disabled: false, iconCssClass: 'fa fa-download', positionOrder: 51, title: 'Export in CSV format' },
// { action: expect.anything(), command: 'export-excel', disabled: false, iconCssClass: 'fa fa-file-excel-o text-success', positionOrder: 54, title: 'Exporter vers Excel' },
{ command: 'help', disabled: false, iconCssClass: 'fa fa-question-circle', positionOrder: 99, title: 'Help', titleKey: 'HELP' },
]);
});

it('should have user Context Menu Command items when "enableTranslate" is active', () => {
extension.register();
expect(SharedService.prototype.gridOptions.contextMenu.commandItems).toEqual([
{ action: expect.anything(), command: 'export-csv', disabled: false, iconCssClass: 'fa fa-download', positionOrder: 51, title: 'Exporter en format CSV' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ export class ContextMenuExtension implements Extension {

// dynamically import the SlickGrid plugin (addon) with RequireJS
this.extensionUtility.loadExtensionDynamically(ExtensionName.contextMenu);

// merge the original commands with the built-in internal commands
const originalCommandItems = this._userOriginalContextMenu && Array.isArray(this._userOriginalContextMenu.commandItems) ? this._userOriginalContextMenu.commandItems : [];
contextMenu.commandItems = [...originalCommandItems, ...this.addMenuCustomCommands(originalCommandItems)];
this.sharedService.gridOptions.contextMenu = { ...contextMenu };

// sort all menu items by their position order when defined
contextMenu.commandItems = this.addMenuCustomCommands([]);
this.extensionUtility.sortItems(contextMenu.commandItems || [], 'positionOrder');
this.extensionUtility.sortItems(contextMenu.optionItems || [], 'positionOrder');

Expand Down