-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stanislav Lysak
committed
Dec 4, 2024
1 parent
a8f7dfe
commit 441f2af
Showing
4 changed files
with
132 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { changeLanguageMock, fireEvent, mockSupportedLngs, render, screen } from '@app/test-utils' | ||
|
||
import { describe, expect, it, vi } from 'vitest' | ||
|
||
import LanguageMenu from './LanguageMenu' | ||
|
||
vi.mock('iso-639-1', () => ({ | ||
default: { | ||
getNativeName: (lang: string) => `Native Name of ${lang}`, // Return a mocked native name | ||
}, | ||
})) | ||
|
||
describe('LanguageMenu', () => { | ||
it('renders the supported languages in sorted order', () => { | ||
const setCurrentViewMock = vi.fn() | ||
|
||
render(<LanguageMenu setCurrentView={setCurrentViewMock} />) | ||
|
||
mockSupportedLngs | ||
.filter((lang) => lang && lang !== 'cimode') | ||
.forEach((lang) => { | ||
expect(screen.getByTestId(`lang-${lang}`)).toBeInTheDocument() | ||
expect(screen.getByText(`Native Name of ${lang}`)).toBeInTheDocument() | ||
expect(screen.getByText(lang.toLocaleUpperCase())).toBeInTheDocument() | ||
}) | ||
|
||
expect(screen.queryByTestId('lang-cimode')).not.toBeInTheDocument() | ||
}) | ||
|
||
it('changes the language when a language item is clicked', () => { | ||
const setCurrentViewMock = vi.fn() | ||
|
||
render(<LanguageMenu setCurrentView={setCurrentViewMock} />) | ||
|
||
const frenchLanguageItem = screen.getByTestId('lang-fr') | ||
fireEvent.click(frenchLanguageItem) | ||
|
||
expect(changeLanguageMock).toHaveBeenCalledWith('fr') | ||
}) | ||
|
||
it('calls setCurrentView with "main" when the heading is clicked', () => { | ||
const setCurrentViewMock = vi.fn() | ||
|
||
render(<LanguageMenu setCurrentView={setCurrentViewMock} />) | ||
const frenchLanguageItem = screen.getByTestId('lang-header') | ||
fireEvent.click(frenchLanguageItem) | ||
|
||
expect(setCurrentViewMock).toHaveBeenCalledWith('main') | ||
}) | ||
|
||
it('shows the active language with a check icon', () => { | ||
const setCurrentViewMock = vi.fn() | ||
|
||
render(<LanguageMenu setCurrentView={setCurrentViewMock} />) | ||
|
||
const activeIcon = screen.getByTestId('check-lang-en') | ||
expect(activeIcon).toHaveStyle({ display: 'block' }) | ||
|
||
const inactiveIcon = screen.getByTestId('check-lang-fr') | ||
expect(inactiveIcon).toHaveStyle({ display: 'none' }) | ||
}) | ||
}) |
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
52 changes: 52 additions & 0 deletions
52
src/components/@molecules/VerificationBadge/VerificationBadge.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,52 @@ | ||
import { render, screen } from '@app/test-utils' | ||
|
||
import { describe, expect, it } from 'vitest' | ||
|
||
import { VerificationBadge } from './VerificationBadge' | ||
|
||
describe('VerificationBadge', () => { | ||
it('should render with with badge', () => { | ||
render( | ||
<VerificationBadge showBadge={true} type="record"> | ||
<div></div> | ||
</VerificationBadge>, | ||
) | ||
expect(screen.getByTestId('verification-badge-record')).toBeInTheDocument() | ||
}) | ||
|
||
it('should render with without badge', () => { | ||
render( | ||
<VerificationBadge showBadge={false} type="record"> | ||
<div></div> | ||
</VerificationBadge>, | ||
) | ||
expect(screen.queryByTestId('verification-badge-record')).not.toBeInTheDocument() | ||
}) | ||
|
||
it('should render with alert svg', () => { | ||
render( | ||
<VerificationBadge isVerified={false} showBadge={true} type="record"> | ||
<div></div> | ||
</VerificationBadge>, | ||
) | ||
expect(screen.getByTestId('verification-badge-error-icon')).toBeInTheDocument() | ||
}) | ||
|
||
it('should render with verified svg', () => { | ||
render( | ||
<VerificationBadge isVerified={true} showBadge={true} type="record"> | ||
<div></div> | ||
</VerificationBadge>, | ||
) | ||
expect(screen.getByTestId('verification-badge-record-icon')).toBeInTheDocument() | ||
}) | ||
|
||
it('should render with personhood svg', () => { | ||
render( | ||
<VerificationBadge isVerified={true} showBadge={true} type="personhood"> | ||
<div></div> | ||
</VerificationBadge>, | ||
) | ||
expect(screen.getByTestId('verification-badge-person-icon')).toBeInTheDocument() | ||
}) | ||
}) |
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