-
Notifications
You must be signed in to change notification settings - Fork 0
Make navigation bar application aware #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
16cc7c7
Make navigation bar application aware
CharlesFarris 9c10d4d
Fix PR issues
CharlesFarris 39bc0b3
Pass username from jwtPayload
CharlesFarris fe3beef
Fix conditional
CharlesFarris d03524b
Fix navigation bar item test
CharlesFarris b843dc6
Fix tests
CharlesFarris ac232f7
Update getUsernameFromJwtPayload
CharlesFarris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 { describe, expect, test } from "bun:test"; | ||
| import { NavigationBar } from "./navigationBar.tsx"; | ||
|
|
||
| describe("NavigationBar", () => { | ||
| test("renders authenticated navigation links, username, and logout action", () => { | ||
| const html = NavigationBar({ | ||
| type: "authenticated", | ||
| currentPath: "/add-todo", | ||
| username: "test-user", | ||
| }); | ||
| const htmlString = String(html); | ||
|
|
||
| expect(htmlString).toContain("<nav>"); | ||
| expect(htmlString).toContain('<a href="/">Home</a>'); | ||
| expect(htmlString).not.toContain('<a href="/add-todo">Add</a>'); | ||
| expect(htmlString).toContain('<a href="/about">About</a>'); | ||
| expect(htmlString).toContain("<li>test-user</li>"); | ||
| expect(htmlString).toContain('<form action="/api/logout" method="post">'); | ||
| expect(htmlString).toContain( | ||
| '<button class="nav-link-button" type="submit">', | ||
| ); | ||
| }); | ||
|
|
||
| test("hides the authenticated current route link", () => { | ||
| const html = NavigationBar({ | ||
| type: "authenticated", | ||
| currentPath: "/", | ||
| username: "test-user", | ||
| }); | ||
| const htmlString = String(html); | ||
|
|
||
| expect(htmlString).not.toContain('<a href="/">Home</a>'); | ||
| expect(htmlString).toContain('<a href="/add-todo">Add</a>'); | ||
| expect(htmlString).toContain('<a href="/about">About</a>'); | ||
| expect(htmlString).toContain("<li>test-user</li>"); | ||
| expect(htmlString).toContain('<form action="/api/logout" method="post">'); | ||
| }); | ||
|
|
||
| test("renders unauthenticated links", () => { | ||
| const html = NavigationBar({ type: "unauthenticated", currentPath: "/" }); | ||
| const htmlString = String(html); | ||
|
|
||
| expect(htmlString).toContain('<a href="/login">Login</a>'); | ||
| expect(htmlString).toContain('<a href="/about">About</a>'); | ||
| expect(htmlString).not.toContain("Logout"); | ||
| }); | ||
|
|
||
| test("hides the unauthenticated current route link", () => { | ||
| const html = NavigationBar({ | ||
| type: "unauthenticated", | ||
| currentPath: "/login", | ||
| }); | ||
| const htmlString = String(html); | ||
|
|
||
| expect(htmlString).not.toContain('<a href="/login">Login</a>'); | ||
| expect(htmlString).toContain('<a href="/about">About</a>'); | ||
| }); | ||
| }); |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,27 +1,85 @@ | ||
| import { apiRoutes } from "./apiRoutes.ts"; | ||
| import { NavigationBarItem } from "./navigationBarItem.tsx"; | ||
| import { pageRoutes } from "./pageRoutes.ts"; | ||
|
|
||
| export function navigationBar() { | ||
| return ( | ||
| <nav> | ||
| <ul> | ||
| <li> | ||
| <a href={pageRoutes.HOME}>Home</a> | ||
| </li> | ||
| <li> | ||
| <a href={pageRoutes.ABOUT}>About</a> | ||
| </li> | ||
| <li> | ||
| <a href={pageRoutes.LOGIN}>Login</a> | ||
| </li> | ||
| <li> | ||
| <form action={apiRoutes.LOGOUT} method="post"> | ||
| <button class="nav-link-button" type="submit"> | ||
| Logout | ||
| </button> | ||
| </form> | ||
| </li> | ||
| </ul> | ||
| </nav> | ||
| ); | ||
| export type SharedNavigationBarProps = Readonly<{ | ||
| currentPath: string; | ||
| }>; | ||
|
|
||
| export type AuthenticatedNavigationBarProps = SharedNavigationBarProps & | ||
| Readonly<{ | ||
| type: "authenticated"; | ||
| username: string; | ||
| }>; | ||
|
|
||
| export type UnauthenticatedNavigationBarProps = SharedNavigationBarProps & | ||
| Readonly<{ | ||
| type: "unauthenticated"; | ||
| }>; | ||
|
|
||
| export type NavigationBarProps = | ||
| | AuthenticatedNavigationBarProps | ||
| | UnauthenticatedNavigationBarProps; | ||
|
|
||
| export function NavigationBar(props: NavigationBarProps) { | ||
| switch (props.type) { | ||
| case "authenticated": | ||
| return ( | ||
| <nav> | ||
| <ul> | ||
| <NavigationBarItem | ||
| type="link" | ||
| label="Home" | ||
| url={pageRoutes.HOME} | ||
| currentPath={props.currentPath} | ||
| /> | ||
| <NavigationBarItem | ||
| type="link" | ||
| label="Add" | ||
| url={pageRoutes.ADD_TODO} | ||
| currentPath={props.currentPath} | ||
| /> | ||
|
CharlesFarris marked this conversation as resolved.
|
||
| <NavigationBarItem | ||
| type="link" | ||
| label="About" | ||
| url={pageRoutes.ABOUT} | ||
| currentPath={props.currentPath} | ||
| /> | ||
| <NavigationBarItem type="generic"> | ||
| {props.username} | ||
| </NavigationBarItem> | ||
| <NavigationBarItem type="generic"> | ||
| <form action={apiRoutes.LOGOUT} method="post"> | ||
| <button class="nav-link-button" type="submit"> | ||
| Logout | ||
| </button> | ||
| </form> | ||
| </NavigationBarItem> | ||
| </ul> | ||
| </nav> | ||
| ); | ||
| case "unauthenticated": | ||
| return ( | ||
| <nav> | ||
| <ul> | ||
| <NavigationBarItem | ||
| type="link" | ||
| label="Login" | ||
| url={pageRoutes.LOGIN} | ||
| currentPath={props.currentPath} | ||
| /> | ||
| <NavigationBarItem | ||
| type="link" | ||
| label="About" | ||
| url={pageRoutes.ABOUT} | ||
| currentPath={props.currentPath} | ||
| /> | ||
| </ul> | ||
| </nav> | ||
| ); | ||
| default: { | ||
| const _unknownType: never = props; | ||
| return _unknownType; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.