forked from marmelab/react-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
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
3cb06df
commit d59d2ba
Showing
7 changed files
with
138 additions
and
33 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,50 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { createStore } from 'redux'; | ||
import { Provider } from 'react-redux'; | ||
import { reducer as formReducer } from 'redux-form'; | ||
import { TranslationProvider } from 'ra-core'; | ||
import merge from 'lodash/merge'; | ||
|
||
const defaultStore = { | ||
admin: { | ||
resources: {}, | ||
references: { possibleValues: {} }, | ||
ui: { viewVersion: 1 }, | ||
}, | ||
form: formReducer(), | ||
i18n: { locale: 'en', messages: {} }, | ||
}; | ||
|
||
/** | ||
* Simulate a react-admin context in unit tests | ||
* | ||
* Pass custom store values as store prop | ||
* | ||
* @example | ||
* // in an enzyme test | ||
* const wrapper = render( | ||
* <AdminContext store={{ admin: { resources: { post: { data: { 1: {id: 1, title: 'foo' } } } } } }}> | ||
* <Show {...defaultShowProps} /> | ||
* </AdminContext> | ||
* ); | ||
*/ | ||
const TestContext = ({ store, children }) => { | ||
const storeWithDefault = createStore(() => merge(store, defaultStore)); | ||
return ( | ||
<Provider store={storeWithDefault}> | ||
<TranslationProvider>{children}</TranslationProvider> | ||
</Provider> | ||
); | ||
}; | ||
|
||
TestContext.propTypes = { | ||
store: PropTypes.object, | ||
children: PropTypes.node, | ||
}; | ||
|
||
TestContext.defaultProps = { | ||
store: {}, | ||
}; | ||
|
||
export default TestContext; |
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
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,28 @@ | ||
import React from 'react'; | ||
import { render } from 'enzyme'; | ||
import { TestContext } from 'ra-core'; | ||
|
||
import { Edit } from './Edit'; | ||
|
||
describe('<Edit />', () => { | ||
const defaultEditProps = { | ||
basePath: '/', | ||
id: '123', | ||
resource: 'foo', | ||
location: {}, | ||
match: {}, | ||
}; | ||
|
||
it('should display aside component', () => { | ||
const Aside = () => <div id="aside">Hello</div>; | ||
const wrapper = render( | ||
<TestContext> | ||
<Edit {...defaultEditProps} aside={<Aside />}> | ||
<div /> | ||
</Edit> | ||
</TestContext> | ||
); | ||
const aside = wrapper.find('#aside'); | ||
expect(aside.text()).toEqual('Hello'); | ||
}); | ||
}); |
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,28 @@ | ||
import React from 'react'; | ||
import { render } from 'enzyme'; | ||
import { TestContext } from 'ra-core'; | ||
|
||
import { Show } from './Show'; | ||
|
||
describe('<Show />', () => { | ||
const defaultShowProps = { | ||
basePath: '/', | ||
id: '123', | ||
resource: 'foo', | ||
location: {}, | ||
match: {}, | ||
}; | ||
|
||
it('should display aside component', () => { | ||
const Aside = () => <div id="aside">Hello</div>; | ||
const wrapper = render( | ||
<TestContext> | ||
<Show {...defaultShowProps} aside={<Aside />}> | ||
<div /> | ||
</Show> | ||
</TestContext> | ||
); | ||
const aside = wrapper.find('#aside'); | ||
expect(aside.text()).toEqual('Hello'); | ||
}); | ||
}); |
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