[web] Add tests for js/components/Header/MainMenu.js

This commit is contained in:
Matthew Shao 2017-05-28 19:20:09 +08:00
parent fbaa842a46
commit 9c90d13149
3 changed files with 117 additions and 1 deletions

View File

@ -0,0 +1,26 @@
jest.mock('../../../ducks/settings')
import React from 'react'
import renderer from 'react-test-renderer'
import MainMenu, { setIntercept } from '../../../components/Header/MainMenu'
import { Provider } from 'react-redux'
import { update as updateSettings } from '../../../ducks/settings'
import { TStore } from '../../ducks/tutils'
describe('MainMenu Component', () => {
let store = TStore()
it('should render and connect to state', () => {
let provider = renderer.create(
<Provider store={store}>
<MainMenu/>
</Provider>),
tree = provider.toJSON()
expect(tree).toMatchSnapshot()
})
it('should handle change on interceptInput', () => {
setIntercept('foo')
expect(updateSettings).toBeCalledWith({ intercept: 'foo' })
})
})

View File

@ -0,0 +1,86 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`MainMenu Component should render and connect to state 1`] = `
<div
className="menu-main"
>
<div
className="filter-input input-group"
>
<span
className="input-group-addon"
>
<i
className="fa fa-fw fa-search"
style={
Object {
"color": "black",
}
}
/>
</span>
<input
className="form-control"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
placeholder="Search"
type="text"
value="~u foo"
/>
</div>
<div
className="filter-input input-group"
>
<span
className="input-group-addon"
>
<i
className="fa fa-fw fa-tag"
style={
Object {
"color": "hsl(48, 100%, 50%)",
}
}
/>
</span>
<input
className="form-control"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
placeholder="Highlight"
type="text"
value="~a bar"
/>
</div>
<div
className="filter-input input-group"
>
<span
className="input-group-addon"
>
<i
className="fa fa-fw fa-pause"
style={
Object {
"color": "hsl(208, 56%, 53%)",
}
}
/>
</span>
<input
className="form-control"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
placeholder="Intercept"
type="text"
value=""
/>
</div>
</div>
`;

View File

@ -17,6 +17,10 @@ export default function MainMenu() {
)
}
export function setIntercept(intercept) {
updateSettings({ intercept })
}
const InterceptInput = connect(
state => ({
value: state.settings.intercept || '',
@ -24,7 +28,7 @@ const InterceptInput = connect(
type: 'pause',
color: 'hsl(208, 56%, 53%)'
}),
{ onChange: intercept => updateSettings({ intercept }) }
{ onChange: setIntercept }
)(FilterInput);
const FlowFilterInput = connect(