[web] Add TStore in js/__tests__/ducks/tutils.js

This commit is contained in:
Matthew Shao 2017-05-27 21:19:49 +08:00
parent b1d29dcaa1
commit cdb256682e
3 changed files with 65 additions and 8 deletions

View File

@ -2,9 +2,8 @@ import React from 'react'
import renderer from 'react-test-renderer'
import ConnectedHead, { FlowTableHead } from '../../../components/FlowTable/FlowTableHead'
import { Provider } from 'react-redux'
import configureStore from 'redux-mock-store'
import { TStore } from '../../ducks/tutils'
const mockStore = configureStore()
describe('FlowTableHead Component', () => {
let sortFn = jest.fn(),
@ -21,7 +20,7 @@ describe('FlowTableHead Component', () => {
})
it('should connect to state', () => {
let store = mockStore({ flows: {sort: {desc: true, column: 'PathColumn'}} }),
let store = TStore(),
provider = renderer.create(
<Provider store={store}>
<ConnectedHead/>

View File

@ -3,9 +3,7 @@ import renderer from 'react-test-renderer'
import ConnectedIndicator, { ConnectionIndicator } from '../../../components/Header/ConnectionIndicator'
import { ConnectionState } from '../../../ducks/connection'
import { Provider } from 'react-redux'
import configureStore from 'redux-mock-store'
const mockStore = configureStore()
import { TStore } from '../../ducks/tutils'
describe('ConnectionIndicator Component', () => {
@ -45,7 +43,7 @@ describe('ConnectionIndicator Component', () => {
})
it('should connect to state', () => {
let store = mockStore({ connection: {state: ConnectionState.INIT} }),
let store = TStore(),
provider = renderer.create(
<Provider store={store}>
<ConnectedIndicator/>

View File

@ -1,5 +1,11 @@
import React from 'react'
import { combineReducers, applyMiddleware, createStore as createReduxStore } from 'redux'
import thunk from 'redux-thunk'
import configureStore from 'redux-mock-store'
import { ConnectionState } from '../../ducks/connection'
import TFlow from './_tflow'
const mockStore = configureStore([thunk])
export function createStore(parts) {
return createReduxStore(
@ -8,4 +14,58 @@ export function createStore(parts) {
)
}
export { default as TFlow } from './_tflow'
export { TFlow }
export function TStore(){
let tflow = new TFlow()
return mockStore({
ui: {
flow: {
contentView: 'Auto',
displayLarge: false,
showFullContent: true,
maxContentLines: 10,
content: ['foo', 'bar'],
viewDescription: 'foo',
modifiedFlow: true,
tab: 'request'
},
header: {
tab: 'Start'
}
},
settings: {
contentViews: ['Auto', 'Raw', 'Text'],
anticache: true,
anticomp: false
},
flows: {
selected: ["d91165be-ca1f-4612-88a9-c0f8696f3e29"],
byId: {"d91165be-ca1f-4612-88a9-c0f8696f3e29": tflow},
filter: '~u foo',
highlight: '~a bar',
sort: {
desc: true,
column: 'PathColumn'
}
},
connection: {
state: ConnectionState.ESTABLISHED
},
eventLog: {
visible: true,
filters: {
debug: true,
info: true,
web: false,
warn: true,
error: true
},
view: [
{ id: 1, level: 'info', message: 'foo' },
{ id: 2, level: 'error', message: 'bar' }
]
}
})
}