|
| 1 | +import "@testing-library/jest-dom" |
| 2 | +import {render, screen} from "@testing-library/react" |
| 3 | +import {BrowserRouter} from "react-router-dom" |
| 4 | +import React from "react" |
| 5 | +import App from "@/App" |
| 6 | + |
| 7 | +// Mock all the context providers |
| 8 | +jest.mock("@/context/AuthProvider", () => ({ |
| 9 | + AuthProvider: ({children}: {children: React.ReactNode}) => <div>{children}</div> |
| 10 | +})) |
| 11 | + |
| 12 | +jest.mock("@/context/AccessProvider", () => ({ |
| 13 | + AccessProvider: ({children}: {children: React.ReactNode}) => <div>{children}</div> |
| 14 | +})) |
| 15 | + |
| 16 | +jest.mock("@/context/SearchProvider", () => ({ |
| 17 | + SearchProvider: ({children}: {children: React.ReactNode}) => <div>{children}</div> |
| 18 | +})) |
| 19 | + |
| 20 | +jest.mock("@/context/NavigationProvider", () => ({ |
| 21 | + NavigationProvider: ({children}: {children: React.ReactNode}) => <div>{children}</div> |
| 22 | +})) |
| 23 | + |
| 24 | +jest.mock("@/context/PatientDetailsProvider", () => ({ |
| 25 | + PatientDetailsProvider: ({children}: {children: React.ReactNode}) => <div>{children}</div> |
| 26 | +})) |
| 27 | + |
| 28 | +jest.mock("@/context/PrescriptionInformationProvider", () => ({ |
| 29 | + PrescriptionInformationProvider: ({children}: {children: React.ReactNode}) => <div>{children}</div> |
| 30 | +})) |
| 31 | + |
| 32 | +// Mock Layout component |
| 33 | +jest.mock("@/Layout", () => { |
| 34 | + return function MockLayout({children}: {children: React.ReactNode}) { |
| 35 | + return <div data-testid="layout">{children}</div> |
| 36 | + } |
| 37 | +}) |
| 38 | + |
| 39 | +// Mock all the page components |
| 40 | +jest.mock("@/pages/LoginPage", () => () => <div>Login Page</div>) |
| 41 | +jest.mock("@/pages/LogoutPage", () => () => <div>Logout Page</div>) |
| 42 | +jest.mock("@/pages/SelectYourRolePage", () => () => <div>Select Your Role</div>) |
| 43 | +jest.mock("@/pages/ChangeRolePage", () => () => <div>Change Role</div>) |
| 44 | +jest.mock( |
| 45 | + "@/pages/SearchPrescriptionPage", |
| 46 | + () => () => <div>Search Prescription</div> |
| 47 | +) |
| 48 | +jest.mock("@/pages/YourSelectedRolePage", () => () => <div>Your Selected Role</div>) |
| 49 | +jest.mock("@/pages/NotFoundPage", () => () => <div>Not Found</div>) |
| 50 | +jest.mock("@/pages/PrescriptionListPage", () => () => <div>Prescription List</div>) |
| 51 | +jest.mock( |
| 52 | + "@/pages/PrescriptionDetailsPage", |
| 53 | + () => () => <div>Prescription Details</div> |
| 54 | +) |
| 55 | +jest.mock("@/pages/CookiePolicyPage", () => () => <div>Cookie Policy</div>) |
| 56 | +jest.mock("@/pages/CookieSettingsPage", () => () => <div>Cookie Settings</div>) |
| 57 | +jest.mock( |
| 58 | + "@/pages/BasicDetailsSearchResultsPage", |
| 59 | + () => () => <div>Search Results</div> |
| 60 | +) |
| 61 | +jest.mock("@/pages/PrivacyNoticePage", () => () => <div>Privacy Notice</div>) |
| 62 | +jest.mock("@/pages/SessionSelection", () => () => <div>Session Selection</div>) |
| 63 | +jest.mock("@/pages/SessionLoggedOut", () => () => <div>Session Logged Out</div>) |
| 64 | + |
| 65 | +// Mock EPSCookieBanner |
| 66 | +jest.mock("@/components/EPSCookieBanner", () => () => <div>Cookie Banner</div>) |
| 67 | + |
| 68 | +describe("App", () => { |
| 69 | + it("renders the skip link for regular pages", () => { |
| 70 | + render( |
| 71 | + <BrowserRouter> |
| 72 | + <App /> |
| 73 | + </BrowserRouter> |
| 74 | + ) |
| 75 | + |
| 76 | + const skipLink = screen.getByTestId("eps_header_skipLink") |
| 77 | + expect(skipLink).toBeInTheDocument() |
| 78 | + expect(skipLink).toHaveAttribute("href", "#main-content") |
| 79 | + expect(skipLink).toHaveTextContent("Skip to main content") |
| 80 | + expect(skipLink).toHaveClass("nhsuk-skip-link") |
| 81 | + }) |
| 82 | +}) |
0 commit comments