-
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 #184 from nr2f1/unit-tests
Unit tests
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 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,26 @@ | ||
import { render, waitFor } from '@testing-library/react'; | ||
import axe from '@tests/a11y/test-utils'; | ||
import { describe, expect, it } from 'vitest'; | ||
import Accordion from './index'; | ||
|
||
const TITLE = 'summary'; | ||
const Content = () => <p>Lorem Ipsum</p>; | ||
|
||
describe('accordion', () => { | ||
it('renders without any accessibility violation', async () => { | ||
const { container } = render( | ||
<Accordion title={TITLE} content={<Content />} />, | ||
); | ||
const results = await waitFor(() => axe(container), { timeout: 5000 }); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
|
||
it('renders copy', () => { | ||
const { getByText } = render( | ||
<Accordion title={TITLE} content={<Content />} />, | ||
); | ||
|
||
expect(getByText('Lorem Ipsum')).toBeInTheDocument(); | ||
expect(getByText(TITLE)).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { AVAILABLE_LOCALES_LABEL_KEYS } from '@i18n/locales'; | ||
import { render, screen, waitFor, within } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import axe from '@tests/a11y/test-utils'; | ||
import { describe, expect, it } from 'vitest'; | ||
import LocaleSelector from './dropdown'; | ||
|
||
const [es] = AVAILABLE_LOCALES_LABEL_KEYS; | ||
|
||
describe('accordion', () => { | ||
it('renders without any accessibility violation', async () => { | ||
const { container } = render(<LocaleSelector />); | ||
const results = await waitFor(() => axe(container), { timeout: 5000 }); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
|
||
it('allow selecting options', async () => { | ||
const { getByRole } = render(<LocaleSelector />); | ||
const user = userEvent.setup(); | ||
|
||
await user.pointer({ target: getByRole('combobox'), keys: '[MouseLeft]' }); | ||
|
||
const listbox = within(getByRole('listbox')); | ||
|
||
await user.click(listbox.getByText(new RegExp(es.label, 'i'))); | ||
|
||
await waitFor(() => { | ||
const hiddenInput = screen.getByRole('textbox', { hidden: true }); | ||
expect(hiddenInput).toHaveValue(es.value); | ||
}); | ||
}); | ||
}); |
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, waitFor } from '@testing-library/react'; | ||
import axe from '@tests/a11y/test-utils'; | ||
import { describe, expect, it } from 'vitest'; | ||
import SocialMediaLinks from './social-media-links'; | ||
|
||
describe('SocialMediaLinks', () => { | ||
it('renders without any accessibility violation', async () => { | ||
const { container } = render(<SocialMediaLinks />); | ||
const results = await waitFor(() => axe(container), { timeout: 5000 }); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |