This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(createIndex): support root as props * refactor(createIndex): rewrite as a functionnal component * feat(stories): add Index with custom root * fix(createInstantSearch): really test the root prop * docs(Index): add root
- Loading branch information
Showing
7 changed files
with
134 additions
and
59 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
31 changes: 24 additions & 7 deletions
31
packages/react-instantsearch/src/core/__snapshots__/createIndex.test.js.snap
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 |
---|---|---|
@@ -1,11 +1,28 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`createIndex expect to create Index with a custom root props 1`] = ` | ||
<Index | ||
indexName="name" | ||
root={ | ||
Object { | ||
"Root": "span", | ||
"props": Object { | ||
"style": Object { | ||
"flex": 1, | ||
}, | ||
}, | ||
} | ||
} | ||
/> | ||
`; | ||
|
||
exports[`createIndex wraps Index 1`] = ` | ||
Object { | ||
"children": undefined, | ||
"indexName": "name", | ||
"root": Object { | ||
"Root": "div", | ||
}, | ||
} | ||
<Index | ||
indexName="name" | ||
root={ | ||
Object { | ||
"Root": "div", | ||
} | ||
} | ||
/> | ||
`; |
23 changes: 23 additions & 0 deletions
23
packages/react-instantsearch/src/core/__snapshots__/createInstantSearch.test.js.snap
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 |
---|---|---|
@@ -1,29 +1,34 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import React, { Component } from 'react'; | ||
import Index from './Index'; | ||
|
||
/** | ||
* Creates a specialized root Index component. It accepts | ||
* a specification of the root Element. | ||
* @param {object} root - the defininition of the root of an Index sub tree. | ||
* @returns {object} a Index root | ||
* @param {object} defaultRoot - the defininition of the root of an Index sub tree. | ||
* @return {object} a Index root | ||
*/ | ||
export default function createIndex(root) { | ||
return class CreateIndex extends Component { | ||
static propTypes = { | ||
children: PropTypes.oneOfType([ | ||
PropTypes.arrayOf(PropTypes.node), | ||
PropTypes.node, | ||
]), | ||
indexName: PropTypes.string.isRequired, | ||
}; | ||
const createIndex = defaultRoot => { | ||
const CreateIndex = ({ indexName, root, children }) => ( | ||
<Index indexName={indexName} root={root}> | ||
{children} | ||
</Index> | ||
); | ||
|
||
render() { | ||
return ( | ||
<Index indexName={this.props.indexName} root={root}> | ||
{this.props.children} | ||
</Index> | ||
); | ||
} | ||
CreateIndex.propTypes = { | ||
indexName: PropTypes.string.isRequired, | ||
root: PropTypes.shape({ | ||
Root: PropTypes.oneOfType([PropTypes.string, PropTypes.func]).isRequired, | ||
props: PropTypes.object, | ||
}), | ||
children: PropTypes.node, | ||
}; | ||
} | ||
|
||
CreateIndex.defaultProps = { | ||
root: defaultRoot, | ||
}; | ||
|
||
return CreateIndex; | ||
}; | ||
|
||
export default createIndex; |
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 |
---|---|---|
@@ -1,19 +1,34 @@ | ||
/* eslint-env jest, jasmine */ | ||
/* eslint-disable no-console */ | ||
import React from 'react'; | ||
import Enzyme, { shallow } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
import createIndex from './createIndex'; | ||
import Index from './Index'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
describe('createIndex', () => { | ||
const CustomIndex = createIndex({ Root: 'div' }); | ||
|
||
it('wraps Index', () => { | ||
const wrapper = shallow(<CustomIndex indexName="name" />); | ||
expect(wrapper.is(Index)).toBe(true); | ||
expect(wrapper.props()).toMatchSnapshot(); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
it('expect to create Index with a custom root props', () => { | ||
const root = { | ||
Root: 'span', | ||
props: { | ||
style: { | ||
flex: 1, | ||
}, | ||
}, | ||
}; | ||
|
||
const wrapper = shallow(<CustomIndex indexName="name" root={root} />); | ||
|
||
expect(wrapper.is(Index)).toBe(true); | ||
expect(wrapper.props().root).toEqual(root); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
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