mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 02:10:59 +00:00
[web] Add tests for js/components/helpers/AutoScroll.js
This commit is contained in:
parent
6757eda23a
commit
c327ae853c
41
web/src/js/__tests__/components/helpers/AutoScrollSpec.js
Normal file
41
web/src/js/__tests__/components/helpers/AutoScrollSpec.js
Normal file
@ -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")
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user