[web] Updates test to use the new _tflow.js.

This commit is contained in:
Matthew Shao 2017-05-19 09:49:10 +08:00
parent 50c0703424
commit 5df0ddf358
3 changed files with 30 additions and 63 deletions

View File

@ -1,101 +1,101 @@
import React from 'react'
import renderer from 'react-test-renderer'
import * as Columns from '../../../components/FlowTable/FlowColumns'
import { TFlow } from '../../ducks/tutils'
import _tflow from '../../ducks/_tflow'
describe('FlowColumns Components', () => {
let tFlow = new TFlow()
let tflow = _tflow()
it('should render TLSColumn', () => {
let tlsColumn = renderer.create(<Columns.TLSColumn flow={tFlow}/>),
let tlsColumn = renderer.create(<Columns.TLSColumn flow={tflow}/>),
tree = tlsColumn.toJSON()
expect(tree).toMatchSnapshot()
})
it('should render IconColumn', () => {
let iconColumn = renderer.create(<Columns.IconColumn flow={tFlow}/>),
let iconColumn = renderer.create(<Columns.IconColumn flow={tflow}/>),
tree = iconColumn.toJSON()
// plain
expect(tree).toMatchSnapshot()
// not modified
tFlow.response.status_code = 304
iconColumn = renderer.create(<Columns.IconColumn flow={tFlow}/>)
tflow.response.status_code = 304
iconColumn = renderer.create(<Columns.IconColumn flow={tflow}/>)
tree = iconColumn.toJSON()
expect(tree).toMatchSnapshot()
// redirect
tFlow.response.status_code = 302
iconColumn = renderer.create(<Columns.IconColumn flow={tFlow}/>)
tflow.response.status_code = 302
iconColumn = renderer.create(<Columns.IconColumn flow={tflow}/>)
tree = iconColumn.toJSON()
expect(tree).toMatchSnapshot()
// image
let imageFlow = new TFlow()
let imageFlow = _tflow()
imageFlow.response.headers = [['Content-Type', 'image/jpeg']]
iconColumn = renderer.create(<Columns.IconColumn flow={imageFlow}/>)
tree = iconColumn.toJSON()
expect(tree).toMatchSnapshot()
// javascript
let jsFlow = new TFlow()
let jsFlow = _tflow()
jsFlow.response.headers = [['Content-Type', 'application/x-javascript']]
iconColumn = renderer.create(<Columns.IconColumn flow={jsFlow}/>)
tree = iconColumn.toJSON()
expect(tree).toMatchSnapshot()
// css
let cssFlow = new TFlow()
let cssFlow = _tflow()
cssFlow.response.headers = [['Content-Type', 'text/css']]
iconColumn = renderer.create(<Columns.IconColumn flow={cssFlow}/>)
tree = iconColumn.toJSON()
expect(tree).toMatchSnapshot()
// default
let fooFlow = new TFlow()
let fooFlow = _tflow()
fooFlow.response.headers = [['Content-Type', 'foo']]
iconColumn = renderer.create(<Columns.IconColumn flow={fooFlow}/>)
tree = iconColumn.toJSON()
expect(tree).toMatchSnapshot()
// no response
tFlow.response = null
iconColumn = renderer.create(<Columns.IconColumn flow={tFlow}/>)
tflow.response = null
iconColumn = renderer.create(<Columns.IconColumn flow={tflow}/>)
tree = iconColumn.toJSON()
expect(tree).toMatchSnapshot()
})
it('should render pathColumn', () => {
let pathColumn = renderer.create(<Columns.PathColumn flow={tFlow}/>),
let pathColumn = renderer.create(<Columns.PathColumn flow={tflow}/>),
tree = pathColumn.toJSON()
expect(tree).toMatchSnapshot()
tFlow.error.msg = 'Connection killed'
tFlow.intercepted = true
pathColumn = renderer.create(<Columns.PathColumn flow={tFlow}/>)
tflow.error.msg = 'Connection killed'
tflow.intercepted = true
pathColumn = renderer.create(<Columns.PathColumn flow={tflow}/>)
tree = pathColumn.toJSON()
expect(tree).toMatchSnapshot()
})
it('should render MethodColumn', () => {
let methodColumn =renderer.create(<Columns.MethodColumn flow={tFlow}/>),
let methodColumn =renderer.create(<Columns.MethodColumn flow={tflow}/>),
tree = methodColumn.toJSON()
expect(tree).toMatchSnapshot()
})
it('should render StatusColumn', () => {
let statusColumn = renderer.create(<Columns.StatusColumn flow={tFlow}/>),
let statusColumn = renderer.create(<Columns.StatusColumn flow={tflow}/>),
tree = statusColumn.toJSON()
expect(tree).toMatchSnapshot()
})
it('should render SizeColumn', () => {
tFlow = new TFlow()
let sizeColumn = renderer.create(<Columns.SizeColumn flow={tFlow}/>),
tflow = _tflow()
let sizeColumn = renderer.create(<Columns.SizeColumn flow={tflow}/>),
tree = sizeColumn.toJSON()
expect(tree).toMatchSnapshot()
})
it('should render TimeColumn', () => {
let timeColumn = renderer.create(<Columns.TimeColumn flow={tFlow}/>),
let timeColumn = renderer.create(<Columns.TimeColumn flow={tflow}/>),
tree = timeColumn.toJSON()
expect(tree).toMatchSnapshot()
tFlow.response = null
timeColumn = renderer.create(<Columns.TimeColumn flow={tFlow}/>),
tflow.response = null
timeColumn = renderer.create(<Columns.TimeColumn flow={tflow}/>),
tree = timeColumn.toJSON()
expect(tree).toMatchSnapshot()
})

View File

@ -5,7 +5,7 @@ exports[`FlowColumns Components should render IconColumn 1`] = `
className="col-icon"
>
<div
className="resource-icon resource-icon-document"
className="resource-icon resource-icon-plain"
/>
</td>
`;
@ -92,7 +92,7 @@ exports[`FlowColumns Components should render SizeColumn 1`] = `
<td
className="col-size"
>
100b
14b
</td>
`;
@ -112,7 +112,7 @@ exports[`FlowColumns Components should render TimeColumn 1`] = `
<td
className="col-time"
>
2min
415322h
</td>
`;
@ -128,13 +128,10 @@ exports[`FlowColumns Components should render pathColumn 1`] = `
<td
className="col-path"
>
<i
className="fa fa-fw fa-repeat pull-right"
/>
<i
className="fa fa-fw fa-exclamation pull-right"
/>
http://undefined:undefinedundefined
http://address:22/path
</td>
`;
@ -142,15 +139,12 @@ exports[`FlowColumns Components should render pathColumn 2`] = `
<td
className="col-path"
>
<i
className="fa fa-fw fa-repeat pull-right"
/>
<i
className="fa fa-fw fa-pause pull-right"
/>
<i
className="fa fa-fw fa-times pull-right"
/>
http://undefined:undefinedundefined
http://address:22/path
</td>
`;

View File

@ -7,30 +7,3 @@ export function createStore(parts) {
applyMiddleware(...[thunk])
)
}
export function TFlow(intercepted=false, marked=false, modified=false) {
return {
intercepted ,
marked,
modified,
id: "foo",
request: {
scheme: 'http',
is_replay: true,
method: 'GET',
contentLength: 100
},
response: {
status_code: 200,
headers: [["Content-Type", 'text/html']],
timestamp_end: 200
},
error: {
msg: ''
},
server_conn: {
timestamp_start: 100
},
type: 'http'
}
}