From 9cc7c82f095ab7a9ad99a52f5179cc54c6744597 Mon Sep 17 00:00:00 2001 From: Vishal Baraiya <142961593+mr-baraiya@users.noreply.github.com> Date: Fri, 13 Mar 2026 18:53:44 +0000 Subject: [PATCH 1/5] fix(Page): handle failed dynamic content loading safely test(Page): add unit test for content.__error rendering and fix test setup --- src/components/Page/Page.jsx | 16 +++++++-- src/components/Page/__tests__/Page.test.jsx | 40 +++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/components/Page/__tests__/Page.test.jsx diff --git a/src/components/Page/Page.jsx b/src/components/Page/Page.jsx index 997b0ffae849..543fb829c016 100644 --- a/src/components/Page/Page.jsx +++ b/src/components/Page/Page.jsx @@ -30,7 +30,9 @@ export default function Page(props) { ); const content = isDynamicContent ? dynamicContent - : props.content.default || props.content; + : props.content && props.content.default !== undefined + ? props.content.default + : props.content; const [contentLoaded, setContentLoaded] = useState(!isDynamicContent); @@ -41,7 +43,13 @@ export default function Page(props) { setContent(() => mod.default || mod); setContentLoaded(true); }) - .catch(() => setContent("Error loading content.")); + .catch(() => { + setContent({ + __error: true, + message: "Failed to load page content.", + }); + setContentLoaded(true); + }); } }, [props.content]); @@ -94,6 +102,10 @@ export default function Page(props) { if (typeof content === "function") { contentRender = content({}).props.children; + } else if (content && content.__error) { + contentRender = ( +
{content.message}
+ ); } else { contentRender = (
() =>
); +jest.mock("../../PageLinks/PageLinks.jsx", () => () =>
); + +// Mock react-router hook used inside Page +jest.mock("react-router", () => ({ + ...jest.requireActual("react-router"), + useLocation: () => ({ pathname: "/test", hash: "" }), +})); + +// Mock scrollTo (jsdom doesn't support it) +window.scrollTo = jest.fn(); + +describe("Page component", () => { + it("renders error message when content.__error exists", async () => { + const content = { + __error: true, + message: "Failed to load content", + }; + + render( + + + , + ); + + const errorElement = await screen.findByText(/failed to load content/i); + expect(errorElement).toBeInTheDocument(); + }); +}); From ee00510f38f1c3df4761555ddeb55b314ba6f63d Mon Sep 17 00:00:00 2001 From: Vishal Baraiya <142961593+mr-baraiya@users.noreply.github.com> Date: Tue, 17 Mar 2026 18:15:25 +0000 Subject: [PATCH 2/5] fix(test): correct router import and align error message --- src/components/Page/__tests__/Page.test.jsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/Page/__tests__/Page.test.jsx b/src/components/Page/__tests__/Page.test.jsx index de38ad3edc55..132a262910c2 100644 --- a/src/components/Page/__tests__/Page.test.jsx +++ b/src/components/Page/__tests__/Page.test.jsx @@ -5,7 +5,7 @@ import React from "react"; import { render, screen } from "@testing-library/react"; import "@testing-library/jest-dom"; -import { MemoryRouter } from "react-router"; +import { MemoryRouter } from "react-router-dom"; import Page from "../Page"; // Mock components that cause unrelated failures @@ -13,8 +13,8 @@ jest.mock("../../Contributors/Contributors.jsx", () => () =>
); jest.mock("../../PageLinks/PageLinks.jsx", () => () =>
); // Mock react-router hook used inside Page -jest.mock("react-router", () => ({ - ...jest.requireActual("react-router"), +jest.mock("react-router-dom", () => ({ + ...jest.requireActual("react-router-dom"), useLocation: () => ({ pathname: "/test", hash: "" }), })); @@ -25,7 +25,7 @@ describe("Page component", () => { it("renders error message when content.__error exists", async () => { const content = { __error: true, - message: "Failed to load content", + message: "Failed to load page content.", }; render( @@ -34,7 +34,9 @@ describe("Page component", () => { , ); - const errorElement = await screen.findByText(/failed to load content/i); + const errorElement = await screen.findByText( + /failed to load page content/i, + ); expect(errorElement).toBeInTheDocument(); }); }); From 3defed00dcb7cf69ee62f45e70f3091811b3406e Mon Sep 17 00:00:00 2001 From: Vishal Baraiya <142961593+mr-baraiya@users.noreply.github.com> Date: Tue, 17 Mar 2026 18:18:35 +0000 Subject: [PATCH 3/5] fix(test): stabilize test for CI (router mock + scrollTo) --- src/components/Page/__tests__/Page.test.jsx | 27 ++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/components/Page/__tests__/Page.test.jsx b/src/components/Page/__tests__/Page.test.jsx index 132a262910c2..e8a089c049cb 100644 --- a/src/components/Page/__tests__/Page.test.jsx +++ b/src/components/Page/__tests__/Page.test.jsx @@ -12,14 +12,20 @@ import Page from "../Page"; jest.mock("../../Contributors/Contributors.jsx", () => () =>
); jest.mock("../../PageLinks/PageLinks.jsx", () => () =>
); -// Mock react-router hook used inside Page -jest.mock("react-router-dom", () => ({ - ...jest.requireActual("react-router-dom"), - useLocation: () => ({ pathname: "/test", hash: "" }), -})); +// Stable mock for react-router-dom (CI safe) +jest.mock("react-router-dom", () => { + const actual = jest.requireActual("react-router-dom"); + return { + ...actual, + useLocation: () => ({ pathname: "/test", hash: "" }), + }; +}); -// Mock scrollTo (jsdom doesn't support it) -window.scrollTo = jest.fn(); +// Mock scrollTo properly (CI safe) +Object.defineProperty(window, "scrollTo", { + value: jest.fn(), + writable: true, +}); describe("Page component", () => { it("renders error message when content.__error exists", async () => { @@ -34,9 +40,8 @@ describe("Page component", () => { , ); - const errorElement = await screen.findByText( - /failed to load page content/i, - ); - expect(errorElement).toBeInTheDocument(); + expect( + await screen.findByText(/failed to load page content/i), + ).toBeInTheDocument(); }); }); From b1344092ac14ab4af0850257ebdd54e58eef1bff Mon Sep 17 00:00:00 2001 From: Vishal Baraiya <142961593+mr-baraiya@users.noreply.github.com> Date: Tue, 17 Mar 2026 18:21:48 +0000 Subject: [PATCH 4/5] fix(test): remove jest-dom dependency and use native assertion --- src/components/Page/__tests__/Page.test.jsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/components/Page/__tests__/Page.test.jsx b/src/components/Page/__tests__/Page.test.jsx index e8a089c049cb..1035bf3dcea9 100644 --- a/src/components/Page/__tests__/Page.test.jsx +++ b/src/components/Page/__tests__/Page.test.jsx @@ -4,15 +4,12 @@ import React from "react"; import { render, screen } from "@testing-library/react"; -import "@testing-library/jest-dom"; import { MemoryRouter } from "react-router-dom"; import Page from "../Page"; -// Mock components that cause unrelated failures jest.mock("../../Contributors/Contributors.jsx", () => () =>
); jest.mock("../../PageLinks/PageLinks.jsx", () => () =>
); -// Stable mock for react-router-dom (CI safe) jest.mock("react-router-dom", () => { const actual = jest.requireActual("react-router-dom"); return { @@ -21,7 +18,6 @@ jest.mock("react-router-dom", () => { }; }); -// Mock scrollTo properly (CI safe) Object.defineProperty(window, "scrollTo", { value: jest.fn(), writable: true, @@ -40,8 +36,9 @@ describe("Page component", () => { , ); - expect( - await screen.findByText(/failed to load page content/i), - ).toBeInTheDocument(); + const errorElement = await screen.findByText( + /failed to load page content/i, + ); + expect(errorElement).toBeTruthy(); }); }); From d86027ef006d7d6aa1a25347c3148e5c0d48de9b Mon Sep 17 00:00:00 2001 From: Vishal Baraiya <142961593+mr-baraiya@users.noreply.github.com> Date: Tue, 17 Mar 2026 18:24:41 +0000 Subject: [PATCH 5/5] fix(test): resolve eslint issues in Page test --- src/components/Page/__tests__/Page.test.jsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/Page/__tests__/Page.test.jsx b/src/components/Page/__tests__/Page.test.jsx index 1035bf3dcea9..aec6335f4369 100644 --- a/src/components/Page/__tests__/Page.test.jsx +++ b/src/components/Page/__tests__/Page.test.jsx @@ -2,13 +2,19 @@ * @jest-environment jsdom */ -import React from "react"; import { render, screen } from "@testing-library/react"; import { MemoryRouter } from "react-router-dom"; -import Page from "../Page"; +import Page from "../Page.jsx"; -jest.mock("../../Contributors/Contributors.jsx", () => () =>
); -jest.mock("../../PageLinks/PageLinks.jsx", () => () =>
); +jest.mock("../../Contributors/Contributors.jsx", () => { + const MockContributors = () =>
; + return MockContributors; +}); + +jest.mock("../../PageLinks/PageLinks.jsx", () => { + const MockPageLinks = () =>
; + return MockPageLinks; +}); jest.mock("react-router-dom", () => { const actual = jest.requireActual("react-router-dom");