-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathReferenceOneFieldBase.spec.tsx
More file actions
74 lines (66 loc) · 2.68 KB
/
ReferenceOneFieldBase.spec.tsx
File metadata and controls
74 lines (66 loc) · 2.68 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import * as React from 'react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import {
Basic,
Loading,
Offline,
WithRenderProp,
} from './ReferenceOneFieldBase.stories';
describe('ReferenceOneFieldBase', () => {
it('should pass the loading state', async () => {
jest.spyOn(console, 'error')
.mockImplementationOnce(() => {})
.mockImplementationOnce(() => {});
render(<Loading />);
await waitFor(() => {
expect(screen.queryByText('Loading...')).not.toBeNull();
});
});
it('should render the data', async () => {
render(<Basic />);
await waitFor(() => {
expect(screen.queryByText('9780393966473')).not.toBeNull();
});
});
describe('with render prop', () => {
it('should pass the loading state', async () => {
jest.spyOn(console, 'error')
.mockImplementationOnce(() => {})
.mockImplementationOnce(() => {});
const dataProviderWithAuthorsLoading = {
getOne: () =>
Promise.resolve({
data: {
id: 1,
title: 'War and Peace',
author: 1,
summary:
"War and Peace broadly focuses on Napoleon's invasion of Russia, and the impact it had on Tsarist society. The book explores themes such as revolution, revolution and empire, the growth and decline of various states and the impact it had on their economies, culture, and society.",
year: 1869,
},
}),
getMany: _resource => new Promise(() => {}),
} as any;
render(
<WithRenderProp dataProvider={dataProviderWithAuthorsLoading} />
);
await waitFor(() => {
expect(screen.queryByText('Loading...')).not.toBeNull();
});
});
it('should render the data', async () => {
render(<WithRenderProp />);
await waitFor(() => {
expect(screen.queryByText('9780393966473')).not.toBeNull();
});
});
});
it('should render the offline prop node when offline', async () => {
render(<Offline />);
fireEvent.click(await screen.findByText('Simulate offline'));
fireEvent.click(await screen.findByText('Toggle Child'));
await screen.findByText('Offline');
fireEvent.click(await screen.findByText('Simulate online'));
await screen.findByText('9780393966473');
});
});