-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathReferenceOneField.spec.tsx
51 lines (47 loc) · 1.66 KB
/
ReferenceOneField.spec.tsx
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
import * as React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import {
RecordRepresentation,
Basic,
EmptyWithTranslate,
QueryOptions,
} from './ReferenceOneField.stories';
describe('ReferenceOneField', () => {
it('should render the recordRepresentation of the related record', async () => {
render(<RecordRepresentation />);
await screen.findByText('Genre: novel, ISBN: 9780393966473');
});
it('should render its child in the context of the related record', async () => {
render(<Basic />);
await screen.findByText('9780393966473');
});
it('should translate emptyText', async () => {
render(<EmptyWithTranslate />);
await screen.findByText('Not found');
});
it('should accept a queryOptions prop', async () => {
const dataProvider = {
getManyReference: jest.fn().mockImplementationOnce(() =>
Promise.resolve({
data: [{ id: 1, ISBN: '9780393966473', genre: 'novel' }],
total: 1,
})
),
};
render(<QueryOptions dataProvider={dataProvider} />);
await waitFor(() => {
expect(dataProvider.getManyReference).toHaveBeenCalledWith(
'book_details',
{
id: 1,
target: 'book_id',
sort: { field: 'id', order: 'ASC' },
pagination: { page: 1, perPage: 1 },
filter: {},
meta: { foo: 'bar' },
signal: undefined,
}
);
});
});
});