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 fce8e6b commit 3e8de4f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
34 changes: 0 additions & 34 deletions web/src/components/ArticlesCell/ArticlesCell.test.js

This file was deleted.

43 changes: 43 additions & 0 deletions web/src/components/ArticlesCell/ArticlesCell.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { render, screen, within } from '@redwoodjs/testing'

import { Loading, Empty, Failure, Success } from './ArticlesCell'
import { standard } from './ArticlesCell.mock'

describe('ArticlesCell', () => {
test('Loading renders successfully', () => {
expect(() => {
render(<Loading />)
}).not.toThrow()
})

test('Empty renders successfully', async () => {
expect(() => {
render(<Empty />)
}).not.toThrow()
})

test('Failure renders successfully', async () => {
expect(() => {
render(<Failure error={new Error('Oh no')} />)
}).not.toThrow()
})

test('Success renders successfully', async () => {
const articles = standard().articles
render(<Success articles={articles} />)

articles.forEach((article) => {
const truncatedBody = article.body.substring(0, 10)
const matchedBody = screen.getByText(truncatedBody, { exact: false })
const ellipsis = within(matchedBody).getByText('...', { exact: false })

expect(screen.getByText(article.title)).toBeInTheDocument()
// The full body of the post body is not present
expect(screen.queryByText(article.body)).not.toBeInTheDocument()
// But, at least the first couple of words of the post are present
expect(matchedBody).toBeInTheDocument()
// The text that is shown ends in "..."
expect(ellipsis).toBeInTheDocument()
})
})
})

0 comments on commit 3e8de4f

Please sign in to comment.