Skip to content

Commit

Permalink
chore: add missing unit test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Jul 23, 2024
1 parent d26ed6d commit 919fe25
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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"', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -935,8 +935,7 @@ export class SlickVanillaGridBundle<TData = any> {

// 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
Expand Down Expand Up @@ -1121,7 +1120,7 @@ export class SlickVanillaGridBundle<TData = any> {
* 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.');
Expand Down

0 comments on commit 919fe25

Please sign in to comment.