-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathReferenceArrayInputBase.spec.tsx
More file actions
54 lines (49 loc) · 1.98 KB
/
ReferenceArrayInputBase.spec.tsx
File metadata and controls
54 lines (49 loc) · 1.98 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 * as React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { testDataProvider } from 'ra-core';
import { Basic, WithError } from './ReferenceArrayInputBase.stories';
describe('<ReferenceArrayInputBase>', () => {
afterEach(async () => {
// wait for the getManyAggregate batch to resolve
await waitFor(() => new Promise(resolve => setTimeout(resolve, 0)));
});
it('should pass down the error if any occurred', async () => {
jest.spyOn(console, 'error').mockImplementation(() => {});
render(<WithError />);
await waitFor(() => {
expect(screen.queryByText('Error: fetch error')).not.toBeNull();
});
});
it('should pass the correct resource down to child component', async () => {
render(<Basic />);
// Check that the child component receives the correct resource (tags)
await screen.findByText('Selected tags: 1, 3');
});
it('should provide a ChoicesContext with all available choices', async () => {
render(<Basic />);
await screen.findByText('Total tags: 5');
});
it('should apply default values', async () => {
render(<Basic />);
// Check that the default values are applied (1, 3)
await screen.findByText('Selected tags: 1, 3');
});
it('should accept meta in queryOptions', async () => {
const getList = jest
.fn()
.mockImplementationOnce(() =>
Promise.resolve({ data: [], total: 25 })
);
const dataProvider = testDataProvider({ getList });
render(<Basic meta dataProvider={dataProvider} />);
await waitFor(() => {
expect(getList).toHaveBeenCalledWith('tags', {
filter: {},
pagination: { page: 1, perPage: 25 },
sort: { field: 'id', order: 'DESC' },
meta: { foo: 'bar' },
signal: undefined,
});
});
});
});