Add story and tests for login state in BlogLayout

This commit is contained in:
Rob Cameron
2021-01-07 12:18:36 -08:00
parent 3a5d215a0f
commit 93d5b558aa
2 changed files with 35 additions and 6 deletions

View File

@@ -1,11 +1,34 @@
import { render } from '@redwoodjs/testing'
import { render, screen, waitFor } from '@redwoodjs/testing'
import BlogLayout from './BlogLayout'
const EMAIL = 'rob@redwoodjs.com'
const loggedIn = () => {
mockCurrentUser({ email: EMAIL })
}
const loggedOut = () => {
mockCurrentUser(null)
}
describe('BlogLayout', () => {
it('renders successfully', () => {
expect(() => {
render(<BlogLayout />)
}).not.toThrow()
it('displays a Log In link when not logged in', async () => {
loggedOut()
render(<BlogLayout />)
await waitFor(() => expect(screen.getByText('Log In')).toBeInTheDocument())
})
it('displays a Log Out link when logged in', async () => {
loggedIn()
render(<BlogLayout />)
await waitFor(() => expect(screen.getByText('Log Out')).toBeInTheDocument())
})
it("displays a logged in user's email address", async () => {
loggedIn()
render(<BlogLayout />)
await waitFor(() => expect(screen.getByText(EMAIL)).toBeInTheDocument())
})
})