From cbaddcb6c5baefa6fb7f726428e8856ce58b5ee6 Mon Sep 17 00:00:00 2001 From: Johnson Mao Date: Fri, 22 Dec 2023 20:09:43 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor=20unit=20test=20a?= =?UTF-8?q?nd=20minor=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/[lang]/__tests__/card.test.tsx | 5 +- src/app/[lang]/__tests__/footer.test.tsx | 5 +- src/app/[lang]/__tests__/header.test.tsx | 89 ++++++++----------- src/app/[lang]/__tests__/layout.test.tsx | 15 ++-- src/app/[lang]/__tests__/menu.test.tsx | 49 +++++----- src/app/[lang]/__tests__/page.test.tsx | 14 ++- .../posts/[postId]/__tests__/page.test.tsx | 84 ++++++++--------- src/app/[lang]/posts/__tests__/page.test.tsx | 16 ++-- src/app/layout.tsx | 2 +- src/app/not-found.tsx | 9 +- src/components/CodeBox/codeBox.test.tsx | 19 ++-- src/components/Comment/comment.test.tsx | 6 +- src/components/Container/container.test.tsx | 4 +- src/components/Heading/heading.test.tsx | 10 +-- src/components/Image/image.test.tsx | 17 ++-- src/components/Link/link.test.tsx | 10 +-- src/components/List/list.test.tsx | 9 +- src/components/NotFound/NotFound.tsx | 25 ------ src/components/NotFound/index.tsx | 3 - src/components/NotFound/notFound.test.tsx | 18 ---- .../TableOfContents/tableOfContents.test.tsx | 6 +- src/components/ThemeSwitcher/index.tsx | 4 +- .../ThemeSwitcher/themeSwitcher.test.tsx | 16 ++-- src/hooks/__tests__/useAutoReset.test.ts | 8 +- src/hooks/__tests__/useI18n.test.ts | 4 +- .../__tests__/useIntersectionObserver.test.ts | 16 ++-- src/hooks/__tests__/useMounted.test.ts | 3 +- src/hooks/__tests__/useScroll.test.ts | 55 ++++++------ .../__tests__/rehypeImageMetadata.test.ts | 25 ++++-- src/utils/__tests__/clipboard.test.ts | 20 +++-- src/utils/__tests__/cn.test.ts | 11 ++- src/utils/__tests__/date.test.ts | 63 +++++++++---- src/utils/__tests__/generateRSS.test.ts | 25 ++++-- src/utils/__tests__/getLocale.test.ts | 23 +++-- src/utils/__tests__/math.test.ts | 23 +++-- src/utils/__tests__/mdx.test.ts | 32 ++++--- tailwind.config.js | 14 +-- 37 files changed, 372 insertions(+), 385 deletions(-) delete mode 100644 src/components/NotFound/NotFound.tsx delete mode 100644 src/components/NotFound/index.tsx delete mode 100644 src/components/NotFound/notFound.test.tsx diff --git a/src/app/[lang]/__tests__/card.test.tsx b/src/app/[lang]/__tests__/card.test.tsx index 3ba6f57e..b0a57475 100644 --- a/src/app/[lang]/__tests__/card.test.tsx +++ b/src/app/[lang]/__tests__/card.test.tsx @@ -5,6 +5,7 @@ import Article from '../Article'; describe('Article component', () => { it('should render correct element', () => { + // Arrange const data: DataFrontmatter = { id: 'test_id', title: 'title test', @@ -17,13 +18,11 @@ describe('Article component', () => { tags: ['tag_A', 'tag_B'], description: 'description test', }; - render(
); - const article = screen.getByRole('article'); const image = screen.getByRole('img'); const heading = screen.getByRole('heading'); - + // Assert expect(article).toBeInTheDocument(); expect(image).toHaveAttribute('src', data.image); expect(image).toHaveAttribute('alt', `${data.title} cover`); diff --git a/src/app/[lang]/__tests__/footer.test.tsx b/src/app/[lang]/__tests__/footer.test.tsx index 089cbbad..f64fe575 100644 --- a/src/app/[lang]/__tests__/footer.test.tsx +++ b/src/app/[lang]/__tests__/footer.test.tsx @@ -3,12 +3,11 @@ import Footer from '../Footer'; describe('Footer component', () => { it('should render correct element', () => { + // Arrange const footerCopyright = 'footer copyright'; - render(