From 2f8acbbcdfc124f7ca6fa23469687d6dcbbd2917 Mon Sep 17 00:00:00 2001 From: louiscklaw Date: Thu, 24 Apr 2025 10:25:31 +0800 Subject: [PATCH] init test and snapshot, --- .../__tests__/__snapshots__/snapshot.js.snap | 35 +++++++++++++++++++ .../__tests__/app/_helloworld/page.test.tsx | 21 +++++++++++ 002_source/cms/src/__tests__/snapshot.js | 9 +++++ 3 files changed, 65 insertions(+) create mode 100644 002_source/cms/src/__tests__/__snapshots__/snapshot.js.snap create mode 100644 002_source/cms/src/__tests__/app/_helloworld/page.test.tsx create mode 100644 002_source/cms/src/__tests__/snapshot.js diff --git a/002_source/cms/src/__tests__/__snapshots__/snapshot.js.snap b/002_source/cms/src/__tests__/__snapshots__/snapshot.js.snap new file mode 100644 index 0000000..1873932 --- /dev/null +++ b/002_source/cms/src/__tests__/__snapshots__/snapshot.js.snap @@ -0,0 +1,35 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders homepage unchanged 1`] = ` +
+
+ hello world! + +
+

+ inner component +

+
+ + + +
+
+
+`; diff --git a/002_source/cms/src/__tests__/app/_helloworld/page.test.tsx b/002_source/cms/src/__tests__/app/_helloworld/page.test.tsx new file mode 100644 index 0000000..5c198ca --- /dev/null +++ b/002_source/cms/src/__tests__/app/_helloworld/page.test.tsx @@ -0,0 +1,21 @@ +/// +import '@testing-library/jest-dom'; +import { render, screen } from '@testing-library/react'; +import Page from '@/app/_helloworld/page'; + +// Mock the translation hook +jest.mock('react-i18next', () => ({ + useTranslation: () => ({ + t: (key: string) => key, + }), +})); + +describe('Page', () => { + it('renders a heading', () => { + render(); + + const heading = screen.getByRole('heading', { level: 1 }); + + expect(heading).toBeInTheDocument(); + }); +}); diff --git a/002_source/cms/src/__tests__/snapshot.js b/002_source/cms/src/__tests__/snapshot.js new file mode 100644 index 0000000..c070dc2 --- /dev/null +++ b/002_source/cms/src/__tests__/snapshot.js @@ -0,0 +1,9 @@ +import { render } from '@testing-library/react'; + +// CUT = Component Under Test +import CUT from '../components/_helloworld'; + +it('renders homepage unchanged', () => { + const { container } = render(); + expect(container).toMatchSnapshot(); +});