From 392a50cceb4129119ee5531d8a545f7bc78bc5a8 Mon Sep 17 00:00:00 2001 From: Priscila Moneo Date: Tue, 10 Mar 2026 19:28:50 -0300 Subject: [PATCH] fix: fix pagination issue page not found --- .../form-template-item-list-page.test.js | 77 +++++++++++++++++++ .../form-template-item-list-page.js | 4 +- 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/pages/sponsors-global/form-templates/__tests__/form-template-item-list-page.test.js diff --git a/src/pages/sponsors-global/form-templates/__tests__/form-template-item-list-page.test.js b/src/pages/sponsors-global/form-templates/__tests__/form-template-item-list-page.test.js new file mode 100644 index 000000000..b00feb680 --- /dev/null +++ b/src/pages/sponsors-global/form-templates/__tests__/form-template-item-list-page.test.js @@ -0,0 +1,77 @@ +import React from "react"; +import { waitFor } from "@testing-library/react"; +import FormTemplateItemListPage from "../form-template-item-list-page"; +import { renderWithRedux } from "../../../../utils/test-utils"; +import { getFormTemplateItems } from "../../../../actions/form-template-item-actions"; +import { getFormTemplate } from "../../../../actions/form-template-actions"; +import { DEFAULT_CURRENT_PAGE } from "../../../../utils/constants"; + +jest.mock("../../../../actions/form-template-item-actions", () => ({ + ...jest.requireActual("../../../../actions/form-template-item-actions"), + getFormTemplateItems: jest.fn(() => () => Promise.resolve()) +})); + +jest.mock("../../../../actions/form-template-actions", () => ({ + ...jest.requireActual("../../../../actions/form-template-actions"), + getFormTemplate: jest.fn(() => () => Promise.resolve()) +})); + +describe("FormTemplateItemListPage", () => { + const formTemplateId = 123; + const initialPage = 2; + const perPage = 10; + const order = "name"; + const orderDir = 1; + const hideArchived = false; + const buildInitialState = () => ({ + currentFormTemplateItemListState: { + formTemplateItems: [], + term: "", + order, + orderDir, + currentPage: initialPage, + lastPage: 1, + perPage, + totalFormTemplateItems: 5, + hideArchived + }, + currentFormTemplateState: { + entity: { id: formTemplateId, code: "FT", name: "Form Template" }, + errors: {} + }, + currentFormTemplateItemState: { + entity: {}, + errors: {} + } + }); + + beforeEach(() => { + jest.clearAllMocks(); + }); + + describe("Component", () => { + test("should request page 1 on mount when previous page is 2", async () => { + renderWithRedux( + , + { + initialState: buildInitialState() + } + ); + + await waitFor(() => { + expect(getFormTemplate).toHaveBeenCalledWith(formTemplateId); + expect(getFormTemplateItems).toHaveBeenCalledTimes(1); + expect(getFormTemplateItems).toHaveBeenNthCalledWith( + 1, + formTemplateId, + "", + DEFAULT_CURRENT_PAGE, + perPage, + order, + orderDir, + hideArchived + ); + }); + }); + }); +}); diff --git a/src/pages/sponsors-global/form-templates/form-template-item-list-page.js b/src/pages/sponsors-global/form-templates/form-template-item-list-page.js index 5ff709b1f..ee3287591 100644 --- a/src/pages/sponsors-global/form-templates/form-template-item-list-page.js +++ b/src/pages/sponsors-global/form-templates/form-template-item-list-page.js @@ -1,5 +1,5 @@ /** - * Copyright 2025 OpenStack Foundation + * Copyright 2026 OpenStack Foundation * 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 @@ -80,7 +80,7 @@ const FormTemplateItemListPage = ({ getFormTemplateItems( formTemplateId, term, - currentPage, + DEFAULT_CURRENT_PAGE, perPage, order, orderDir,