mirror of
https://github.com/prymitive/karma
synced 2026-05-05 03:16:51 +00:00
fix(ui): ensure that pagination doesn't set active page to 0
This commit is contained in:
@@ -137,7 +137,7 @@ const Browser = observer(
|
||||
resetIfNeeded(totalItemsCount, maxPerPage) {
|
||||
const totalPages = Math.ceil(totalItemsCount / maxPerPage);
|
||||
if (this.activePage > totalPages) {
|
||||
this.activePage = totalPages;
|
||||
this.activePage = Math.max(1, totalPages);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -203,7 +203,7 @@ describe("<Browser />", () => {
|
||||
expect(tree.find("ManagedSilence")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("resetes pagination to last page on truncation", async () => {
|
||||
it("resets pagination to last page on truncation", async () => {
|
||||
fetch.mockResponseOnce(JSON.stringify(MockSilenceList(11)));
|
||||
const tree = MountedBrowser();
|
||||
const instance = tree.instance();
|
||||
@@ -224,6 +224,14 @@ describe("<Browser />", () => {
|
||||
|
||||
expect(tree.find("ManagedSilence")).toHaveLength(2);
|
||||
expect(instance.pagination.activePage).toBe(2);
|
||||
|
||||
fetch.mockResponseOnce(JSON.stringify([]));
|
||||
instance.onFetch();
|
||||
await expect(instance.dataSource.fetch).resolves.toBeUndefined();
|
||||
tree.update();
|
||||
|
||||
expect(tree.find("ManagedSilence")).toHaveLength(0);
|
||||
expect(instance.pagination.activePage).toBe(1);
|
||||
});
|
||||
|
||||
it("renders error after failed fetch", async () => {
|
||||
|
||||
Reference in New Issue
Block a user