-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve team mamber card and add tests
- Loading branch information
1 parent
be59c1c
commit 758834e
Showing
7 changed files
with
135 additions
and
24 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/components/OptionalLinkWrapper/OptionalLinkWrapper.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { FC, ReactNode } from 'react' | ||
|
||
interface OptionalLinkWrapperProps { | ||
url?: string | ||
children: ReactNode | ||
} | ||
|
||
/** | ||
* If url is falsy, returns children. If url is truthy, returns the component wrapped in a link | ||
*/ | ||
const OptionalLinkWrapper: FC<OptionalLinkWrapperProps> = ({ url, children }) => { | ||
if (url) { | ||
return <a href={url} target='_blank' rel="noreferrer"> | ||
{children} | ||
</a> | ||
} | ||
return children | ||
} | ||
|
||
export default OptionalLinkWrapper |
33 changes: 33 additions & 0 deletions
33
src/components/OptionalLinkWrapper/__test__/OptionalLinkWrapper.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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { render } from '@/tests/customRender' | ||
import { screen } from '@testing-library/react' | ||
import OptionalLinkWrapper from '../OptionalLinkWrapper'; | ||
|
||
|
||
describe('OptionalLinkWrapper', () => { | ||
const exampleURL = 'https://example.com' | ||
|
||
it('should render the link when URL is set', async () => { | ||
render(<OptionalLinkWrapper url={exampleURL}> | ||
<span>child</span> | ||
</OptionalLinkWrapper>) | ||
|
||
const link = await screen.findByRole('link') | ||
expect(link).toHaveAttribute('href', exampleURL) | ||
|
||
const child = await screen.findByText('child') | ||
expect(child).toBeVisible() | ||
}) | ||
|
||
it.each(['', undefined])('should render the child component when URL is %i', async (url: string | undefined) => { | ||
render(<OptionalLinkWrapper url={url}> | ||
<span>child</span> | ||
</OptionalLinkWrapper>) | ||
|
||
const child = await screen.findByText('child') | ||
expect(child).toBeVisible() | ||
|
||
const link = screen.queryByRole('link') | ||
expect(link).toBeNull() | ||
}) | ||
}); |
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
48 changes: 48 additions & 0 deletions
48
src/components/TeamMemberCard/__team__/TeamMemberCard.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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { render } from '@/tests/customRender' | ||
import { screen } from '@testing-library/react' | ||
import TeamMemberCard from '../TeamMemberCard'; | ||
import TeamMember from '@/types/TeamMember'; | ||
import '@/i18n/config'; | ||
import i18next from 'i18next'; | ||
import { I18nextProvider } from 'react-i18next'; | ||
|
||
|
||
describe('TeamMemberCard', () => { | ||
const member = { | ||
nameEN: 'Alice', | ||
nameJA: 'アリス', | ||
titleEN: 'Lead', | ||
titleJA: 'リード', | ||
image: 'example.png', | ||
url: 'https://example.com' | ||
} as TeamMember | ||
|
||
it('should render a TeamMemberCard in English', async () => { | ||
render(<TeamMemberCard member={member} />) | ||
const name = await screen.findByText(member.nameEN) | ||
expect(name).toBeVisible() | ||
const title = await screen.findByText(member.titleEN) | ||
expect(title).toBeVisible() | ||
const link = await screen.findByRole('link') | ||
expect(link).toHaveAttribute('href', member.url) | ||
const image = await screen.findByRole('img') | ||
expect(image).toBeVisible() | ||
}) | ||
|
||
it('should render a TeamMemberCard in Japanese', async () => { | ||
await i18next.changeLanguage('ja') | ||
render(<I18nextProvider i18n={i18next}> | ||
<TeamMemberCard member={member} /> | ||
</I18nextProvider>) | ||
|
||
const name = await screen.findByText(member.nameJA) | ||
expect(name).toBeVisible() | ||
const title = await screen.findByText(member.titleJA) | ||
expect(title).toBeVisible() | ||
const link = await screen.findByRole('link') | ||
expect(link).toHaveAttribute('href', member.url) | ||
const image = await screen.findByRole('img') | ||
expect(image).toBeVisible() | ||
}) | ||
}); |
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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ type TeamMember = { | |
titleEN: string | ||
titleJA: string | ||
image: string | ||
url: string | ||
} | ||
|
||
export default TeamMember |