mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-15 12:03:46 +00:00
Add more accessibility tests
This commit is contained in:
@@ -3,13 +3,14 @@ import { fromPartial } from '@total-typescript/shoehorn';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import type { ServerWithId } from '../../src/servers/data';
|
||||
import { ServersListGroup } from '../../src/servers/ServersListGroup';
|
||||
import { checkAccessibility } from '../__helpers__/accessibility';
|
||||
|
||||
describe('<ServersListGroup />', () => {
|
||||
const servers: ServerWithId[] = [
|
||||
fromPartial({ name: 'foo', id: '123' }),
|
||||
fromPartial({ name: 'bar', id: '456' }),
|
||||
];
|
||||
const setUp = (params: { servers?: ServerWithId[]; withChildren?: boolean; embedded?: boolean }) => {
|
||||
const setUp = (params: { servers?: ServerWithId[]; withChildren?: boolean; embedded?: boolean } = {}) => {
|
||||
const { servers = [], withChildren = true, embedded } = params;
|
||||
|
||||
return render(
|
||||
@@ -21,14 +22,16 @@ describe('<ServersListGroup />', () => {
|
||||
);
|
||||
};
|
||||
|
||||
it('passes a11y checks', () => checkAccessibility(setUp()));
|
||||
|
||||
it('renders title', () => {
|
||||
setUp({});
|
||||
expect(screen.getByRole('heading')).toHaveTextContent('The list of servers');
|
||||
expect(screen.getByTestId('title')).toHaveTextContent('The list of servers');
|
||||
});
|
||||
|
||||
it('does not render title when children is not provided', () => {
|
||||
setUp({ withChildren: false });
|
||||
expect(screen.queryByRole('heading')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('title')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it.each([
|
||||
@@ -37,7 +40,7 @@ describe('<ServersListGroup />', () => {
|
||||
])('shows servers list', (servers) => {
|
||||
setUp({ servers });
|
||||
|
||||
expect(screen.queryAllByRole('list')).toHaveLength(servers.length ? 1 : 0);
|
||||
expect(screen.queryAllByTestId('list')).toHaveLength(servers.length ? 1 : 0);
|
||||
expect(screen.queryAllByRole('link')).toHaveLength(servers.length);
|
||||
});
|
||||
|
||||
@@ -47,6 +50,6 @@ describe('<ServersListGroup />', () => {
|
||||
[undefined, 'servers-list__list-group'],
|
||||
])('renders proper classes for embedded', (embedded, expectedClasses) => {
|
||||
setUp({ servers, embedded });
|
||||
expect(screen.getByRole('list')).toHaveAttribute('class', `${expectedClasses} list-group`);
|
||||
expect(screen.getByTestId('list')).toHaveAttribute('class', `${expectedClasses} list-group`);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user