-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Switch to using api v2 endpoints when fetching user * Add optional admin_url field to user type definition * Handle optional admin url in global state * Show admin url in user menu Only visible for users who have admin urls * Add divider * Add icons to admin_url and logout menu items * Make admin_url menu item an anchor element Better accessibility * Make user menu more accessible Also makes it easier to test the components * Test rendering of Header componenet * Update changelog * Make admin url component an external react link Since admin_url it is always an absolute URL * Add aria label to admin url link component For better accessibility
- Loading branch information
1 parent
09e138b
commit 803c7e9
Showing
12 changed files
with
125 additions
and
12 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
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,74 @@ | ||
import {render, screen, within} from "@testing-library/react"; | ||
import React from "react"; | ||
import Header from "./Header"; | ||
import {MemoryRouter} from "react-router-dom"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
|
||
describe("Render Header", () => { | ||
it("renders the Logo, both image and link", () => { | ||
render( | ||
<MemoryRouter> | ||
<Header/> | ||
</MemoryRouter> | ||
); | ||
expect(screen.getByRole('img', {name: /argus logo/i})).toBeInTheDocument(); | ||
expect(screen.getByRole('link', {name: /argus logo/i})).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders the Incidents button", () => { | ||
render( | ||
<MemoryRouter> | ||
<Header/> | ||
</MemoryRouter> | ||
); | ||
expect(screen.getByRole('button', {name: 'Incidents'})).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders the Timeslots button", () => { | ||
render( | ||
<MemoryRouter> | ||
<Header/> | ||
</MemoryRouter> | ||
); | ||
expect(screen.getByRole('button', {name: /timeslots/i})).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders the Profiles button", () => { | ||
render( | ||
<MemoryRouter> | ||
<Header/> | ||
</MemoryRouter> | ||
); | ||
expect(screen.getByRole('button', {name: /profiles/i})).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders the user menu button", () => { | ||
render( | ||
<MemoryRouter> | ||
<Header/> | ||
</MemoryRouter> | ||
); | ||
expect(screen.getByRole('button', {name: /user menu/i})).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders only 2 default user menu items", () => { | ||
render( | ||
<MemoryRouter> | ||
<Header/> | ||
</MemoryRouter> | ||
); | ||
|
||
// Open user menu | ||
userEvent.click(screen.getByRole('button', {name: /user menu/i})); | ||
const userMenu = screen.getByRole('menu') | ||
expect(userMenu).toBeInTheDocument() | ||
expect(userMenu).toBeVisible() | ||
|
||
// Expect 2 menu items to load - links to Destinations and Logout | ||
const menuItems = within(userMenu).getAllByRole("menuitem") | ||
expect(menuItems).toHaveLength(2) | ||
expect(menuItems[0]).toHaveTextContent(/destinations/i) | ||
expect(menuItems[1]).toHaveTextContent(/logout/i) | ||
}); | ||
}); |
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
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
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