From 919fe254c885acd174febf4a1af206c6f8603ae7 Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Tue, 23 Jul 2024 00:26:44 -0400 Subject: [PATCH] chore: add missing unit test coverage --- .../src/examples/example26.ts | 1 - .../__tests__/slick-vanilla-grid.spec.ts | 25 +++++++++++++++++-- .../components/slick-vanilla-grid-bundle.ts | 5 ++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/examples/vite-demo-vanilla-bundle/src/examples/example26.ts b/examples/vite-demo-vanilla-bundle/src/examples/example26.ts index 175599f14..070a6df77 100644 --- a/examples/vite-demo-vanilla-bundle/src/examples/example26.ts +++ b/examples/vite-demo-vanilla-bundle/src/examples/example26.ts @@ -168,7 +168,6 @@ export default class Example26 { } getCustomerCallback(data) { - console.log('getCustomerCallback', data); // totalItems property needs to be filled for pagination to work correctly // however we need to force Aurelia to do a dirty check, doing a clone object will do just that const totalItemCount: number = data['@odata.count']; diff --git a/packages/vanilla-bundle/src/components/__tests__/slick-vanilla-grid.spec.ts b/packages/vanilla-bundle/src/components/__tests__/slick-vanilla-grid.spec.ts index 8c0373caf..62bba80ac 100644 --- a/packages/vanilla-bundle/src/components/__tests__/slick-vanilla-grid.spec.ts +++ b/packages/vanilla-bundle/src/components/__tests__/slick-vanilla-grid.spec.ts @@ -1388,7 +1388,6 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', () }); it('should call "onScrollEnd" when defined and call backend util setInfiniteScrollBottomHit(true) when we still have more pages in the dataset', (done) => { - component.paginationService.goToNextPage; mockGraphqlService.options = { datasetName: 'users', infiniteScroll: true }; const backendServiceApi = { service: mockGraphqlService, @@ -1412,7 +1411,6 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', () }); it('should call "onScrollEnd" when defined and call backend util setInfiniteScrollBottomHit(false) when we no longer have more pages', (done) => { - component.paginationService.goToNextPage; mockGraphqlService.options = { datasetName: 'users', infiniteScroll: true }; const backendServiceApi = { service: mockGraphqlService, @@ -1434,6 +1432,29 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', () done(); }); }); + + it('should throw an error if we try to set a "presets.pagination" with Infinite Scroll', () => { + const consoleSpy = jest.spyOn(console, 'warn').mockReturnValue(); + mockGraphqlService.options = { datasetName: 'users', infiniteScroll: true }; + const backendServiceApi = { + service: mockGraphqlService, + process: jest.fn(), + }; + + gridOptions = { + enablePagination: true, + backendServiceApi, + presets: { pagination: { pageNumber: 2 } }, + pagination: { pageSizes: [10, 20], pageSize: 10 } + } as unknown as GridOption; + jest.spyOn(component.slickGrid!, 'getOptions').mockReturnValue(gridOptions); + component.gridOptions = gridOptions; + + component.initialization(divContainer, slickEventHandler); + component.refreshGridData([]); + + expect(consoleSpy).toHaveBeenCalledWith('[Slickgrid-Universal] `presets.pagination` is not supported with Infinite Scroll, reverting to first page.'); + }); }); describe('bindDifferentHooks private method called by "attached"', () => { diff --git a/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts b/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts index 0af960da1..75ca2b7e7 100644 --- a/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts +++ b/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts @@ -935,8 +935,7 @@ export class SlickVanillaGridBundle { // when user enables Infinite Scroll if (backendApi.service.options?.infiniteScroll) { - const gridOptions = this.slickGrid!.getOptions(); - gridOptions.backendServiceApi!.onScrollEnd = () => { + this.slickGrid!.getOptions().backendServiceApi!.onScrollEnd = () => { this.backendUtilityService.setInfiniteScrollBottomHit(true); // even if we're not showing pagination, we still use pagination service behind the scene @@ -1121,7 +1120,7 @@ export class SlickVanillaGridBundle { * Check if there's any Pagination Presets defined in the Grid Options, * if there are then load them in the paginationOptions object */ - setPaginationOptionsWhenPresetDefined(gridOptions: GridOption, paginationOptions: Pagination): Pagination { + protected setPaginationOptionsWhenPresetDefined(gridOptions: GridOption, paginationOptions: Pagination): Pagination { if (gridOptions.presets?.pagination && paginationOptions && !this._isPaginationInitialized) { if (this.hasInfiniteScroll()) { console.warn('[Slickgrid-Universal] `presets.pagination` is not supported with Infinite Scroll, reverting to first page.');