-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
5002e2c
commit 20525b9
Showing
2 changed files
with
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,44 @@ | ||
import { render, screen } from '@redwoodjs/testing' | ||
import { render, screen, waitFor } from '@redwoodjs/testing' | ||
|
||
import Comment from './Comment' | ||
|
||
const COMMENT = { | ||
id: 1, | ||
name: 'John Doe', | ||
body: 'This is my comment', | ||
createdAt: '2020-01-02T12:34:56Z', | ||
postId: 1, | ||
} | ||
|
||
describe('Comment', () => { | ||
it('renders successfully', () => { | ||
const comment = { | ||
name: 'John Doe', | ||
body: 'This is my comment', | ||
createdAt: '2020-01-02T12:34:56Z', | ||
} | ||
render(<Comment comment={comment} />) | ||
|
||
expect(screen.getByText(comment.name)).toBeInTheDocument() | ||
expect(screen.getByText(comment.body)).toBeInTheDocument() | ||
render(<Comment comment={COMMENT} />) | ||
|
||
expect(screen.getByText(COMMENT.name)).toBeInTheDocument() | ||
expect(screen.getByText(COMMENT.body)).toBeInTheDocument() | ||
const dateExpect = screen.getByText('2 January 2020') | ||
expect(dateExpect).toBeInTheDocument() | ||
expect(dateExpect.nodeName).toEqual('TIME') | ||
expect(dateExpect).toHaveAttribute('datetime', comment.createdAt) | ||
expect(dateExpect).toHaveAttribute('datetime', COMMENT.createdAt) | ||
}) | ||
|
||
it('does not render a delete button if user is logged out', async () => { | ||
render(<Comment comment={COMMENT} />) | ||
|
||
await waitFor(() => | ||
expect(screen.queryByText('Delete')).not.toBeInTheDocument() | ||
) | ||
}) | ||
|
||
it('renders a delete button if the user is a moderator', async () => { | ||
mockCurrentUser({ | ||
roles: 'moderator', | ||
id: 1, | ||
email: '[email protected]', | ||
}) | ||
|
||
render(<Comment comment={COMMENT} />) | ||
|
||
await waitFor(() => expect(screen.getByText('Delete')).toBeInTheDocument()) | ||
}) | ||
}) |
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