Skip to content

Commit

Permalink
Merge 3da2599 into 628b33c
Browse files Browse the repository at this point in the history
  • Loading branch information
hyesungoh authored Jun 28, 2022
2 parents 628b33c + 3da2599 commit 33173e6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: CI

on:
push:
branches: -main
branches:
- main
pull_request:
branches:
- main
Expand Down
47 changes: 47 additions & 0 deletions apps/blog/src/components/PostCard/PostCard.test.tsx
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);
});
});
7 changes: 7 additions & 0 deletions apps/blog/src/components/PostCard/index.test.tsx
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();
});
});

0 comments on commit 33173e6

Please sign in to comment.