-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0131ba
commit ddd8449
Showing
6 changed files
with
306 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as React from 'react'; | ||
import expect from 'expect'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { CoreAdminContext } from 'ra-core'; | ||
|
||
import { EditGuesser } from './EditGuesser'; | ||
import { ThemeProvider } from '../layout'; | ||
|
||
describe('<EditGuesser />', () => { | ||
it('should log the guessed Edit view based on the fetched record', async () => { | ||
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); | ||
const dataProvider = { | ||
getOne: () => | ||
Promise.resolve({ | ||
data: { | ||
id: 123, | ||
author: 'john doe', | ||
post_id: 6, | ||
score: 3, | ||
body: | ||
"Queen, tossing her head through the wood. 'If it had lost something; and she felt sure it.", | ||
created_at: new Date('2012-08-02'), | ||
}, | ||
}), | ||
getMany: () => Promise.resolve({ data: [] }), | ||
}; | ||
render( | ||
<ThemeProvider theme={{}}> | ||
<CoreAdminContext dataProvider={dataProvider as any}> | ||
<EditGuesser resource="comments" id={123} /> | ||
</CoreAdminContext> | ||
</ThemeProvider> | ||
); | ||
await waitFor(() => { | ||
screen.getByDisplayValue('john doe'); | ||
}); | ||
expect(logSpy).toHaveBeenCalledWith(`Guessed Edit: | ||
import { DateInput, Edit, NumberInput, ReferenceInput, SelectInput, SimpleForm, TextInput } from 'react-admin'; | ||
export const CommentEdit = () => ( | ||
<Edit> | ||
<SimpleForm> | ||
<TextInput source="id" /> | ||
<TextInput source="author" /> | ||
<ReferenceInput source="post_id" reference="posts"><SelectInput optionText="id" /></ReferenceInput> | ||
<NumberInput source="score" /> | ||
<TextInput source="body" /> | ||
<DateInput source="created_at" /> | ||
</SimpleForm> | ||
</Edit> | ||
);`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as React from 'react'; | ||
import expect from 'expect'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { CoreAdminContext } from 'ra-core'; | ||
|
||
import { ShowGuesser } from './ShowGuesser'; | ||
import { ThemeProvider } from '../layout'; | ||
|
||
describe('<ShowGuesser />', () => { | ||
it('should log the guessed Show view based on the fetched record', async () => { | ||
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); | ||
const dataProvider = { | ||
getOne: () => | ||
Promise.resolve({ | ||
data: { | ||
id: 123, | ||
author: 'john doe', | ||
post_id: 6, | ||
score: 3, | ||
body: | ||
"Queen, tossing her head through the wood. 'If it had lost something; and she felt sure it.", | ||
created_at: new Date('2012-08-02'), | ||
}, | ||
}), | ||
}; | ||
render( | ||
<ThemeProvider theme={{}}> | ||
<CoreAdminContext dataProvider={dataProvider as any}> | ||
<ShowGuesser resource="comments" id={123} /> | ||
</CoreAdminContext> | ||
</ThemeProvider> | ||
); | ||
await waitFor(() => { | ||
screen.getByText('john doe'); | ||
}); | ||
expect(logSpy).toHaveBeenCalledWith(`Guessed Show: | ||
import { DateField, NumberField, ReferenceField, Show, SimpleShowLayout, TextField } from 'react-admin'; | ||
export const CommentShow = () => ( | ||
<Show> | ||
<SimpleShowLayout> | ||
<TextField source="id" /> | ||
<TextField source="author" /> | ||
<ReferenceField source="post_id" reference="posts"><TextField source="id" /></ReferenceField> | ||
<NumberField source="score" /> | ||
<TextField source="body" /> | ||
<DateField source="created_at" /> | ||
</SimpleShowLayout> | ||
</Show> | ||
);`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as React from 'react'; | ||
import expect from 'expect'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { CoreAdminContext } from 'ra-core'; | ||
|
||
import { ListGuesser } from './ListGuesser'; | ||
import { ThemeProvider } from '../layout'; | ||
|
||
describe('<ListGuesser />', () => { | ||
it('should log the guessed List view based on the fetched records', async () => { | ||
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); | ||
const dataProvider = { | ||
getList: () => | ||
Promise.resolve({ | ||
data: [ | ||
{ | ||
id: 123, | ||
author: 'john doe', | ||
post_id: 6, | ||
score: 3, | ||
body: | ||
"Queen, tossing her head through the wood. 'If it had lost something; and she felt sure it.", | ||
created_at: new Date('2012-08-02'), | ||
}, | ||
], | ||
total: 1, | ||
}), | ||
}; | ||
render( | ||
<ThemeProvider theme={{}}> | ||
<CoreAdminContext dataProvider={dataProvider as any}> | ||
<ListGuesser resource="comments" /> | ||
</CoreAdminContext> | ||
</ThemeProvider> | ||
); | ||
await waitFor(() => { | ||
screen.getByText('john doe'); | ||
}); | ||
expect(logSpy).toHaveBeenCalledWith(`Guessed List: | ||
import { Datagrid, DateField, List, NumberField, ReferenceField, TextField } from 'react-admin'; | ||
export const CommentList = () => ( | ||
<List> | ||
<Datagrid rowClick="edit"> | ||
<TextField source="id" /> | ||
<TextField source="author" /> | ||
<ReferenceField source="post_id" reference="posts"><TextField source="id" /></ReferenceField> | ||
<NumberField source="score" /> | ||
<TextField source="body" /> | ||
<DateField source="created_at" /> | ||
</Datagrid> | ||
</List> | ||
);`); | ||
}); | ||
}); |
Oops, something went wrong.