From 04899a3397ccf622f5508a280eebb4dc65bda19b Mon Sep 17 00:00:00 2001 From: Hyesung Oh Date: Wed, 29 Jun 2022 03:57:20 +0900 Subject: [PATCH 1/3] test: blog PostCard index --- apps/blog/src/components/PostCard/index.test.tsx | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 apps/blog/src/components/PostCard/index.test.tsx diff --git a/apps/blog/src/components/PostCard/index.test.tsx b/apps/blog/src/components/PostCard/index.test.tsx new file mode 100644 index 00000000..6371a070 --- /dev/null +++ b/apps/blog/src/components/PostCard/index.test.tsx @@ -0,0 +1,7 @@ +import Default from './index'; + +describe('blog - components - PostCard - index', () => { + it('should defined', () => { + expect(Default).toBeDefined(); + }); +}); From da0ed8185dd79213f06694cac91fa9e781243ea2 Mon Sep 17 00:00:00 2001 From: Hyesung Oh Date: Wed, 29 Jun 2022 04:00:55 +0900 Subject: [PATCH 2/3] fix: typo at CI --- .github/workflows/CI.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 544586e6..a3500f80 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -2,7 +2,8 @@ name: CI on: push: - branches: -main + branches: + - main pull_request: branches: - main From 3da2599ead3fb972e8a8f6b905c3328eff0afffa Mon Sep 17 00:00:00 2001 From: Hyesung Oh Date: Wed, 29 Jun 2022 04:16:00 +0900 Subject: [PATCH 3/3] test: blog PostCard component --- .../src/components/PostCard/PostCard.test.tsx | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 apps/blog/src/components/PostCard/PostCard.test.tsx diff --git a/apps/blog/src/components/PostCard/PostCard.test.tsx b/apps/blog/src/components/PostCard/PostCard.test.tsx new file mode 100644 index 00000000..6786ff3c --- /dev/null +++ b/apps/blog/src/components/PostCard/PostCard.test.tsx @@ -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(); + 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(); + 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(); + expect(screen.getByText(mockSubtitle)).toBeInTheDocument(); + }); + + it('should render date', () => { + render(); + expect(screen.getByRole('article')).toHaveTextContent(mockDate); + }); + + it('should render category when passing props', () => { + render(); + expect(screen.getByRole('article')).toHaveTextContent(mockCategory); + }); +});