Add test for getComponent() and mapStateToProps in a container component

This commit is contained in:
Owen Conti
2017-08-14 18:44:26 -06:00
parent d9b0632d16
commit d9918f9f31

View File

@@ -1,7 +1,11 @@
/* eslint-env mocha */
import React, { PureComponent } from "react"
import expect from "expect"
import System from "core/system"
import { fromJS } from "immutable"
import { render } from "enzyme"
import ViewPlugin from "core/plugins/view/index.js"
import { connect, Provider } from "react-redux"
describe("bound system", function(){
@@ -444,4 +448,66 @@ describe("bound system", function(){
})
describe("getComponent", function() {
it("returns a component from the system", function() {
const system = new System({
plugins: [
ViewPlugin,
{
components: {
test: ({ name }) => <div>{name} component</div>
}
}
]
})
// When
var Component = system.getSystem().getComponent("test")
const renderedComponent = render(<Component name="Test" />)
expect(renderedComponent.text()).toEqual("Test component")
})
it("allows container components to provide their own `mapStateToProps` function", function() {
// Given
class ContainerComponent extends PureComponent {
static mapStateToProps(nextState, props) {
return {
"abc": "This came from mapStateToProps"
}
}
static defaultProps = {
"abc" : ""
}
render() {
return (
<div>{ this.props.abc }</div>
)
}
}
const system = new System({
plugins: [
ViewPlugin,
{
components: {
ContainerComponent
}
}
]
})
// When
var Component = system.getSystem().getComponent("ContainerComponent", true)
const renderedComponent = render(
<Provider store={system.getStore()}>
<Component />
</Provider>
)
// Then
expect(renderedComponent.text()).toEqual("This came from mapStateToProps")
})
})
})