mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-25 18:03:50 +00:00
[web] Add tests for js/components/common/ToggleInputButton.jsx
This commit is contained in:
parent
2b5a300284
commit
ace67b5a87
@ -0,0 +1,43 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import renderer from 'react-test-renderer'
|
||||||
|
import ToggleInputButton from '../../../components/common/ToggleInputButton'
|
||||||
|
import { Key } from '../../../utils'
|
||||||
|
|
||||||
|
describe('ToggleInputButton Component', () => {
|
||||||
|
let mockFunc = jest.fn(),
|
||||||
|
toggleInputButton = undefined,
|
||||||
|
tree = undefined
|
||||||
|
|
||||||
|
it('should render correctly', () => {
|
||||||
|
toggleInputButton = renderer.create(
|
||||||
|
<ToggleInputButton checked={true} name="foo" onToggleChanged={mockFunc}
|
||||||
|
placeholder="bar">text</ToggleInputButton>)
|
||||||
|
tree = toggleInputButton.toJSON()
|
||||||
|
expect(tree).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should handle keydown and click action', () => {
|
||||||
|
toggleInputButton = renderer.create(
|
||||||
|
<ToggleInputButton checked={false} name="foo" onToggleChanged={mockFunc}
|
||||||
|
placeholder="bar" txt="txt">text</ToggleInputButton>)
|
||||||
|
tree = toggleInputButton.toJSON()
|
||||||
|
let mockEvent = {
|
||||||
|
keyCode: Key.ENTER,
|
||||||
|
stopPropagation: jest.fn()
|
||||||
|
}
|
||||||
|
|
||||||
|
tree.children[1].props.onKeyDown(mockEvent)
|
||||||
|
expect(mockFunc).toBeCalledWith("txt")
|
||||||
|
|
||||||
|
tree.children[0].props.onClick()
|
||||||
|
expect(mockFunc).toBeCalledWith("txt")
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should update state onChange', () => {
|
||||||
|
// trigger onChange
|
||||||
|
tree.children[1].props.onChange({ target: { value: "foo" }})
|
||||||
|
// update the tree
|
||||||
|
tree = toggleInputButton.toJSON()
|
||||||
|
expect(tree.children[1].props.value).toEqual("foo")
|
||||||
|
})
|
||||||
|
})
|
@ -0,0 +1,31 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`ToggleInputButton Component should render correctly 1`] = `
|
||||||
|
<div
|
||||||
|
className="input-group toggle-input-btn"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="input-group-btn"
|
||||||
|
onClick={[Function]}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="btn btn-primary"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="fa fa-check-square-o"
|
||||||
|
/>
|
||||||
|
|
||||||
|
foo
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
|
<input
|
||||||
|
className="form-control"
|
||||||
|
disabled={true}
|
||||||
|
onChange={[Function]}
|
||||||
|
onKeyDown={[Function]}
|
||||||
|
placeholder="bar"
|
||||||
|
type="text"
|
||||||
|
value=""
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
`;
|
Loading…
Reference in New Issue
Block a user