docbrown/app/javascript/article-form/components/__tests__/PageTitle.test.jsx
Viviane Dias 27373c6cf8
Improves UI unit tests by correcting wrong use of queries (#17599)
* test(cover-image): uses correct queries for ui unit tests

* test(form): replaces queries to getByRole and adds expect where necessary

* feat(help): adds expect assert and uses within to test inside specific block

* feat(image-uploader): uses correct queries to validate behaviour

* test: corrects queries and adds expect assertions to some unit tests
2022-05-09 14:23:56 +01:00

66 lines
1.6 KiB
JavaScript

import { h } from 'preact';
import { render } from '@testing-library/preact';
import { axe } from 'jest-axe';
import { PageTitle } from '../PageTitle';
import '@testing-library/jest-dom';
let organizations, organizationId, onToggle;
describe('<PageTitle/>', () => {
beforeEach(() => {
organizations = [
{
id: 4,
bg_color_hex: '',
name: 'DEV',
text_color_hex: '',
profile_image_90:
'/uploads/organization/profile_image/4/1689e7ae-6306-43cd-acba-8bde7ed80a17.JPG',
},
];
organizationId = null;
onToggle = null;
});
it('should have no a11y violations', async () => {
const { container } = render(
<PageTitle
organizations={organizations}
organizationId={organizationId}
onToggle={onToggle}
/>,
);
const results = await axe(container);
expect(results).toHaveNoViolations();
});
it('shows the picker if there is more than one organisation', () => {
const { getByRole } = render(
<PageTitle
organizations={organizations}
organizationId={organizationId}
onToggle={onToggle}
/>,
);
expect(
getByRole('combobox', { name: /select an organization/i }),
).toBeInTheDocument();
});
it('does not show the picker if there is no organisations', () => {
const { queryByRole } = render(
<PageTitle
organizations={[]}
organizationId={organizationId}
onToggle={onToggle}
/>,
);
expect(
queryByRole('combobox', { name: /select an organization/i }),
).not.toBeInTheDocument();
});
});