|
1 | 1 | import * as React from 'react'; |
2 | 2 | import expect from 'expect'; |
3 | | -import { render, screen, waitFor } from '@testing-library/react'; |
4 | | -import { CoreAdminContext } from 'ra-core'; |
| 3 | +import { render, screen } from '@testing-library/react'; |
5 | 4 |
|
6 | | -import { EditGuesser } from './EditGuesser'; |
7 | | -import { ThemeProvider } from '../theme/ThemeProvider'; |
| 5 | +import { EditGuesser } from './EditGuesser.stories'; |
8 | 6 |
|
9 | 7 | describe('<EditGuesser />', () => { |
10 | 8 | it('should log the guessed Edit view based on the fetched record', async () => { |
11 | 9 | const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); |
12 | | - const dataProvider = { |
13 | | - getOne: () => |
14 | | - Promise.resolve({ |
15 | | - data: { |
16 | | - id: 123, |
17 | | - author: 'john doe', |
18 | | - post_id: 6, |
19 | | - score: 3, |
20 | | - body: "Queen, tossing her head through the wood. 'If it had lost something; and she felt sure it.", |
21 | | - created_at: new Date('2012-08-02'), |
22 | | - tags_ids: [1, 2], |
23 | | - }, |
24 | | - }), |
25 | | - getMany: () => Promise.resolve({ data: [] }), |
26 | | - }; |
27 | | - render( |
28 | | - <ThemeProvider> |
29 | | - <CoreAdminContext dataProvider={dataProvider as any}> |
30 | | - <EditGuesser resource="comments" id={123} enableLog /> |
31 | | - </CoreAdminContext> |
32 | | - </ThemeProvider> |
33 | | - ); |
34 | | - await waitFor(() => { |
35 | | - screen.getByDisplayValue('john doe'); |
36 | | - }); |
| 10 | + render(<EditGuesser />); |
| 11 | + await screen.findByDisplayValue('john doe'); |
37 | 12 | expect(logSpy).toHaveBeenCalledWith(`Guessed Edit: |
38 | 13 |
|
39 | | -import { DateInput, Edit, NumberInput, ReferenceArrayInput, ReferenceInput, SimpleForm, TextInput } from 'react-admin'; |
| 14 | +import { ArrayInput, BooleanInput, DateInput, Edit, NumberInput, ReferenceArrayInput, ReferenceInput, SimpleForm, SimpleFormIterator, TextArrayInput, TextInput } from 'react-admin'; |
40 | 15 |
|
41 | | -export const CommentEdit = () => ( |
| 16 | +export const BookEdit = () => ( |
42 | 17 | <Edit> |
43 | 18 | <SimpleForm> |
44 | 19 | <TextInput source="id" /> |
45 | | - <TextInput source="author" /> |
| 20 | + <ArrayInput source="authors"><SimpleFormIterator><TextInput source="id" /> |
| 21 | +<TextInput source="name" /> |
| 22 | +<DateInput source="dob" /></SimpleFormIterator></ArrayInput> |
46 | 23 | <ReferenceInput source="post_id" reference="posts" /> |
47 | 24 | <NumberInput source="score" /> |
48 | 25 | <TextInput source="body" /> |
| 26 | + <TextInput source="description" /> |
49 | 27 | <DateInput source="created_at" /> |
50 | 28 | <ReferenceArrayInput source="tags_ids" reference="tags" /> |
| 29 | + <TextInput source="url" /> |
| 30 | + <TextInput source="email" /> |
| 31 | + <BooleanInput source="isAlreadyPublished" /> |
| 32 | + <TextArrayInput source="genres" /> |
51 | 33 | </SimpleForm> |
52 | 34 | </Edit> |
53 | 35 | );`); |
|
0 commit comments