Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tktcorporation committed Oct 10, 2022
1 parent 5002e2c commit 20525b9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
45 changes: 34 additions & 11 deletions web/src/components/Comment/Comment.test.tsx
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())
})
})
2 changes: 2 additions & 0 deletions web/src/components/CommentsCell/CommentsCell.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ export const standard = () => ({
id: 1,
name: 'Rob Cameron',
body: 'First comment',
postId: 1,
createdAt: '2020-01-02T12:34:56Z',
},
{
id: 2,
name: 'David Price',
body: 'Second comment',
postId: 2,
createdAt: '2020-02-03T23:00:00Z',
},
],
Expand Down

0 comments on commit 20525b9

Please sign in to comment.