diff --git a/src/pages/sponsors/__tests__/sponsor-list-page.test.js b/src/pages/sponsors/__tests__/sponsor-list-page.test.js new file mode 100644 index 000000000..a09a49d07 --- /dev/null +++ b/src/pages/sponsors/__tests__/sponsor-list-page.test.js @@ -0,0 +1,63 @@ +import React from "react"; +import { screen } from "@testing-library/react"; +import SponsorListPage from "../sponsor-list-page"; + +import { renderWithRedux } from "../../../utils/test-utils"; +import { getSponsors } from "../../../actions/sponsor-actions"; + +jest.mock("../../../actions/sponsor-actions", () => ({ + ...jest.requireActual("../../../actions/sponsor-actions"), + getSponsors: jest.fn(() => ({ type: "MOCK_ACTION" })) +})); + +describe("SponsorListPage", () => { + describe("Component", () => { + it("should preserve and apply the search term when navigating back to the list", () => { + const initialState = { + loggedUserState: { + member: { canAddSponsors: () => true, canDeleteSponsors: () => true } + }, + currentSummitState: { currentSummit: { id: 1 } }, + currentSponsorListState: { + sponsors: [ + { + id: 1, + company_name: "FNTECH", + sponsorships: [], + documents: [], + forms: [], + purchases: [], + pages: [], + order: 1 + } + ], + totalSponsors: 1, + perPage: 10, + currentPage: 1, + term: "FNTECH", + order: "order", + orderDir: 1 + }, + currentSummitSponsorshipListState: { sponsorships: [] } + }; + + renderWithRedux(, { initialState }); + + // The input should have the search term value + const input = screen.getByPlaceholderText(/search_inventory_items/i); + expect(input.value).toBe("FNTECH"); + // Only FNTECH should be visible in the list + expect(screen.getByText("FNTECH")).toBeInTheDocument(); + expect(screen.queryByText("OTHER")).not.toBeInTheDocument(); + + // Should call getSponsors with the preserved term and params, including currentPage from state + expect(getSponsors).toHaveBeenCalledWith( + "FNTECH", + initialState.currentSponsorListState.currentPage, // currentPage from state + 10, // perPage + "order", + 1 + ); + }); + }); +}); diff --git a/src/pages/sponsors/sponsor-list-page.js b/src/pages/sponsors/sponsor-list-page.js index 10bc028b7..586fe484e 100644 --- a/src/pages/sponsors/sponsor-list-page.js +++ b/src/pages/sponsors/sponsor-list-page.js @@ -62,9 +62,9 @@ const SponsorListPage = ({ useEffect(() => { if (currentSummit) { - getSponsors(); + getSponsors(term, currentPage, perPage, order, orderDir); } - }, [currentSummit]); + }, [currentSummit, term, perPage, order, orderDir, currentPage]); const handleSearchDebounced = useCallback( _.debounce((term) => {