Skip to content

Commit

Permalink
fix(plugins): do not recreate header button plugin after re-render (#706
Browse files Browse the repository at this point in the history
)

* fix(filters): use defaultFilterOperator in range when none provided
- when using 2 dots notation (`2..5`), we should use `defaultFilterRangeOperator` when none is provided and/or isn't a range operator

* fix(plugins): do not recreate header button plugin after re-render
- there is no need to recreate the header button because if we do that then we lose previous ref and onCommand stops working
  • Loading branch information
ghiscoding committed Mar 1, 2021
1 parent 959fc38 commit da62a48
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('ExtensionService', () => {
expect(gridSpy).toHaveBeenCalled();
expect(getAddonSpy).toHaveBeenCalled();
expect(extSpy).toHaveBeenCalled();
expect(output.instance).toEqual(instance);
expect(output!.instance).toEqual(instance);
expect(output).toEqual({ name: ExtensionName.gridMenu, addon: instanceMock, instance: instanceMock, class: extensionGridMenuStub } as ExtensionModel);
});
});
Expand Down Expand Up @@ -259,7 +259,7 @@ describe('ExtensionService', () => {
expect(gridSpy).toHaveBeenCalled();
expect(getAddonSpy).toHaveBeenCalled();
expect(extSpy).toHaveBeenCalled();
expect(output.instance).toEqual(instance);
expect(output!.instance).toEqual(instance);
expect(output).toEqual({ name: ExtensionName.gridMenu, addon: instanceMock, instance: instanceMock, class: extensionGridMenuStub } as ExtensionModel);
});

Expand Down Expand Up @@ -448,7 +448,7 @@ describe('ExtensionService', () => {
});

describe('createExtensionsBeforeGridCreation method', () => {
let instanceMock;
let instanceMock: any;

beforeEach(() => {
instanceMock = { onColumnsChanged: () => { } };
Expand Down Expand Up @@ -703,36 +703,6 @@ describe('ExtensionService', () => {
expect(setColumnsSpy).toHaveBeenCalledWith(columnsMock);
});

it('should re-register the Header Button when enable and method is called with new column definition collection provided as argument', () => {
const instanceMock = { onColumnsChanged: jest.fn() };
const extensionMock = { name: ExtensionName.headerButton, addon: null, instance: null, class: null } as ExtensionModel;
const expectedExtension = { name: ExtensionName.headerButton, instance: instanceMock as unknown, class: null } as ExtensionModel;
const gridOptionsMock = { enableHeaderButton: true } as GridOption;
const columnsMock = [
{ id: 'field1', field: 'field1', nameKey: 'HELLO' },
{ id: 'field2', field: 'field2', nameKey: 'WORLD' }
] as Column[];

jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock);
jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub);
const spyGetExt = jest.spyOn(service, 'getExtensionByName').mockReturnValue(extensionMock);
const spyGmDispose = jest.spyOn(extensionHeaderButtonStub, 'dispose');
const spyGmRegister = jest.spyOn(extensionHeaderButtonStub, 'register').mockReturnValue(instanceMock);
const spyAllCols = jest.spyOn(SharedService.prototype, 'allColumns', 'set');
const setColumnsSpy = jest.spyOn(gridStub, 'setColumns');

service.renderColumnHeaders(columnsMock);

expect(expectedExtension).toEqual(expectedExtension);
expect(spyGetExt).toHaveBeenCalled();
expect(expectedExtension).toEqual(expectedExtension);
expect(spyGetExt).toHaveBeenCalled();
expect(spyGmDispose).toHaveBeenCalled();
expect(spyGmRegister).toHaveBeenCalled();
expect(spyAllCols).toHaveBeenCalledWith(columnsMock);
expect(setColumnsSpy).toHaveBeenCalledWith(columnsMock);
});

it('should re-register the Header Menu when enable and method is called with new column definition collection provided as argument', () => {
const instanceMock = { onColumnsChanged: jest.fn() };
const extensionMock = { name: ExtensionName.headerMenu, addon: null, instance: null, class: null } as ExtensionModel;
Expand Down Expand Up @@ -767,7 +737,7 @@ describe('ExtensionService', () => {

describe('without ngx-translate', () => {
beforeEach(() => {
translate = null;
(translate as any) = null;
service = new ExtensionService(
// extensions
extensionStub as unknown as AutoTooltipExtension,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,6 @@ export class ExtensionService {
this.recreateExternalAddon(this.gridMenuExtension, ExtensionName.gridMenu);
}

// recreate the Header Button when enabled
if (this.sharedService.gridOptions.enableHeaderButton) {
this.recreateExternalAddon(this.headerButtonExtension, ExtensionName.headerButton);
}

// recreate the Header Menu when enabled
if (this.sharedService.gridOptions.enableHeaderMenu) {
this.recreateExternalAddon(this.headerMenuExtension, ExtensionName.headerMenu);
Expand Down

0 comments on commit da62a48

Please sign in to comment.