-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #485 from huwshimi/navigation-tests
WD-17050 - chore(tests): add Navigation component tests
- Loading branch information
Showing
3 changed files
with
76 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { renderComponent } from "test/utils"; | ||
import { screen, within } from "@testing-library/dom"; | ||
|
||
import { urls } from "urls"; | ||
|
||
import Navigation from "./Navigation"; | ||
import { Label } from "./types"; | ||
import { authURLs } from "api/auth"; | ||
import { appendAPIBasePath } from "util/basePaths"; | ||
|
||
test("displays page links", () => { | ||
renderComponent(<Navigation />); | ||
expect( | ||
screen.getByRole("link", { name: Label.IDENTITY_PROVIDERS }), | ||
).toHaveAttribute("href", urls.providers.index); | ||
expect(screen.getByRole("link", { name: Label.CLIENTS })).toHaveAttribute( | ||
"href", | ||
urls.clients.index, | ||
); | ||
expect(screen.getByRole("link", { name: Label.IDENTITIES })).toHaveAttribute( | ||
"href", | ||
urls.identities.index, | ||
); | ||
expect(screen.getByRole("link", { name: Label.SCHEMAS })).toHaveAttribute( | ||
"href", | ||
urls.schemas.index, | ||
); | ||
expect(screen.getByRole("link", { name: "Groups" })).toHaveAttribute( | ||
"href", | ||
urls.groups.index, | ||
); | ||
expect(screen.getByRole("link", { name: "Roles" })).toHaveAttribute( | ||
"href", | ||
urls.roles.index, | ||
); | ||
}); | ||
|
||
test("displays username", () => { | ||
renderComponent(<Navigation username="[email protected]" />); | ||
const userNav = document.querySelector(".p-side-navigation--user-menu"); | ||
expect(userNav).toBeInTheDocument(); | ||
if (userNav) { | ||
expect( | ||
within(userNav as HTMLElement).getByText("[email protected]"), | ||
).toBeInTheDocument(); | ||
} | ||
}); | ||
|
||
test("has a logout link", () => { | ||
renderComponent(<Navigation username="[email protected]" />); | ||
const userNav = document.querySelector(".p-side-navigation--user-menu"); | ||
expect(userNav).toBeInTheDocument(); | ||
if (userNav) { | ||
expect( | ||
within(userNav as HTMLElement).getByRole("link", { name: Label.LOGOUT }), | ||
).toHaveAttribute("href", appendAPIBasePath(authURLs.logout)); | ||
} | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export enum Label { | ||
CLIENTS = "Clients", | ||
IDENTITIES = "Identities", | ||
IDENTITY_PROVIDERS = "Identity providers", | ||
LOGOUT = "Logout", | ||
SCHEMAS = "Schemas", | ||
} |