diff options
author | Matthew Shao <me@matshao.com> | 2017-05-12 09:05:06 +0800 |
---|---|---|
committer | Matthew Shao <me@matshao.com> | 2017-05-12 09:05:06 +0800 |
commit | 2b5a300284b3b15c08f51f0aa3948c1f6465929f (patch) | |
tree | 24df18a00cd8cbd5a59f8079038c5e099e70bcbb /web/src/js/__tests__/components | |
parent | 782d564e7608fe8c208876ca4c7bc0f89cfc938a (diff) | |
download | mitmproxy-2b5a300284b3b15c08f51f0aa3948c1f6465929f.tar.gz mitmproxy-2b5a300284b3b15c08f51f0aa3948c1f6465929f.tar.bz2 mitmproxy-2b5a300284b3b15c08f51f0aa3948c1f6465929f.zip |
[web] Add tests for js/components/common/ToggleButton.jsx
Diffstat (limited to 'web/src/js/__tests__/components')
-rw-r--r-- | web/src/js/__tests__/components/common/ToggleButtonSpec.js | 26 | ||||
-rw-r--r-- | web/src/js/__tests__/components/common/__snapshots__/ToggleButtonSpec.js.snap | 14 |
2 files changed, 40 insertions, 0 deletions
diff --git a/web/src/js/__tests__/components/common/ToggleButtonSpec.js b/web/src/js/__tests__/components/common/ToggleButtonSpec.js new file mode 100644 index 00000000..2188da82 --- /dev/null +++ b/web/src/js/__tests__/components/common/ToggleButtonSpec.js @@ -0,0 +1,26 @@ +import React from 'react' +import renderer from 'react-test-renderer' +import ToggleButton from '../../../components/common/ToggleButton' + +describe('ToggleButton Component', () => { + let mockFunc = jest.fn() + + it('should render correctly', () => { + let checkedButton = renderer.create( + <ToggleButton checked={true} onToggle={mockFunc} text="foo"> + text + </ToggleButton>), + tree = checkedButton.toJSON() + expect(tree).toMatchSnapshot() + }) + + it('should handle click action', () => { + let uncheckButton = renderer.create( + <ToggleButton checked={false} onToggle={mockFunc} text="foo"> + text + </ToggleButton>), + tree = uncheckButton.toJSON() + tree.props.onClick() + expect(mockFunc).toBeCalled() + }) +}) diff --git a/web/src/js/__tests__/components/common/__snapshots__/ToggleButtonSpec.js.snap b/web/src/js/__tests__/components/common/__snapshots__/ToggleButtonSpec.js.snap new file mode 100644 index 00000000..f468d39f --- /dev/null +++ b/web/src/js/__tests__/components/common/__snapshots__/ToggleButtonSpec.js.snap @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ToggleButton Component should render correctly 1`] = ` +<div + className="btn btn-toggle btn-primary" + onClick={[Function]} +> + <i + className="fa fa-fw fa-check-square-o" + /> + + foo +</div> +`; |