-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from JohnsonMao/refactor/tests-folder
🏗️ refactor tests folder architectural
- Loading branch information
Showing
54 changed files
with
170 additions
and
383 deletions.
There are no files selected for viewing
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/components/Heading/Heading.tsx → src/components/Heading.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
src/app/[lang]/__tests__/footer.test.tsx → tests/app/[lang]/footer.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 5 additions & 9 deletions
14
src/app/[lang]/__tests__/layout.test.tsx → tests/app/[lang]/layout.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,39 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { locales } from '~/i18n'; | ||
import mockPathname from '~/tests/navigation'; | ||
import Layout, { generateMetadata, generateStaticParams } from '../layout'; | ||
import mockNavigation from '~/tests/navigation'; | ||
import Layout, { generateMetadata, generateStaticParams } from '@/app/[lang]/layout'; | ||
|
||
describe('I18n layout', () => { | ||
it('should render correct element', async () => { | ||
// Arrange | ||
const testText = 'Test layout component'; | ||
mockPathname.mockReturnValueOnce('/'); | ||
mockNavigation.pathname.mockReturnValueOnce('/'); | ||
const layout = await Layout({ | ||
children: <h2>{testText}</h2>, | ||
params: { lang: 'en' } | ||
}); | ||
render(layout); | ||
|
||
const testChildren = await screen.findByRole('heading'); | ||
const header = await screen.findByRole('banner'); | ||
const nav = await screen.findByRole('navigation'); | ||
const footer = await screen.findByRole('contentinfo'); | ||
// Assert | ||
|
||
expect(testChildren).toHaveTextContent(testText); | ||
expect(header).toBeInTheDocument(); | ||
expect(nav).toBeInTheDocument(); | ||
expect(footer).toBeInTheDocument(); | ||
}); | ||
|
||
it('should generate correct metadata', async () => { | ||
// Arrange | ||
const metadata = await generateMetadata({ | ||
params: { lang: 'en' }, | ||
}); | ||
// Assert | ||
expect(metadata).toBeTruthy(); | ||
}); | ||
|
||
it('should generate correct static params', async () => { | ||
// Arrange | ||
const staticParams = await generateStaticParams(); | ||
const expected = locales.map(lang => ({ lang })); | ||
// Assert | ||
expect(staticParams).toStrictEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 1 addition & 5 deletions
6
src/app/[lang]/__tests__/page.test.tsx → tests/app/[lang]/page.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,23 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import en from '~/i18n/locales/en'; | ||
import Page, { generateMetadata } from '../page'; | ||
import Page, { generateMetadata } from '@/app/[lang]/page'; | ||
|
||
jest.mock('@/utils/mdx', () => ({ | ||
getAllDataFrontmatter: () => [], | ||
})); | ||
|
||
describe('Root page component', () => { | ||
it('should render correct element', async () => { | ||
// Arrange | ||
const page = await Page({ params: { lang: 'en' } }); | ||
render(page); | ||
const heading = await screen.findByRole('heading', { level: 1 }); | ||
// Assert | ||
expect(heading).toBeInTheDocument(); | ||
}); | ||
|
||
it('should generate correct metadata', async () => { | ||
// Arrange | ||
const metadata = await generateMetadata({ | ||
params: { lang: 'en' }, | ||
}); | ||
// Assert | ||
expect(metadata).toStrictEqual({ title: en.common.home }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.