-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
103 additions
and
11 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
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,17 @@ | ||
{ | ||
"user": { | ||
"id": "user:google-oauth2|123", | ||
"name": "Test User", | ||
"picture": "https://ui-avatars.com/api/?name=Joe+Bloggs", | ||
"email": "[email protected]" | ||
}, | ||
"rooms": [ | ||
{ | ||
"id": "room:100", | ||
"name": "Test Room", | ||
"ownerId": "user:google-oauth2|123", | ||
"contentPolicy": "private", | ||
"joinPolicy": "invite" | ||
} | ||
] | ||
} |
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 @@ | ||
{ "id": "system", "name": "System", "email": "[email protected]" } |
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,65 @@ | ||
import React from 'react' | ||
import { render } from '../../../test/fixtures' | ||
import { waitFor, screen } from '@testing-library/react' | ||
import { AuthContext } from '../../../features/auth/context' | ||
import { Header } from './header' | ||
import userEvent from '@testing-library/user-event' | ||
|
||
describe('Header', () => { | ||
const signIn = vitest.fn() | ||
const signOut = vitest.fn() | ||
|
||
describe('when signed out', () => { | ||
it('has a sign in button', async () => { | ||
render( | ||
<AuthContext.Provider value={{ isAuthenticated: false, isLoading: false, signIn }}> | ||
<Header /> | ||
</AuthContext.Provider>, | ||
{ | ||
path: '/', | ||
initialEntry: '/', | ||
}, | ||
) | ||
|
||
const openMenu = screen.getByRole('button', { name: 'Open Menu' }) | ||
|
||
await waitFor(() => { | ||
expect(openMenu).toBeVisible() | ||
}) | ||
|
||
userEvent.click(openMenu) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByRole('button', { name: 'Sign In' })).toBeVisible() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when signed in', () => { | ||
it('has a sign out button', async () => { | ||
render( | ||
<AuthContext.Provider | ||
value={{ isAuthenticated: true, isLoading: false, signOut, token: 'a1b2c3', userName: 'Test User' }} | ||
> | ||
<Header /> | ||
</AuthContext.Provider>, | ||
{ | ||
path: '/', | ||
initialEntry: '/', | ||
}, | ||
) | ||
|
||
const openMenu = screen.getByRole('button', { name: 'Open Menu' }) | ||
|
||
await waitFor(() => { | ||
expect(openMenu).toBeVisible() | ||
}) | ||
|
||
userEvent.click(openMenu) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByRole('button', { name: 'Sign Out Test User' })).toBeVisible() | ||
}) | ||
}) | ||
}) | ||
}) |