|
| 1 | +import { screen } from "@testing-library/react" |
| 2 | +import React from "react" |
| 3 | +import { AdminDropdown, Language } from "." |
| 4 | +import { history, render } from "../../../test_helpers" |
| 5 | + |
| 6 | +const renderAndClick = async () => { |
| 7 | + render(<AdminDropdown />) |
| 8 | + const trigger = await screen.findByText(Language.menuTitle) |
| 9 | + trigger.click() |
| 10 | +} |
| 11 | + |
| 12 | +describe("AdminDropdown", () => { |
| 13 | + describe("when the trigger is clicked", () => { |
| 14 | + it("opens the menu", async () => { |
| 15 | + await renderAndClick() |
| 16 | + expect(screen.getByText(Language.usersLabel)).toBeDefined() |
| 17 | + expect(screen.getByText(Language.orgsLabel)).toBeDefined() |
| 18 | + expect(screen.getByText(Language.settingsLabel)).toBeDefined() |
| 19 | + }) |
| 20 | + }) |
| 21 | + |
| 22 | + it("links to the users page", async () => { |
| 23 | + await renderAndClick() |
| 24 | + |
| 25 | + const usersLink = screen.getByText(Language.usersLabel).closest("a") |
| 26 | + usersLink?.click() |
| 27 | + |
| 28 | + expect(history.location.pathname).toEqual("/users") |
| 29 | + }) |
| 30 | + |
| 31 | + it("links to the orgs page", async () => { |
| 32 | + await renderAndClick() |
| 33 | + |
| 34 | + const usersLink = screen.getByText(Language.orgsLabel).closest("a") |
| 35 | + usersLink?.click() |
| 36 | + |
| 37 | + expect(history.location.pathname).toEqual("/orgs") |
| 38 | + }) |
| 39 | + |
| 40 | + it("links to the settings page", async () => { |
| 41 | + await renderAndClick() |
| 42 | + |
| 43 | + const usersLink = screen.getByText(Language.settingsLabel).closest("a") |
| 44 | + usersLink?.click() |
| 45 | + |
| 46 | + expect(history.location.pathname).toEqual("/settings") |
| 47 | + }) |
| 48 | +}) |
0 commit comments