Skip to content

Commit 41375d1

Browse files
committed
Update Architecture.md; Include unit tests for PageLayout; Include id attribute for PageLayout
1 parent df3544a commit 41375d1

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

Architecture.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ frontend/
494494
│ │ │ ├── InitializationForm.test.ts # InitializationForm component testing
495495
│ │ │ ├── Letter.test.ts # Letter component testing
496496
│ │ │ ├── LetterDisclaimer.test.ts # LetterDisclaimer component testing
497+
│ │ │ ├── PageLayout.test.ts # PageLayout component testing
497498
│ │ │ └── MessageWindow.test.ts # MessageWindow component testing
498499
│ │ └── utils/ # Utility function testing
499500
│ │ ├── letterHelper.test.ts # letterHelper testing

frontend/src/layouts/PageLayout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default function PageLayout({ children }: Props) {
1313
className={`flex items-center justify-center pt-16
1414
${isChatPages ? "h-screen" : "sm:pt-32 sm:pb-16"}
1515
`}
16+
id="page-layout"
1617
>
1718
{children}
1819
</div>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
2+
import { render } from "@testing-library/react";
3+
import { describe, it } from "vitest";
4+
import HousingContextProvider from "../../contexts/HousingContext";
5+
import { MemoryRouter } from "react-router-dom";
6+
7+
beforeAll(() => {
8+
if (!("scrollTo" in HTMLElement.prototype)) {
9+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
10+
// @ts-expect-error
11+
HTMLElement.prototype.scrollTo = function () {};
12+
}
13+
HTMLDialogElement.prototype.showModal = vi.fn();
14+
HTMLDialogElement.prototype.close = vi.fn();
15+
});
16+
17+
const renderLayout = async (path: string) => {
18+
const { default: Layout } = await import("../../layouts/PageLayout");
19+
const queryClient = new QueryClient();
20+
return render(
21+
<QueryClientProvider client={queryClient}>
22+
<HousingContextProvider>
23+
<MemoryRouter initialEntries={[path]}>
24+
<Layout>
25+
<div />
26+
</Layout>
27+
</MemoryRouter>
28+
</HousingContextProvider>
29+
</QueryClientProvider>
30+
);
31+
};
32+
33+
describe("Page Layout component", () => {
34+
const pageSetup = async (path: string) => {
35+
const { container } = await renderLayout(path);
36+
return container.querySelector("#page-layout");
37+
};
38+
39+
it("returns h-screen when path is index", async () => {
40+
const pageLayout = await pageSetup("/");
41+
42+
expect(pageLayout).toHaveClass("h-screen");
43+
expect(pageLayout).not.toHaveClass("sm:pt-32", "sm:pb-16");
44+
});
45+
46+
it("returns h-screen when path starts with /letter", async () => {
47+
const pageLayout = await pageSetup("/letter/oregon-law-help");
48+
49+
expect(pageLayout).toHaveClass("h-screen");
50+
expect(pageLayout).not.toHaveClass("sm:pt-32", "sm:pb-16");
51+
});
52+
53+
it("returns h-screen when path starts with /letter", async () => {
54+
const pageLayout = await pageSetup("/about");
55+
56+
expect(pageLayout).not.toHaveClass("h-screen");
57+
expect(pageLayout).toHaveClass("sm:pt-32", "sm:pb-16");
58+
});
59+
});

0 commit comments

Comments
 (0)