|
| 1 | +import { LoadingPageComponent } from "@/components/LoadingPageComponent"; |
| 2 | +import { IsAuthenticated } from "@/lib/auth/AuthContext"; |
| 3 | +import { withAuth } from "@/test/helpers/helpers-renderers"; |
| 4 | +import { getMergedConfig } from "@businessnjgovnavigator/shared/contexts"; |
| 5 | +import { render, screen } from "@testing-library/react"; |
| 6 | + |
| 7 | +const Config = getMergedConfig(); |
| 8 | + |
| 9 | +jest.mock("next/compat/router", () => ({ useRouter: jest.fn() })); |
| 10 | + |
| 11 | +describe("LoadingPageComponent", () => { |
| 12 | + describe("when there are no errors", () => { |
| 13 | + it("shows only the loading indicator", () => { |
| 14 | + render( |
| 15 | + withAuth(<LoadingPageComponent hasError={false} />, { |
| 16 | + isAuthenticated: IsAuthenticated.TRUE, |
| 17 | + }), |
| 18 | + ); |
| 19 | + |
| 20 | + expect(screen.queryByText(Config.loginSupportPage.havingTrouble)).not.toBeInTheDocument(); |
| 21 | + expect(screen.queryByText(Config.loginSupportPage.unlinkedAccount)).not.toBeInTheDocument(); |
| 22 | + }); |
| 23 | + }); |
| 24 | + |
| 25 | + describe("when there are errors", () => { |
| 26 | + describe("user is logged in and has a myNJ linking error", () => { |
| 27 | + it("shows unlinked account message, logout instructions, and help link", () => { |
| 28 | + render( |
| 29 | + withAuth(<LoadingPageComponent hasError={true} isLinkingError={true} />, { |
| 30 | + isAuthenticated: IsAuthenticated.TRUE, |
| 31 | + }), |
| 32 | + ); |
| 33 | + |
| 34 | + expect(screen.getByText(Config.loginSupportPage.unlinkedAccount)).toBeInTheDocument(); |
| 35 | + |
| 36 | + expect( |
| 37 | + screen.getByRole("button", { name: Config.loginSupportPage.logoutButtonTextUnlinked }), |
| 38 | + ).toBeInTheDocument(); |
| 39 | + expect(screen.getByText(/please/i)).toBeInTheDocument(); |
| 40 | + expect(screen.getByText(/and try again/i)).toBeInTheDocument(); |
| 41 | + |
| 42 | + expect(screen.getByRole("link", { name: /login issues help page/i })).toBeInTheDocument(); |
| 43 | + }); |
| 44 | + |
| 45 | + it("'unlinked account' message is not bold", () => { |
| 46 | + render( |
| 47 | + withAuth(<LoadingPageComponent hasError={true} isLinkingError={true} />, { |
| 48 | + isAuthenticated: IsAuthenticated.TRUE, |
| 49 | + }), |
| 50 | + ); |
| 51 | + |
| 52 | + const UnlinkedAccountMessage = screen.getByText(Config.loginSupportPage.unlinkedAccount); |
| 53 | + expect(UnlinkedAccountMessage).not.toHaveClass("text-bold"); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe("user is logged in and has no myNJ linking error", () => { |
| 58 | + it("shows bolded 'having trouble' message, logout instructions, and help link", () => { |
| 59 | + render( |
| 60 | + withAuth(<LoadingPageComponent hasError={true} isLinkingError={false} />, { |
| 61 | + isAuthenticated: IsAuthenticated.TRUE, |
| 62 | + }), |
| 63 | + ); |
| 64 | + |
| 65 | + const havingTroubleMessage = screen.getByText(Config.loginSupportPage.havingTrouble); |
| 66 | + expect(havingTroubleMessage).toBeInTheDocument(); |
| 67 | + expect(havingTroubleMessage).toHaveClass("text-bold"); |
| 68 | + |
| 69 | + expect( |
| 70 | + screen.getByRole("button", { name: Config.loginSupportPage.logoutButtonText }), |
| 71 | + ).toBeInTheDocument(); |
| 72 | + expect(screen.getByText(/and try again/i)).toBeInTheDocument(); |
| 73 | + |
| 74 | + expect(screen.getByRole("link", { name: /login issues help page/i })).toBeInTheDocument(); |
| 75 | + }); |
| 76 | + |
| 77 | + it("does not show the 'Please' text from the unlinked 'log out' message'", () => { |
| 78 | + render( |
| 79 | + withAuth(<LoadingPageComponent hasError={true} isLinkingError={false} />, { |
| 80 | + isAuthenticated: IsAuthenticated.TRUE, |
| 81 | + }), |
| 82 | + ); |
| 83 | + |
| 84 | + expect(screen.queryByText(/please/i)).not.toBeInTheDocument(); |
| 85 | + }); |
| 86 | + }); |
| 87 | + |
| 88 | + describe("user is logged out and has a myNJ linking error", () => { |
| 89 | + it("shows unlinked account message and help link, but no logout link", () => { |
| 90 | + render( |
| 91 | + withAuth(<LoadingPageComponent hasError={true} isLinkingError={true} />, { |
| 92 | + isAuthenticated: IsAuthenticated.FALSE, |
| 93 | + }), |
| 94 | + ); |
| 95 | + |
| 96 | + expect(screen.getByText(Config.loginSupportPage.unlinkedAccount)).toBeInTheDocument(); |
| 97 | + |
| 98 | + expect( |
| 99 | + screen.queryByRole("button", { name: Config.loginSupportPage.logoutButtonText }), |
| 100 | + ).not.toBeInTheDocument(); |
| 101 | + // "please" is only in the "logged in and unlinked" error copy |
| 102 | + expect(screen.queryByText(/please/i)).not.toBeInTheDocument(); |
| 103 | + |
| 104 | + expect(screen.getByRole("link", { name: /login issues help page/i })).toBeInTheDocument(); |
| 105 | + }); |
| 106 | + }); |
| 107 | + |
| 108 | + describe("user is logged out and has no myNJ linking error", () => { |
| 109 | + it("shows bolded 'having trouble' message and help link, but no logout link", () => { |
| 110 | + render( |
| 111 | + withAuth(<LoadingPageComponent hasError={true} isLinkingError={false} />, { |
| 112 | + isAuthenticated: IsAuthenticated.FALSE, |
| 113 | + }), |
| 114 | + ); |
| 115 | + |
| 116 | + const havingTroubleMessage = screen.getByText(Config.loginSupportPage.havingTrouble); |
| 117 | + expect(havingTroubleMessage).toBeInTheDocument(); |
| 118 | + expect(havingTroubleMessage).toHaveClass("text-bold"); |
| 119 | + |
| 120 | + expect( |
| 121 | + screen.queryByRole("button", { name: Config.loginSupportPage.logoutButtonText }), |
| 122 | + ).not.toBeInTheDocument(); |
| 123 | + |
| 124 | + expect(screen.getByRole("link", { name: /login issues help page/i })).toBeInTheDocument(); |
| 125 | + }); |
| 126 | + }); |
| 127 | + }); |
| 128 | +}); |
0 commit comments