import * as React from "react";
import {mount} from "enzyme";
import {
fastClick, hasClass, jsxToHTML, printPrettyHtml
} from "../../../components/__test__/TestHelpers"
import {Panel} from "../../../components"
import {
renderComponent,
RenderComponentType,
RenderComponentPropType
} from "../../../"
describe("RenderComponent", ()=> {
beforeEach(()=> {
this.SubPanel = class SubPanel extends Panel {
}
this.SubPanel.defaultProps.title = "SubPanel"
this.SubPanelElement =
this.PanelReactClass = React.createClass({
contextTypes:{
color:React.PropTypes.string
},
render(){
return (
{this.props.children}
)
}
})
this.PanelFunction = (props, context)=> {
return (
{props.children}
)
}
this.PanelFunction.contextTypes = {
color:React.PropTypes.string
}
class Provider extends React.Component{
static childContextTypes = {
color: React.PropTypes.string
}
getChildContext(){
return {color:"purple"}
}
render(){
return this.props.children
}
}
this.mount = (component, props={})=> {
this.wrapper = mount(
{renderComponent(
component, props,
content..
)}
)
}
})
it("React.Component class", ()=> {
this.mount(this.SubPanel)
expect(this.wrapper.html()).toEqual(jsxToHTML(
))
})
it("React Element", ()=> {
this.mount(this.SubPanelElement)
expect(this.wrapper.html()).toEqual(jsxToHTML(
))
})
it("React Class", ()=> {
this.mount(this.PanelReactClass)
expect(this.wrapper.html()).toEqual(jsxToHTML(
))
})
it("Render function", ()=> {
this.mount(this.PanelFunction)
expect(this.wrapper.html()).toEqual(jsxToHTML(
))
})
it("Invalid component", ()=> {
spyOn(console, "warn")
try{
this.mount(10)
printPrettyHtml(this.wrapper.html())
} catch (e){
}
expect(console.warn).toHaveBeenCalledWith(
"Invalid component", 10
)
})
})