Skip to content

Commit

Permalink
fix(mdx-content): fix the unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jerensl committed Jul 9, 2023
1 parent 9c3c518 commit e971746
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 13 deletions.
5 changes: 2 additions & 3 deletions __tests__/pages/Blog/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from 'react'
import { render, within } from '../../../__mocks__/utils/test-providers'
import Blog from '../../../src/pages/blog/index'
import BlogContext from '../../../src/libs/blog/index'
import { getContents } from '../../../src/libs/content'

jest.mock('firebase/messaging', () => jest.fn())
jest.mock('firebase/app', () => jest.fn())
Expand Down Expand Up @@ -33,8 +33,7 @@ useRouter.mockImplementation(() => ({
}))

const renderBlogSlug = async () => {
const post = new BlogContext('__mocks__/contents/blog')
const posts = await post.getAllPublishArticle()
const posts = await getContents('mock/blog')

const utils = render(<Blog posts={posts} tags={['Testing 101']} />)

Expand Down
5 changes: 2 additions & 3 deletions __tests__/pages/Blog/slug.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from 'react'
import { render } from '../../../__mocks__/utils/test-providers'
import Blog from '../../../src/pages/blog/[slug]'
import BlogContext from '../../../src/libs/blog/index'
import { getContent } from '../../../src/libs/content'

jest.mock('remark-math', () => jest.fn())
jest.mock('rehype-katex', () => jest.fn())
Expand Down Expand Up @@ -51,8 +51,7 @@ useRouter.mockImplementation(() => ({
}))

const renderBlogSlug = async () => {
const post = new BlogContext('__mocks__/contents/blog')
const posts = await post.getArticleWithMetadata('id-test-markdown')
const posts = await getContent('mock/blog', 'id-test-markdown')

const utils = render(
<Blog posts={posts} blurDataURL={posts.metadata.blurDataURL} />
Expand Down
5 changes: 2 additions & 3 deletions __tests__/pages/project/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from 'react'
import { render, within } from '../../../__mocks__/utils/test-providers'
import Project from '../../../src/pages/project/index'
import ProjectContext from '../../../src/libs/project/index'
import { getContents } from '../../../src/libs/content'

jest.mock('firebase/messaging', () => jest.fn())
jest.mock('firebase/app', () => jest.fn())
Expand Down Expand Up @@ -33,8 +33,7 @@ useRouter.mockImplementation(() => ({
}))

const renderBlogSlug = async () => {
const project = new ProjectContext('__mocks__/contents/project')
const projects = await project.getAllPublishedProject()
const projects = await getContents('mock/project')

const utils = render(<Project projects={projects} tags={['Testing 101']} />)

Expand Down
5 changes: 2 additions & 3 deletions __tests__/pages/project/slug.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from 'react'
import { render } from '../../../__mocks__/utils/test-providers'
import Project from '../../../src/pages/project/[slug]'
import ProjectContext from '../../../src/libs/project/index'
import { getContent } from '../../../src/libs/content'

jest.mock('remark-math', () => jest.fn())
jest.mock('rehype-katex', () => jest.fn())
Expand Down Expand Up @@ -48,8 +48,7 @@ useRouter.mockImplementation(() => ({
}))

const renderBlogSlug = async () => {
const project = new ProjectContext('__mocks__/contents/project')
const projects = await project.getProjectDetail('test-project')
const projects = await getContent('mock/project', 'test-project')

const utils = render(
<Project
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion src/libs/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import rehypeMetaAttribute from './rehype-meta-attribute'
import matter from 'gray-matter'
import { getPlaiceholder } from 'plaiceholder'
import { IProjectMetadata } from '@/types/project'
import { IContent } from '@/types/content'
import { IBlogMetadata } from '@/types/blog'

export const getFiles = (dir: string): string[] => {
Expand Down Expand Up @@ -108,6 +107,9 @@ async function getContents<T>(directory: string): Promise<Array<T>> {
})
)

console.log('HELOOOOOOO')
console.log(contents)

return contents
}

Expand Down

0 comments on commit e971746

Please sign in to comment.