-
Notifications
You must be signed in to change notification settings - Fork 109
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
fce8e6b
commit 3e8de4f
Showing
2 changed files
with
43 additions
and
34 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,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() | ||
}) | ||
}) | ||
}) |