From f465f08c9ac302007b3aec6709a8e82d63c7ad65 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Thu, 20 Jul 2017 15:39:43 +0800 Subject: [web] Minor fix and update tests. --- .../js/__tests__/components/Modal/OptionSpec.js | 99 +++++++++++ .../Modal/__snapshots__/ModalSpec.js.snap | 196 +++++++++++++-------- .../Modal/__snapshots__/OptionSpec.js.snap | 64 +++++++ web/src/js/__tests__/ducks/optionsSpec.js | 32 +++- web/src/js/__tests__/ducks/tutils.js | 6 + web/src/js/__tests__/ducks/ui/keyboardSpec.js | 7 + web/src/js/__tests__/ducks/ui/optionEditorSpec.js | 32 ++++ web/src/js/__tests__/ducks/ui/optionSpec.js | 39 ++++ web/src/js/components/Modal/Option.jsx | 4 +- web/src/js/ducks/options.js | 4 +- web/src/js/ducks/ui/option.js | 2 +- web/src/js/ducks/ui/optionsEditor.js | 2 +- 12 files changed, 404 insertions(+), 83 deletions(-) create mode 100644 web/src/js/__tests__/components/Modal/OptionSpec.js create mode 100644 web/src/js/__tests__/components/Modal/__snapshots__/OptionSpec.js.snap create mode 100644 web/src/js/__tests__/ducks/ui/optionEditorSpec.js create mode 100644 web/src/js/__tests__/ducks/ui/optionSpec.js (limited to 'web/src') diff --git a/web/src/js/__tests__/components/Modal/OptionSpec.js b/web/src/js/__tests__/components/Modal/OptionSpec.js new file mode 100644 index 00000000..a275aee6 --- /dev/null +++ b/web/src/js/__tests__/components/Modal/OptionSpec.js @@ -0,0 +1,99 @@ +import React from 'react' +import renderer from 'react-test-renderer' +import { Options, ChoicesOption } from '../../../components/Modal/Option' + +describe('BooleanOption Component', () => { + let BooleanOption = Options['bool'], + onChangeFn = jest.fn(), + booleanOption = renderer.create( + + ), + tree = booleanOption.toJSON() + + it('should render correctly', () => { + expect(tree).toMatchSnapshot() + }) + + it('should handle onChange', () => { + let input = tree.children[0].children[0], + mockEvent = { target: { checked: true }} + input.props.onChange(mockEvent) + expect(onChangeFn).toBeCalledWith(mockEvent.target.checked) + }) +}) + +describe('StringOption Component', () => { + let StringOption = Options['str'], + onChangeFn = jest.fn(), + stringOption = renderer.create( + + ), + tree = stringOption.toJSON() + + it('should render correctly', () => { + expect(tree).toMatchSnapshot() + }) + + it('should handle onChange', () => { + let mockEvent = { target: { value: 'bar' }} + tree.props.onChange(mockEvent) + expect(onChangeFn).toBeCalledWith(mockEvent.target.value) + }) + +}) + +describe('NumberOption Component', () => { + let NumberOption = Options['int'], + onChangeFn = jest.fn(), + numberOption = renderer.create( + + ), + tree = numberOption.toJSON() + + it('should render correctly', () => { + expect(tree).toMatchSnapshot() + }) + + it('should handle onChange', () => { + let mockEvent = {target: { value: '2'}} + tree.props.onChange(mockEvent) + expect(onChangeFn).toBeCalledWith(2) + }) +}) + +describe('ChoiceOption Component', () => { + let onChangeFn = jest.fn(), + choiceOption = renderer.create( + + ), + tree = choiceOption.toJSON() + + it('should render correctly', () => { + expect(tree).toMatchSnapshot() + }) + + it('should handle onChange', () => { + let mockEvent = { target: {value: 'b'} } + tree.props.onChange(mockEvent) + expect(onChangeFn).toBeCalledWith(mockEvent.target.value) + }) +}) + +describe('StringOption Component', () => { + let onChangeFn = jest.fn(), + StringSequenceOption = Options['sequence of str'], + stringSequenceOption = renderer.create( + + ), + tree = stringSequenceOption.toJSON() + + it('should render correctly', () => { + expect(tree).toMatchSnapshot() + }) + + it('should handle onChange', () => { + let mockEvent = { target: {value: 'a\nb\nc\n'}} + tree.props.onChange(mockEvent) + expect(onChangeFn).toBeCalledWith(['a', 'b', 'c', '']) + }) +}) diff --git a/web/src/js/__tests__/components/Modal/__snapshots__/ModalSpec.js.snap b/web/src/js/__tests__/components/Modal/__snapshots__/ModalSpec.js.snap index 0550c1fa..bfd855bd 100644 --- a/web/src/js/__tests__/components/Modal/__snapshots__/ModalSpec.js.snap +++ b/web/src/js/__tests__/components/Modal/__snapshots__/ModalSpec.js.snap @@ -47,117 +47,165 @@ exports[`Modal Component should render correctly 2`] = ` className="modal-body" >
- booleanOption + +
+ foo +
- +
+
+ +
+
- choiceOption + +
+ foo +
- + + + + +
- intOption + +
+ foo +
- +
+ +
- strOption + +
+ foo +
- + +
+
diff --git a/web/src/js/__tests__/components/Modal/__snapshots__/OptionSpec.js.snap b/web/src/js/__tests__/components/Modal/__snapshots__/OptionSpec.js.snap new file mode 100644 index 00000000..514e0eb5 --- /dev/null +++ b/web/src/js/__tests__/components/Modal/__snapshots__/OptionSpec.js.snap @@ -0,0 +1,64 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`BooleanOption Component should render correctly 1`] = ` +
+ +
+`; + +exports[`ChoiceOption Component should render correctly 1`] = ` + +`; + +exports[`NumberOption Component should render correctly 1`] = ` + +`; + +exports[`StringOption Component should render correctly 1`] = ` + +`; + +exports[`StringOption Component should render correctly 2`] = ` +