-
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.
Internationalization with App Router (v1)
- Loading branch information
1 parent
0eecf5c
commit 7c8e427
Showing
18 changed files
with
1,244 additions
and
1,168 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,49 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import Card from '../../src/components/Card'; | ||
|
||
describe('Card', () => { | ||
function setup() { | ||
const title = 'Regular card'; | ||
const href = '/card-href'; | ||
const linkText = 'Cool link text'; | ||
const tags = ['First tag', 'Second tag']; | ||
|
||
beforeEach(() => { | ||
render(<Card title={title} href={href} linkText={linkText} tags={tags} />); | ||
}); | ||
const utils = render( | ||
<Card title={title} href={href} linkText={linkText} tags={tags} />, | ||
); | ||
|
||
it('renders the card title', () => { | ||
const renderedTitle = screen.getByRole('heading'); | ||
expect(renderedTitle).toBeInTheDocument(); | ||
expect(renderedTitle).toHaveTextContent(title); | ||
}); | ||
return { | ||
...utils, | ||
title, | ||
href, | ||
linkText, | ||
tags, | ||
}; | ||
} | ||
|
||
it('renders the card link', () => { | ||
const renderedLink = screen.getByRole('link'); | ||
expect(renderedLink).toBeInTheDocument(); | ||
expect(renderedLink).toHaveTextContent(linkText); | ||
expect(renderedLink).toHaveAttribute('href', href); | ||
}); | ||
it('should render the card title with correct text', () => { | ||
const { getByRole, title } = setup(); | ||
const renderedTitle = getByRole('heading'); | ||
|
||
expect(renderedTitle).toBeVisible(); | ||
expect(renderedTitle).toHaveTextContent(title); | ||
}); | ||
|
||
it('should render the card link with correct text and href', () => { | ||
const { getByRole, linkText, href } = setup(); | ||
const renderedLink = getByRole('link'); | ||
|
||
expect(renderedLink).toBeVisible(); | ||
expect(renderedLink).toHaveTextContent(linkText); | ||
expect(renderedLink).toHaveAttribute('href', href); | ||
}); | ||
|
||
it('renders all card tags', () => { | ||
const renderedTags = screen.getAllByTestId('tag'); | ||
expect(renderedTags).toHaveLength(tags.length); | ||
it('should render all card tags with correct texts', () => { | ||
const { getAllByTestId, tags } = setup(); | ||
const renderedTags = getAllByTestId('tag'); | ||
|
||
renderedTags.forEach((tag, index) => { | ||
expect(tag).toHaveTextContent(tags[index]); | ||
}); | ||
expect(renderedTags).toHaveLength(tags.length); | ||
renderedTags.forEach((tag, index) => { | ||
expect(tag).toHaveTextContent(tags[index]); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import About from '../../src/app/[lang]/components/About'; | ||
import FeaturedProjects from '../../src/app/[lang]/components/FeaturedProjects'; | ||
|
||
describe('About me block', () => { | ||
beforeEach(() => { | ||
render(<About />); | ||
}); | ||
it('should redirect the "more about me" button to the about page', async () => { | ||
const { findByRole } = render(await About({ lang: 'en' })); | ||
|
||
test('read more redirects to the about page', () => { | ||
const anchor = screen.getByText('More about me'); | ||
expect(anchor).toHaveAttribute('href', '/about'); | ||
}); | ||
const anchor = await findByRole('link', { name: 'More about me' }); | ||
expect(anchor).toBeVisible(); | ||
expect(anchor).toHaveAttribute('href', '/en/about'); | ||
}); | ||
|
||
describe('Featured projects block', () => { | ||
beforeEach(() => { | ||
render(<FeaturedProjects />); | ||
}); | ||
it('should redirect the "see all projects" button to the projects page', async () => { | ||
const { findByRole } = render(await FeaturedProjects({ lang: 'en' })); | ||
|
||
test('see all projects redirects to the projects page', () => { | ||
const anchor = screen.getByText('See all projects'); | ||
const anchor = await findByRole('link', { name: 'See all projects' }); | ||
|
||
expect(anchor).toHaveAttribute('href', '/projects'); | ||
}); | ||
expect(anchor).toBeVisible(); | ||
expect(anchor).toHaveAttribute('href', '/en/projects'); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import Tag from '../../src/components/Tag'; | ||
|
||
it('should render the tag with correct text', () => { | ||
const tagLabel = 'Tag label'; | ||
const { getByTestId } = render(<Tag label={tagLabel} />); | ||
const tag = getByTestId('tag'); | ||
|
||
expect(tag).toBeVisible(); | ||
expect(tag).toHaveTextContent(tagLabel); | ||
}); |
Oops, something went wrong.