|
| 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