Skip to content

Commit 92ffa3d

Browse files
authored
fix(extension): registerPlugin not implemented correctly (#482)
1 parent a1fe38e commit 92ffa3d

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/app/modules/angular-slickgrid/services/__tests__/extension.service.spec.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const gridStub = {
3030
getColumnIndex: jest.fn(),
3131
getScrollbarDimensions: jest.fn(),
3232
getOptions: jest.fn(),
33+
getPluginByName: jest.fn(),
3334
getColumns: jest.fn(),
3435
setColumns: jest.fn(),
3536
onColumnsReordered: jest.fn(),
@@ -413,7 +414,8 @@ describe('ExtensionService', () => {
413414
const gridOptionsMock = { registerPlugins: [pluginMock] } as GridOption;
414415
const gridSpy = jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub);
415416
const optionSpy = jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock);
416-
const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin').mockReturnValue(instanceMock);
417+
const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin');
418+
jest.spyOn(SharedService.prototype.grid, 'getPluginByName').mockReturnValue(instanceMock);
417419

418420
service.bindDifferentExtensions();
419421
const output = service.getExtensionByName(ExtensionName.noname);
@@ -430,7 +432,8 @@ describe('ExtensionService', () => {
430432
const gridOptionsMock = { registerPlugins: pluginMock } as GridOption;
431433
const gridSpy = jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub);
432434
const optionSpy = jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock);
433-
const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin').mockReturnValue(instanceMock);
435+
const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin');
436+
jest.spyOn(SharedService.prototype.grid, 'getPluginByName').mockReturnValue(instanceMock);
434437

435438
service.bindDifferentExtensions();
436439
const output = service.getExtensionByName(ExtensionName.noname);

src/app/modules/angular-slickgrid/services/extension.service.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,19 @@ export class ExtensionService {
245245

246246
// manually register other plugins
247247
if (this.sharedService.gridOptions.registerPlugins !== undefined) {
248-
if (Array.isArray(this.sharedService.gridOptions.registerPlugins)) {
249-
this.sharedService.gridOptions.registerPlugins.forEach((plugin) => {
250-
const instance = this.sharedService.grid.registerPlugin(plugin);
248+
const grid = this.sharedService.grid;
249+
const gridOptions = this.sharedService.gridOptions;
250+
251+
if (Array.isArray(gridOptions.registerPlugins)) {
252+
gridOptions.registerPlugins.forEach((plugin: any) => {
253+
grid.registerPlugin(plugin);
254+
const instance = grid.getPluginByName(plugin && plugin.name || '');
251255
this._extensionList.push({ name: ExtensionName.noname, class: null, addon: instance, instance });
252256
});
253257
} else {
254-
this.sharedService.grid.registerPlugin(this.sharedService.gridOptions.registerPlugins);
255-
const plugin = this.sharedService.gridOptions.registerPlugins;
256-
const instance = this.sharedService.grid.registerPlugin(plugin);
258+
const plugin = gridOptions.registerPlugins;
259+
grid.registerPlugin(plugin);
260+
const instance = grid.getPluginByName(plugin && plugin.name || '');
257261
this._extensionList.push({ name: ExtensionName.noname, class: null, addon: instance, instance });
258262
}
259263
}

0 commit comments

Comments
 (0)