This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
forked from HHS/simpler-grants-gov
-
Notifications
You must be signed in to change notification settings - Fork 0
[Issue #174] Hide pagination component if no results are found #175
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7ac0d2a
initial commit
btabaska 22bc637
finishing tests
btabaska 52bff05
Merge branch 'main' into btabaska/174-hide-pagination-when-no-results
btabaska a1e2198
merge conflict fixing
btabaska f1195d9
typing issue
btabaska 8ce9d40
typing issue
btabaska 82e9a40
typing issue
btabaska 93bf41d
typing issue
btabaska ef254a9
fixing formatting
btabaska d06a241
removing log statements
btabaska File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -35,24 +35,28 @@ export default function SearchPagination({ | |||
const pages = total || Number(totalPages); | ||||
|
||||
const updatePage = (page: number) => { | ||||
console.log("here"); | ||||
updateTotalPages(String(total)); | ||||
updateTotalResults(totalResults); | ||||
updateQueryParams(String(page), "page", query, scroll); | ||||
console.log("here2"); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one too
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great catch, created. #181 to add no-console to eslint |
||||
}; | ||||
|
||||
return ( | ||||
<div className={`grants-pagination ${loading ? "disabled" : ""}`}> | ||||
<Pagination | ||||
pathname="/search" | ||||
totalPages={pages} | ||||
currentPage={page} | ||||
maxSlots={MAX_SLOTS} | ||||
onClickNext={() => updatePage(page + 1)} | ||||
onClickPrevious={() => updatePage(page > 1 ? page - 1 : 0)} | ||||
onClickPageNumber={(event: React.MouseEvent, page: number) => | ||||
updatePage(page) | ||||
} | ||||
/> | ||||
{pages > 0 && ( | ||||
<Pagination | ||||
pathname="/search" | ||||
totalPages={pages} | ||||
currentPage={page} | ||||
maxSlots={MAX_SLOTS} | ||||
onClickNext={() => updatePage(page + 1)} | ||||
onClickPrevious={() => updatePage(page > 1 ? page - 1 : 0)} | ||||
onClickPageNumber={(event: React.MouseEvent, page: number) => | ||||
updatePage(page) | ||||
} | ||||
/> | ||||
)} | ||||
</div> | ||||
); | ||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
/* eslint-disable jest/no-commented-out-tests */ | ||
/* eslint-disable testing-library/no-node-access */ | ||
import "@testing-library/jest-dom/extend-expect"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
import { render } from "tests/react-utils"; | ||
import React from "react"; | ||
import SearchPagination from "src/components/search/SearchPagination"; | ||
|
||
const mockUpdateQueryParams = jest.fn(); | ||
|
||
// Mock the useSearchParamUpdater hook | ||
jest.mock("src/hooks/useSearchParamUpdater", () => ({ | ||
useSearchParamUpdater: () => ({ | ||
updateQueryParams: mockUpdateQueryParams, | ||
updateQueryParams: jest.fn(), | ||
}), | ||
})); | ||
|
||
// import SearchPagination, { | ||
// PaginationPosition, | ||
// } from "../../../src/components/search/SearchPagination"; | ||
|
||
// import { render } from "@testing-library/react"; | ||
beforeEach(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👏🏿 *for removing commented out code |
||
jest.clearAllMocks(); | ||
}); | ||
|
||
// TODO (Issue #1936): Uncomment tests after React 19 upgrade | ||
describe("SearchPagination", () => { | ||
it("pass test", () => { | ||
expect(1).toBe(1); | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("should not have basic accessibility issues", async () => { | ||
const { container } = render(<SearchPagination page={1} query={"test"} />); | ||
|
||
|
@@ -36,73 +33,14 @@ describe("SearchPagination", () => { | |
}); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
it("Renders Pagination component when pages > 0", () => { | ||
render(<SearchPagination page={1} query={"test"} total={10} />); | ||
|
||
// it("renders hidden input when showHiddenInput is true", () => { | ||
// render( | ||
// <SearchPagination | ||
// showHiddenInput={true} | ||
// totalPages={totalPages} | ||
// page={page} | ||
// handlePageChange={mockHandlePageChange} | ||
// position={PaginationPosition.Top} | ||
// />, | ||
// ); | ||
|
||
// const hiddenInput = screen.getByTestId("hiddenCurrentPage"); | ||
// expect(hiddenInput).toHaveValue("1"); | ||
// }); | ||
|
||
// it("does not render hidden input when showHiddenInput is false", () => { | ||
// render( | ||
// <SearchPagination | ||
// showHiddenInput={false} | ||
// totalPages={totalPages} | ||
// page={page} | ||
// handlePageChange={mockHandlePageChange} | ||
// position={PaginationPosition.Top} | ||
// />, | ||
// ); | ||
// expect(screen.queryByTestId("hiddenCurrentPage")).not.toBeInTheDocument(); | ||
// }); | ||
|
||
// it("calls handlePageChange with next page on next button click", () => { | ||
// render( | ||
// <SearchPagination | ||
// showHiddenInput={true} | ||
// totalPages={totalPages} | ||
// page={page} | ||
// handlePageChange={mockHandlePageChange} | ||
// position={PaginationPosition.Top} | ||
// />, | ||
// ); | ||
// fireEvent.click(screen.getByLabelText("Next page")); | ||
// expect(mockHandlePageChange).toHaveBeenCalledWith(page + 1); | ||
// }); | ||
|
||
// it("calls handlePageChange with previous page on previous button click", () => { | ||
// render( | ||
// <SearchPagination | ||
// showHiddenInput={true} | ||
// totalPages={totalPages} | ||
// page={2} // Set to second page to test going back to first page | ||
// handlePageChange={mockHandlePageChange} | ||
// position={PaginationPosition.Top} | ||
// />, | ||
// ); | ||
// fireEvent.click(screen.getByLabelText("Previous page")); | ||
// expect(mockHandlePageChange).toHaveBeenCalledWith(1); | ||
// }); | ||
expect(screen.getByRole("navigation")).toBeInTheDocument(); | ||
}); | ||
it("Does not render Pagination component when pages <= 0", () => { | ||
render(<SearchPagination page={1} query={"test"} total={0} />); | ||
|
||
// it("returns null when searchResultsLength is less than 1", () => { | ||
// const { container } = render( | ||
// <SearchPagination | ||
// showHiddenInput={true} | ||
// page={page} | ||
// handlePageChange={mockHandlePageChange} | ||
// searchResultsLength={0} // No results, pagination should be hidden | ||
// position={PaginationPosition.Top} | ||
// />, | ||
// ); | ||
// expect(container).toBeEmptyDOMElement(); | ||
// }); | ||
expect(screen.queryByRole("navigation")).not.toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this got left here:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch. This should have been caught by linting. Filing a ticket to add no-console-statement to Eslint config