diff options
author | Matthew Shao <me@matshao.com> | 2017-05-16 18:00:14 +0800 |
---|---|---|
committer | Matthew Shao <me@matshao.com> | 2017-05-16 18:00:14 +0800 |
commit | d63e01d48de70e43b934e8297ccb06ea14546426 (patch) | |
tree | 50aad56019f5afe51220b95eb30f1e1fde419cf3 /web | |
parent | 69c5a0b6993f70340a0a4b99159086c638d77103 (diff) | |
download | mitmproxy-d63e01d48de70e43b934e8297ccb06ea14546426.tar.gz mitmproxy-d63e01d48de70e43b934e8297ccb06ea14546426.tar.bz2 mitmproxy-d63e01d48de70e43b934e8297ccb06ea14546426.zip |
[web] Add tests for js/components/ValueEditor/ValidateEditor.js
Diffstat (limited to 'web')
-rw-r--r-- | web/src/js/__tests__/components/ValueEditor/ValidateEditorSpec.js | 47 | ||||
-rw-r--r-- | web/src/js/__tests__/components/ValueEditor/__snapshots__/ValidateEditorSpec.js.snap | 21 |
2 files changed, 68 insertions, 0 deletions
diff --git a/web/src/js/__tests__/components/ValueEditor/ValidateEditorSpec.js b/web/src/js/__tests__/components/ValueEditor/ValidateEditorSpec.js new file mode 100644 index 00000000..0c6ac359 --- /dev/null +++ b/web/src/js/__tests__/components/ValueEditor/ValidateEditorSpec.js @@ -0,0 +1,47 @@ +import React from 'react' +import renderer from 'react-test-renderer' +import TestUtils from 'react-dom/test-utils' +import ValidateEditor from '../../../components/ValueEditor/ValidateEditor' + +describe('ValidateEditor Component', () => { + let validateFn = jest.fn( content => content.length == 3), + doneFn = jest.fn() + + it('should be render correctly', () => { + let validateEditor = renderer.create( + <ValidateEditor content="foo" onDone={doneFn} isValid={validateFn}/> + ), + tree = validateEditor.toJSON() + expect(tree).toMatchSnapshot() + }) + + let validateEditor = TestUtils.renderIntoDocument( + <ValidateEditor content="foo" onDone={doneFn} isValid={validateFn}/> + ) + it('should handle componentWillReceiveProps', () => { + let mockProps = { + isValid: s => s.length == 3, + content: "bar" + } + validateEditor.componentWillReceiveProps(mockProps) + expect(validateEditor.state.valid).toBeTruthy() + validateEditor.componentWillReceiveProps({...mockProps, content: "bars"}) + expect(validateEditor.state.valid).toBeFalsy() + + }) + + it('should handle input', () => { + validateEditor.onInput("foo bar") + expect(validateFn).toBeCalledWith("foo bar") + }) + + it('should handle done', () => { + // invalid + validateEditor.editor.reset = jest.fn() + validateEditor.onDone("foo bar") + expect(validateEditor.editor.reset).toBeCalled() + // valid + validateEditor.onDone("bar") + expect(doneFn).toBeCalledWith("bar") + }) +}) diff --git a/web/src/js/__tests__/components/ValueEditor/__snapshots__/ValidateEditorSpec.js.snap b/web/src/js/__tests__/components/ValueEditor/__snapshots__/ValidateEditorSpec.js.snap new file mode 100644 index 00000000..7d6f22d8 --- /dev/null +++ b/web/src/js/__tests__/components/ValueEditor/__snapshots__/ValidateEditorSpec.js.snap @@ -0,0 +1,21 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ValidateEditor Component should be render correctly 1`] = ` +<div + className="inline-input editable has-success" + contentEditable={undefined} + dangerouslySetInnerHTML={ + Object { + "__html": "foo", + } + } + onBlur={[Function]} + onClick={[Function]} + onFocus={[Function]} + onInput={[Function]} + onKeyDown={[Function]} + onMouseDown={[Function]} + onPaste={[Function]} + tabIndex={0} +/> +`; |