diff options
author | Matthew Shao <me@matshao.com> | 2017-05-15 17:55:06 +0800 |
---|---|---|
committer | Matthew Shao <me@matshao.com> | 2017-05-15 17:55:06 +0800 |
commit | c327ae853c8e33c50f575fe3589aa1bdda64ba19 (patch) | |
tree | fe74271a56699ccc0b2418e2dee5a2ef3b3ebe24 /web/src | |
parent | 6757eda23a8a927d8ad2228fe64e300298d5d57e (diff) | |
download | mitmproxy-c327ae853c8e33c50f575fe3589aa1bdda64ba19.tar.gz mitmproxy-c327ae853c8e33c50f575fe3589aa1bdda64ba19.tar.bz2 mitmproxy-c327ae853c8e33c50f575fe3589aa1bdda64ba19.zip |
[web] Add tests for js/components/helpers/AutoScroll.js
Diffstat (limited to 'web/src')
-rw-r--r-- | web/src/js/__tests__/components/helpers/AutoScrollSpec.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/web/src/js/__tests__/components/helpers/AutoScrollSpec.js b/web/src/js/__tests__/components/helpers/AutoScrollSpec.js new file mode 100644 index 00000000..18a3d669 --- /dev/null +++ b/web/src/js/__tests__/components/helpers/AutoScrollSpec.js @@ -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") + }) +}) |