Skip to content
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 @@ -41,6 +41,8 @@ export class PaginationController {
updatePageSize(pageSize: number) {
this.showAll = false;
this.updatePageSizeVals(pageSize);
// Reset to the first page when the page size changes so we never request a page past the last one
this.updatePage(1);
}

//This route taken to minimize disruption of all the pages that utilize BackendPaginationController
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/models/paginationController.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {PaginationController} from "@/breeding-insight/model/view_models/PaginationController";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't typically been adding frontend tests but fine to add

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for confirming! I added the test to cover the pagination reset and prevent regression.


describe('PaginationController page size changes', () => {

it('Resets to the first page when page size changes', () => {
const controller = new PaginationController(10, 20, 10, 200);
controller.updatePageSize(200);
expect(controller.currentPage).toEqual(1);
expect(controller.pageSize).toEqual(200);
expect(controller.getPaginationSelections().page).toEqual(1);
});
});
Loading