mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 07:08:10 +00:00
[web] Add tests for js/components/Header/MainMenu.js
This commit is contained in:
parent
fbaa842a46
commit
9c90d13149
26
web/src/js/__tests__/components/Header/MainMenuSpec.js
Normal file
26
web/src/js/__tests__/components/Header/MainMenuSpec.js
Normal 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' })
|
||||
})
|
||||
})
|
@ -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>
|
||||
`;
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user