New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][web] Add tests for UI components #2327

Merged
merged 11 commits into from May 15, 2017
Prev

[web] Add tests for js/components/helpers/AutoScroll.js

  • Loading branch information...
MatthewShao committed May 15, 2017
commit c327ae853c8e33c50f575fe3589aa1bdda64ba19
@@ -0,0 +1,41 @@
import React from "react"
import ReactDOM from "react-dom"
import AutoScroll from '../../../components/helpers/AutoScroll'
import { calcVScroll } from '../../../components/helpers/VirtualScroll'
import TestUtils from 'react-dom/test-utils'
describe('Autoscroll', () => {
let mockFn = jest.fn()
class tComponent extends React.Component {
constructor(props, context){
super(props, context)
this.state = { vScroll: calcVScroll() }
}
componentWillUpdate() {
mockFn("foo")
}
componentDidUpdate() {
mockFn("bar")
}
render() {
return (<p>foo</p>)
}
}
it('should update component', () => {
let Foo = AutoScroll(tComponent),
autoScroll = TestUtils.renderIntoDocument(<Foo></Foo>),
viewport = ReactDOM.findDOMNode(autoScroll)
viewport.scrollTop = 10
Object.defineProperty(viewport, "scrollHeight", { value: 10, writable: true })
autoScroll.componentWillUpdate()
expect(mockFn).toBeCalledWith("foo")
Object.defineProperty(viewport, "scrollHeight", { value: 0, writable: true })
autoScroll.componentDidUpdate()
expect(mockFn).toBeCalledWith("bar")
})
})
ProTip! Use n and p to navigate between commits in a pull request.