Skip to content

Commit

Permalink
Merge pull request #184 from nr2f1/unit-tests
Browse files Browse the repository at this point in the history
Unit tests
  • Loading branch information
pataruco authored Jan 31, 2025
2 parents 8b42177 + 891e005 commit 10c79c4
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
26 changes: 26 additions & 0 deletions website/src/components/accordion/index.test.tsx
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();
});
});
32 changes: 32 additions & 0 deletions website/src/components/footer/dropdown.test.tsx
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);
});
});
});
12 changes: 12 additions & 0 deletions website/src/components/footer/social-media-links.test.tsx
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();
});
});

0 comments on commit 10c79c4

Please sign in to comment.