diff --git a/apps/blog/src/libs/api/api.ts b/apps/blog/src/libs/api/api.ts index bf7031d7..a5efeff6 100644 --- a/apps/blog/src/libs/api/api.ts +++ b/apps/blog/src/libs/api/api.ts @@ -6,8 +6,6 @@ const cwd = process.cwd(); // NOTE: Trinomial for test:coverage environment const postsDirectory = join(cwd, cwd.endsWith('blog') ? '_content' : 'apps/blog/_content'); -console.log(postsDirectory); - function isValidCategory(value: string) { if (value.includes('.')) return false; return true; diff --git a/apps/blog/src/pages/[slug].page.tsx b/apps/blog/src/pages/[slug].page.tsx index 6603cf28..0a40054d 100644 --- a/apps/blog/src/pages/[slug].page.tsx +++ b/apps/blog/src/pages/[slug].page.tsx @@ -71,7 +71,6 @@ export async function getStaticPaths() { export async function getStaticProps({ params }) { const { slug } = params; - // 한 개만 찾는 api 만들어서 리팩토링해야함 const allPosts = getAllPosts(['title', 'subtitle', 'date', 'category', 'content', 'slug']); const currentPost = allPosts.filter(post => post.slug === slug)[0]; if (typeof currentPost === 'undefined') { diff --git a/apps/blog/src/pages/__test__/404.test.tsx b/apps/blog/src/pages/__test__/404.test.tsx new file mode 100644 index 00000000..936ccd52 --- /dev/null +++ b/apps/blog/src/pages/__test__/404.test.tsx @@ -0,0 +1,13 @@ +import { NotFound as CoreNotFount } from 'core'; + +import NotFound from '../404.page'; + +describe('blog - pages - 404', () => { + it('should defined', () => { + expect(NotFound).toBeDefined(); + }); + + it('should return core NotFound component', () => { + expect(NotFound).toBe(CoreNotFount); + }); +}); diff --git a/apps/blog/src/pages/__test__/500.test.tsx b/apps/blog/src/pages/__test__/500.test.tsx new file mode 100644 index 00000000..0fb2421b --- /dev/null +++ b/apps/blog/src/pages/__test__/500.test.tsx @@ -0,0 +1,13 @@ +import { ServerError as CoreServerError } from 'core'; + +import ServerError from '../500.page'; + +describe('blog - pages - 500', () => { + it('should defined', () => { + expect(ServerError).toBeDefined(); + }); + + it('should return core ServerError component', () => { + expect(ServerError).toBe(CoreServerError); + }); +}); diff --git a/apps/blog/src/pages/__test__/[slug].test.tsx b/apps/blog/src/pages/__test__/[slug].test.tsx new file mode 100644 index 00000000..738d8b0d --- /dev/null +++ b/apps/blog/src/pages/__test__/[slug].test.tsx @@ -0,0 +1,35 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; + +import Slug from '../[slug].page'; + +const MOCK_POST = { + slug: 'comet-land', + title: 'Comet-land', + subtitle: 'blog and resume theme', + date: '2022-01-01', + category: 'blog', + content: '

heading

