-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -2,7 +2,8 @@ name: CI | |
|
||
on: | ||
push: | ||
branches: -main | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
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,47 @@ | ||
import { theme } from '@nextui-org/react'; | ||
import { render, screen, within } from '@testing-library/react'; | ||
|
||
import PostCard from './PostCard'; | ||
|
||
const mockSlug = 'slug'; | ||
const mockTitle = 'title'; | ||
const mockSubtitle = 'subtitle'; | ||
const mockDate = '2020-02-02'; | ||
const mockCategory = 'category'; | ||
const mockTheme = theme; | ||
|
||
describe('blog - components - PostCard', () => { | ||
it('should default defined', () => { | ||
expect(PostCard).toBeDefined(); | ||
}); | ||
|
||
it('should render title with level 3 heading', () => { | ||
render(<PostCard slug={mockSlug} title={mockTitle} date={mockDate} theme={mockTheme} />); | ||
const level3Heading = screen.getByRole('heading', { level: 3 }); | ||
expect(level3Heading).toBeInTheDocument(); | ||
expect(within(level3Heading).getByText(mockTitle)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should have link to slug within level 3 heading', () => { | ||
render(<PostCard slug={mockSlug} title={mockTitle} date={mockDate} theme={mockTheme} />); | ||
const level3Heading = screen.getByRole('heading', { level: 3 }); | ||
const linkWithinLevel3Heading = within(level3Heading).getByRole('link'); | ||
expect(linkWithinLevel3Heading).toBeInTheDocument(); | ||
expect(linkWithinLevel3Heading).toHaveAttribute('href', `/${mockSlug}`); | ||
}); | ||
|
||
it('should render subtitle when passing to props', () => { | ||
render(<PostCard slug={mockSlug} title={mockTitle} date={mockDate} theme={mockTheme} subtitle={mockSubtitle} />); | ||
expect(screen.getByText(mockSubtitle)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render date', () => { | ||
render(<PostCard slug={mockSlug} title={mockTitle} date={mockDate} theme={mockTheme} />); | ||
expect(screen.getByRole('article')).toHaveTextContent(mockDate); | ||
}); | ||
|
||
it('should render category when passing props', () => { | ||
render(<PostCard slug={mockSlug} title={mockTitle} date={mockDate} theme={mockTheme} category={mockCategory} />); | ||
expect(screen.getByRole('article')).toHaveTextContent(mockCategory); | ||
}); | ||
}); |
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,7 @@ | ||
import Default from './index'; | ||
|
||
describe('blog - components - PostCard - index', () => { | ||
it('should defined', () => { | ||
expect(Default).toBeDefined(); | ||
}); | ||
}); |