From 1cc143d502ac515b418427636fca895b5381053c Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Fri, 7 Jul 2017 10:20:12 +0800 Subject: [web] Update test. --- .../Modal/__snapshots__/ModalSpec.js.snap | 179 ++++++++++++--------- 1 file changed, 99 insertions(+), 80 deletions(-) (limited to 'web/src/js/__tests__/components/Modal') 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 af587ae4..aaa54608 100644 --- a/web/src/js/__tests__/components/Modal/__snapshots__/ModalSpec.js.snap +++ b/web/src/js/__tests__/components/Modal/__snapshots__/ModalSpec.js.snap @@ -47,94 +47,113 @@ exports[`Modal Component should render correctly 2`] = ` className="modal-body" >
- -
-
-
+ +
+
+ choiceOption +
+
+ - -
-
- -
-
- + + + + +
+
+
+
+ intOption +
+
+ +
+
+
+
+ strOption +
+
+ +
+
- -
+ /> -- cgit v1.2.3 From 73855908da9460a9ba646a03415d2dcde4f378d0 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Mon, 10 Jul 2017 20:43:59 +0800 Subject: [web] Update tests. --- .../components/Modal/__snapshots__/ModalSpec.js.snap | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'web/src/js/__tests__/components/Modal') 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 aaa54608..0550c1fa 100644 --- a/web/src/js/__tests__/components/Modal/__snapshots__/ModalSpec.js.snap +++ b/web/src/js/__tests__/components/Modal/__snapshots__/ModalSpec.js.snap @@ -62,8 +62,11 @@ exports[`Modal Component should render correctly 2`] = ` > @@ -81,9 +84,12 @@ exports[`Modal Component should render correctly 2`] = ` > @@ -141,9 +150,12 @@ exports[`Modal Component should render correctly 2`] = ` className="col-sm-4" > -- cgit v1.2.3 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 +++++++ 3 files changed, 285 insertions(+), 74 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 (limited to 'web/src/js/__tests__/components/Modal') 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`] = ` +