-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ts/components/navMenu): add logout link to mobile nav (#2392)
* feat(ts/components/navMenu): add logout link to mobile nav
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ import { openDrift } from "../../../src/helpers/drift" | |
import { displayHelp } from "../../../src/helpers/appCue" | ||
import NavMenu from "../../../src/components/nav/navMenu" | ||
import { BrowserRouter } from "react-router-dom" | ||
import getTestGroups from "../../../src/userTestGroups" | ||
import { TestGroups } from "../../../src/userInTestGroup" | ||
import getEmailAddress from "../../../src/userEmailAddress" | ||
|
||
jest.mock("../../../src/helpers/drift", () => ({ | ||
__esModule: true, | ||
|
@@ -19,6 +22,13 @@ jest.mock("../../../src/helpers/appCue", () => ({ | |
displayHelp: jest.fn(), | ||
})) | ||
|
||
jest.mock("userTestGroups", () => ({ | ||
__esModule: true, | ||
default: jest.fn(() => []), | ||
})) | ||
|
||
jest.mock("../../../src/userEmailAddress") | ||
|
||
describe("NavMenu", () => { | ||
test("when mobile menu is open, clicking the backdrop toggled the mobile menu", async () => { | ||
const toggleMobileMenu = jest.fn() | ||
|
@@ -71,6 +81,33 @@ describe("NavMenu", () => { | |
expect(result.getByTestId("nav-menu")).not.toHaveClass("c-nav-menu--open") | ||
}) | ||
|
||
test("shows logout button", async () => { | ||
jest.mocked(getTestGroups).mockReturnValue([TestGroups.KeycloakSso]) | ||
jest.mocked(getEmailAddress).mockReturnValue("[email protected]") | ||
|
||
render( | ||
<BrowserRouter> | ||
<NavMenu toggleMobileMenu={jest.fn()} mobileMenuIsOpen={true} /> | ||
</BrowserRouter> | ||
) | ||
|
||
expect(screen.getByRole("link", { name: "Logout" })).toBeVisible() | ||
}) | ||
|
||
test("doesn't show logout button if the user isn't in the Keycloak test group", async () => { | ||
jest.mocked(getTestGroups).mockReturnValue([]) | ||
|
||
render( | ||
<BrowserRouter> | ||
<NavMenu toggleMobileMenu={jest.fn()} mobileMenuIsOpen={true} /> | ||
</BrowserRouter> | ||
) | ||
|
||
expect( | ||
screen.queryByRole("link", { name: "Logout" }) | ||
).not.toBeInTheDocument() | ||
}) | ||
|
||
test("refresh button reloads the page", async () => { | ||
const reloadSpy = jest | ||
.spyOn(browser, "reload") | ||
|