aboutsummaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorMatthew Shao <me@matshao.com>2017-06-25 21:15:01 +0800
committerMatthew Shao <me@matshao.com>2017-06-25 21:15:01 +0800
commitd2fa4d8341e742d66b644928405ee64ce83c414d (patch)
treec0259317c32b0c594d860ce4bd1c500264b3679b /web
parent9f58093954c5f84b9ba0de24339ca5b4fb13a117 (diff)
downloadmitmproxy-d2fa4d8341e742d66b644928405ee64ce83c414d.tar.gz
mitmproxy-d2fa4d8341e742d66b644928405ee64ce83c414d.tar.bz2
mitmproxy-d2fa4d8341e742d66b644928405ee64ce83c414d.zip
[web] Add tests for js/components/FlowTable.jsx
Diffstat (limited to 'web')
-rw-r--r--web/src/js/__tests__/components/FlowTableSpec.js50
-rw-r--r--web/src/js/__tests__/components/__snapshots__/FlowTableSpec.js.snap79
2 files changed, 129 insertions, 0 deletions
diff --git a/web/src/js/__tests__/components/FlowTableSpec.js b/web/src/js/__tests__/components/FlowTableSpec.js
new file mode 100644
index 00000000..4d8de12c
--- /dev/null
+++ b/web/src/js/__tests__/components/FlowTableSpec.js
@@ -0,0 +1,50 @@
+import React from 'react'
+import renderer from 'react-test-renderer'
+import FlowTable from '../../components/FlowTable'
+import TestUtils from 'react-dom/test-utils'
+import { TFlow, TStore } from '../ducks/tutils'
+import { Provider } from 'react-redux'
+
+window.addEventListener = jest.fn()
+
+describe('FlowTable Component', () => {
+ let selectFn = jest.fn(),
+ tflow = TFlow(),
+ store = TStore()
+
+ it('should render correctly', () => {
+ let provider = renderer.create(
+ <Provider store={store}>
+ <FlowTable onSelect={selectFn} flows={[tflow]}/>
+ </Provider>),
+ tree = provider.toJSON()
+ expect(tree).toMatchSnapshot()
+ })
+
+ let provider = TestUtils.renderIntoDocument(
+ <Provider store={store} >
+ <FlowTable onSelect={selectFn} flows={[tflow]}/>
+ </Provider>),
+ flowTable = TestUtils.findRenderedComponentWithType(provider, FlowTable)
+
+ it('should handle componentWillUnmount', () => {
+ flowTable.componentWillUnmount()
+ expect(window.addEventListener).toBeCalledWith('resize', flowTable.onViewportUpdate)
+ })
+
+ it('should handle componentDidUpdate', () => {
+ // flowTable.shouldScrollIntoView == false
+ expect(flowTable.componentDidUpdate()).toEqual(undefined)
+ // rowTop - headHeight < viewportTop
+ flowTable.shouldScrollIntoView = true
+ flowTable.componentDidUpdate()
+ // rowBottom > viewportTop + viewportHeight
+ flowTable.shouldScrollIntoView = true
+ flowTable.componentDidUpdate()
+ })
+
+ it('should handle componentWillReceiveProps', () => {
+ flowTable.componentWillReceiveProps({selected: tflow})
+ expect(flowTable.shouldScrollIntoView).toBeTruthy()
+ })
+})
diff --git a/web/src/js/__tests__/components/__snapshots__/FlowTableSpec.js.snap b/web/src/js/__tests__/components/__snapshots__/FlowTableSpec.js.snap
new file mode 100644
index 00000000..7149903c
--- /dev/null
+++ b/web/src/js/__tests__/components/__snapshots__/FlowTableSpec.js.snap
@@ -0,0 +1,79 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`FlowTable Component should render correctly 1`] = `
+<div
+ className="flow-table"
+ onScroll={[Function]}
+>
+ <table>
+ <thead
+ style={
+ Object {
+ "transform": "translateY(undefinedpx)",
+ }
+ }
+ >
+ <tr>
+ <th
+ className="col-tls"
+ onClick={[Function]}
+ >
+
+ </th>
+ <th
+ className="col-icon"
+ onClick={[Function]}
+ >
+
+ </th>
+ <th
+ className="col-path sort-desc"
+ onClick={[Function]}
+ >
+ Path
+ </th>
+ <th
+ className="col-method"
+ onClick={[Function]}
+ >
+ Method
+ </th>
+ <th
+ className="col-status"
+ onClick={[Function]}
+ >
+ Status
+ </th>
+ <th
+ className="col-size"
+ onClick={[Function]}
+ >
+ Size
+ </th>
+ <th
+ className="col-time"
+ onClick={[Function]}
+ >
+ Time
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr
+ style={
+ Object {
+ "height": 0,
+ }
+ }
+ />
+ <tr
+ style={
+ Object {
+ "height": 0,
+ }
+ }
+ />
+ </tbody>
+ </table>
+</div>
+`;