', + ogImage: null, +}; + +// NOTE: prevent ResizeObserver and IntersectionObserver at PageProgressBar, TOC +jest.spyOn(React, 'useEffect').mockImplementation(f => f()); + +describe('blog - pages - [slug]', () => { + it('should defined', () => { + expect(Slug).toBeDefined(); + }); + + it('should render main', () => { + render(); + + expect(screen.getByRole('main')).toBeInTheDocument(); + }); + + it('should render one level 1 heading', () => { + render(); + + expect(screen.getByRole('heading', { level: 1 })).toBeInTheDocument(); + }); +}); diff --git a/apps/blog/src/pages/__test__/_app.test.tsx b/apps/blog/src/pages/__test__/_app.test.tsx new file mode 100644 index 00000000..4cb73aaa --- /dev/null +++ b/apps/blog/src/pages/__test__/_app.test.tsx @@ -0,0 +1,7 @@ +import BlogApp from '../_app.page'; + +describe('blog - pages - app', () => { + it('should defined', () => { + expect(BlogApp).toBeDefined(); + }); +}); diff --git a/apps/blog/src/pages/__test__/_document.test.tsx b/apps/blog/src/pages/__test__/_document.test.tsx new file mode 100644 index 00000000..cdf747f8 --- /dev/null +++ b/apps/blog/src/pages/__test__/_document.test.tsx @@ -0,0 +1,7 @@ +import BlogDocument from '../_document.page'; + +describe('blog - pages - document', () => { + it('should defined', () => { + expect(BlogDocument).toBeDefined(); + }); +}); diff --git a/apps/blog/src/pages/__test__/_offline.test.tsx b/apps/blog/src/pages/__test__/_offline.test.tsx new file mode 100644 index 00000000..69e90b72 --- /dev/null +++ b/apps/blog/src/pages/__test__/_offline.test.tsx @@ -0,0 +1,13 @@ +import { Offline as CoreOffline } from 'core'; + +import Offline from '../_offline.page'; + +describe('blog - pages - offline', () => { + it('should defined', () => { + expect(Offline).toBeDefined(); + }); + + it('should return core NotFound component', () => { + expect(Offline).toBe(CoreOffline); + }); +}); diff --git a/apps/blog/src/pages/__test__/category/[category].test.tsx b/apps/blog/src/pages/__test__/category/[category].test.tsx new file mode 100644 index 00000000..36a34769 --- /dev/null +++ b/apps/blog/src/pages/__test__/category/[category].test.tsx @@ -0,0 +1,38 @@ +import { render, screen } from '@testing-library/react'; + +import Category from '../../category/[category].page'; + +const MOCK_CATEGORY = 'mockCategory'; +const MOCK_POST = { + slug: 'comet-land', + title: 'Comet-land', + subtitle: 'blog and resume theme', + date: '2022-01-01', + category: 'blog', + content: '

heading

', +}; + +describe('blog - pages - category - [category]', () => { + it('should defined', () => { + expect(Category).toBeDefined(); + }); + + it('should render main', () => { + render(); + + expect(screen.getByRole('main')).toBeInTheDocument(); + }); + + it('should render allPosts props', () => { + render(); + + expect(screen.getByText(MOCK_POST.title)).toBeInTheDocument(); + expect(screen.getByText(MOCK_POST.subtitle)).toBeInTheDocument(); + }); + + it('should render category at lever 2 heading', () => { + render(); + + expect(screen.getAllByRole('heading', { level: 2 }).at(-1)).toHaveTextContent(MOCK_CATEGORY); + }); +}); diff --git a/apps/blog/src/pages/__test__/index.test.tsx b/apps/blog/src/pages/__test__/index.test.tsx new file mode 100644 index 00000000..174af956 --- /dev/null +++ b/apps/blog/src/pages/__test__/index.test.tsx @@ -0,0 +1,36 @@ +import { render, screen } from '@testing-library/react'; + +import Index from '../index.page'; + +const MOCK_POST = { + slug: 'comet-land', + title: 'Comet-land', + subtitle: 'blog and resume theme', + date: '2022-01-01', + category: 'blog', + content: '

heading

', +}; + +describe('blog - pages - index', () => { + it('should defined', () => { + expect(Index).toBeDefined(); + }); + + it('should render main', () => { + render(); + + expect(screen.getByRole('main')).toBeInTheDocument(); + }); + + it('should render post title', () => { + render(); + + expect(screen.getByText(MOCK_POST.title)).toBeInTheDocument(); + }); + + it('should has one level 1 heading', () => { + render(); + + expect(screen.getByRole('heading', { level: 1 })).toBeInTheDocument(); + }); +});