Skip to content

Commit

Permalink
add test to check reading query will result in correct date range
Browse files Browse the repository at this point in the history
  • Loading branch information
angelathe committed Dec 20, 2024
1 parent 1f09869 commit 3c82083
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions containers/ecr-viewer/src/app/tests/HomePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import {
getTotalEcrCount,
listEcrData,
} from "@/app/services/listEcrDataService";
import { convertDateOptionToDateRange } from "@/app/view-data/utils/date-utils";

jest.mock("../services/listEcrDataService");
jest.mock("../components/EcrPaginationWrapper");
jest.mock("../components/LibrarySearch");
jest.mock("../view-data/utils/date-utils.ts");

describe("Home Page", () => {
afterEach(() => {
Expand Down Expand Up @@ -38,3 +40,26 @@ describe("Home Page", () => {
expect(screen.queryByText("Page not found")).not.toBeInTheDocument();
});
});

describe("Reading query params on home page", () => {
it("should call convertDateOptionToDateRange with the correct dateRange from query params", async () => {
process.env.NEXT_PUBLIC_NON_INTEGRATED_VIEWER = "true";
const mockDateRange = "last-7-days";
const searchParams = { dateRange: mockDateRange };
const mockReturnDates = {
startDate: new Date("2024-12-01T00:00:00Z"),
endDate: new Date("2024-12-07T23:59:59Z"),
};

(convertDateOptionToDateRange as jest.Mock).mockReturnValue(
mockReturnDates,
);
const mockData = [{ id: 1, name: "Test Ecr" }];
(listEcrData as jest.Mock).mockResolvedValue(mockData);

render(await HomePage({ searchParams }));

expect(convertDateOptionToDateRange).toHaveBeenCalledWith("last-7-days");
expect(convertDateOptionToDateRange).toHaveReturnedWith(mockReturnDates);
});
});

0 comments on commit 3c82083

Please sign in to comment.