Skip to content

Commit

Permalink
fix: merge default user preferences with stored (#2912)
Browse files Browse the repository at this point in the history
* fix: merge default user preferences with stored

* fix: merging, add test
  • Loading branch information
mcmcgrath13 authored Nov 15, 2024
1 parent 4beb6db commit 39be57b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const EcrPaginationWrapper = ({
useEffect(() => {
const userPreferencesString = localStorage.getItem("userPreferences");
if (userPreferencesString) {
setUserPreferences(JSON.parse(userPreferencesString));
const storedPrefs = JSON.parse(userPreferencesString);
setUserPreferences({ ...defaultPreferences, ...storedPrefs });
}
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ describe("Pagination for EcrPaginationWrapper", () => {
expect(mockPush).toHaveBeenLastCalledWith("?itemsPerPage=50&page=1");
});

it("should load 50 items per page if 50 was previously set and pages wasn't", () => {
const spyLocalStorage = jest.spyOn(Storage.prototype, "getItem");
spyLocalStorage.mockImplementationOnce(() =>
JSON.stringify({ itemsPerPage: 50 }),
);
render(
<EcrPaginationWrapper totalCount={100}>
<br />
</EcrPaginationWrapper>,
);

expect(screen.getByText("Showing 1-50 of 100 eCRs")).toBeInTheDocument();
expect(mockPush).toHaveBeenLastCalledWith("?itemsPerPage=50&page=1");
});

it("should display 51-51 on third page", async () => {
mockSearchParams.set("page", "3");
render(
Expand Down

0 comments on commit 39be57b

Please sign in to comment.