-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathManifestForm.test.jsx
More file actions
54 lines (43 loc) · 1.84 KB
/
ManifestForm.test.jsx
File metadata and controls
54 lines (43 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import { ManifestForm } from '../../../src/components/ManifestForm';
/** create wrapper */
function createWrapper(props) {
return render(
<ManifestForm
addResource={() => {}}
{...props}
/>,
);
}
describe('ManifestForm', () => {
it('renders nothing if it is not open', () => {
createWrapper({ addResourcesOpen: false });
expect(screen.queryByRole('textbox', { name: 'Resource location' })).not.toBeInTheDocument();
});
it('renders the form fields', () => {
createWrapper({ addResourcesOpen: true });
expect(screen.getByRole('textbox', { name: 'Resource location' })).toBeInTheDocument();
expect(screen.getByRole('button')).toHaveAttribute('type', 'submit');
});
it('has a cancel button when a cancel action is provided', async () => {
const user = userEvent.setup();
const onCancel = vi.fn();
createWrapper({ addResourcesOpen: true, onCancel });
await user.type(screen.getByRole('textbox', { name: 'Resource location' }), 'asdf');
await user.click(screen.getByRole('button', { name: 'Cancel' }));
expect(onCancel).toHaveBeenCalled();
expect(screen.getByRole('textbox')).toHaveValue('');
});
it('triggers an action when the form is submitted', async () => {
const user = userEvent.setup();
const addResource = vi.fn();
const onSubmit = vi.fn();
createWrapper({ addResource, addResourcesOpen: true, onSubmit });
await user.type(screen.getByRole('textbox', { name: 'Resource location' }), 'http://example.com/iiif');
await user.click(screen.getByRole('button', { name: 'Add' }));
expect(addResource).toHaveBeenCalledWith('http://example.com/iiif');
expect(onSubmit).toHaveBeenCalled();
expect(screen.getByRole('textbox')).toHaveValue('');
});
});