-
-
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.
Merge pull request #6552 from marmelab/simplelist-recordcontext
Add record context in SimpleList
- Loading branch information
Showing
3 changed files
with
166 additions
and
61 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
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,52 @@ | ||
import * as React from 'react'; | ||
import { render, waitFor, within } from '@testing-library/react'; | ||
import { createMemoryHistory } from 'history'; | ||
import { Router } from 'react-router-dom'; | ||
import { ListContext } from 'ra-core'; | ||
|
||
import SimpleList from './SimpleList'; | ||
import TextField from '../field/TextField'; | ||
|
||
const renderWithRouter = children => { | ||
const history = createMemoryHistory(); | ||
|
||
return { | ||
history, | ||
...render(<Router history={history}>{children}</Router>), | ||
}; | ||
}; | ||
|
||
describe('<SimpleList />', () => { | ||
it('should render a list of items which provide a record context', async () => { | ||
const { getByText } = renderWithRouter( | ||
<ListContext.Provider | ||
value={{ | ||
loaded: true, | ||
loading: false, | ||
ids: [1, 2], | ||
data: { | ||
1: { id: 1, title: 'foo' }, | ||
2: { id: 2, title: 'bar' }, | ||
}, | ||
total: 2, | ||
resource: 'posts', | ||
basePath: '/posts', | ||
}} | ||
> | ||
<SimpleList | ||
primaryText={record => record.id.toString()} | ||
secondaryText={<TextField source="title" />} | ||
/> | ||
</ListContext.Provider> | ||
); | ||
|
||
await waitFor(() => { | ||
expect( | ||
within(getByText('1').closest('li')).queryByText('foo') | ||
).not.toBeNull(); | ||
expect( | ||
within(getByText('2').closest('li')).queryByText('bar') | ||
).not.toBeNull(); | ||
}); | ||
}); | ||
}); |
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