From e9778d1b9d473a1fbb67d9e6ade899a7273f03c5 Mon Sep 17 00:00:00 2001 From: Wei Guangcheng Date: Thu, 4 May 2017 11:05:23 +0800 Subject: [PATCH 1/6] add test for "Back button appearing in root of navbar scenario" #1433 --- test/Reducer.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/Reducer.test.js b/test/Reducer.test.js index e5d9665e5..145fe1b20 100644 --- a/test/Reducer.test.js +++ b/test/Reducer.test.js @@ -134,6 +134,8 @@ describe('handling actions', () => { + + ); @@ -162,6 +164,21 @@ describe('handling actions', () => { expect(current.key).to.eq('hello_0_hello_'); }); + it('reset to a correct scene on RESET', () => { + Actions.world(); + expect(current.key).to.eq('world_0_world_content'); + + Actions.maps({ type: 'push' }); + expect(current.key).to.eq('maps_0_maps_content'); + + Actions.map_tabs(); + expect(current.key).to.eq('map_tabs_0_map_tab_1_'); + expect(current.parentIndex).to.eq(1); + Actions.foo(); + Actions.bar({type: 'reset'}); + expect(current.key).to.eq('bar_0_bar'); + }); + it('maintains scene parentIndex when switching tabs', () => { Actions.world(); expect(current.key).to.eq('world_0_world_content'); From 779ea9bff0e58b1d52d79f74717a362c00aca684 Mon Sep 17 00:00:00 2001 From: Wei Guangcheng Date: Thu, 4 May 2017 11:05:36 +0800 Subject: [PATCH 2/6] fix "Back button appearing in root of navbar scenario" #1433 --- src/Reducer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Reducer.js b/src/Reducer.js index f388c3883..eec7f7198 100644 --- a/src/Reducer.js +++ b/src/Reducer.js @@ -254,7 +254,7 @@ function inject(state, action, props, scenes) { } state.children = state.children.splice(0, 1); - state.children[0] = getInitialState(props, scenes, state.index, action); + state.children[0] = getInitialState(props, scenes, 0, action); return { ...state, From b5fffad014bbbddaed9ecd347bc4fb27efbaa99c Mon Sep 17 00:00:00 2001 From: Wei Guangcheng Date: Thu, 4 May 2017 11:09:45 +0800 Subject: [PATCH 3/6] lint --- test/Reducer.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Reducer.test.js b/test/Reducer.test.js index 145fe1b20..0d8adc098 100644 --- a/test/Reducer.test.js +++ b/test/Reducer.test.js @@ -134,8 +134,8 @@ describe('handling actions', () => { - - + + ); @@ -175,7 +175,7 @@ describe('handling actions', () => { expect(current.key).to.eq('map_tabs_0_map_tab_1_'); expect(current.parentIndex).to.eq(1); Actions.foo(); - Actions.bar({type: 'reset'}); + Actions.bar({ type: 'reset' }); expect(current.key).to.eq('bar_0_bar'); }); From a27625f872dfce7a4a75f283f8b34db97528546b Mon Sep 17 00:00:00 2001 From: Wei Guangcheng Date: Thu, 4 May 2017 11:53:42 +0800 Subject: [PATCH 4/6] fix test --- .../__snapshots__/Example-test.js.snap | 287 ++++++++++++------ Example/__tests__/index.android.js | 12 - Example/__tests__/index.ios.js | 12 - Example/jest-setup.js | 7 + Example/package.json | 2 +- 5 files changed, 200 insertions(+), 120 deletions(-) delete mode 100644 Example/__tests__/index.android.js delete mode 100644 Example/__tests__/index.ios.js create mode 100644 Example/jest-setup.js diff --git a/Example/__tests__/__snapshots__/Example-test.js.snap b/Example/__tests__/__snapshots__/Example-test.js.snap index a72f82973..19170e936 100644 --- a/Example/__tests__/__snapshots__/Example-test.js.snap +++ b/Example/__tests__/__snapshots__/Example-test.js.snap @@ -1,3 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + exports[`Example renders correctly 1`] = ` + } +> + } + > + } + > + } + > + } + > + } + > + } + > + } + > + } + > + type="REACT_NATIVE_ROUTER_FLUX_PUSH" + > + ellipsizeMode="tail" + > Launch page - + accessible={true} + hitSlop={undefined} + isTVSelectable={true} + onLayout={undefined} + onResponderGrant={[Function]} + onResponderMove={[Function]} + onResponderRelease={[Function]} + onResponderTerminate={[Function]} + onResponderTerminationRequest={[Function]} + onStartShouldSetResponder={[Function]} + style={ + Object { + "opacity": 1, + } + } + testID={undefined} + tvParallaxProperties={undefined} + > + } + > Go to Login page - - + + accessible={true} + hitSlop={undefined} + isTVSelectable={true} + onLayout={undefined} + onResponderGrant={[Function]} + onResponderMove={[Function]} + onResponderRelease={[Function]} + onResponderTerminate={[Function]} + onResponderTerminationRequest={[Function]} + onStartShouldSetResponder={[Function]} + style={ + Object { + "opacity": 1, + } + } + testID={undefined} + tvParallaxProperties={undefined} + > + } + > Go to Register page - - + + accessible={true} + hitSlop={undefined} + isTVSelectable={true} + onLayout={undefined} + onResponderGrant={[Function]} + onResponderMove={[Function]} + onResponderRelease={[Function]} + onResponderTerminate={[Function]} + onResponderTerminationRequest={[Function]} + onStartShouldSetResponder={[Function]} + style={ + Object { + "opacity": 1, + } + } + testID={undefined} + tvParallaxProperties={undefined} + > + } + > Go to Register page without animation - - + + accessible={true} + hitSlop={undefined} + isTVSelectable={true} + onLayout={undefined} + onResponderGrant={[Function]} + onResponderMove={[Function]} + onResponderRelease={[Function]} + onResponderTerminate={[Function]} + onResponderTerminationRequest={[Function]} + onStartShouldSetResponder={[Function]} + style={ + Object { + "opacity": 1, + } + } + testID={undefined} + tvParallaxProperties={undefined} + > + } + > Popup error - - + + accessible={true} + hitSlop={undefined} + isTVSelectable={true} + onLayout={undefined} + onResponderGrant={[Function]} + onResponderMove={[Function]} + onResponderRelease={[Function]} + onResponderTerminate={[Function]} + onResponderTerminationRequest={[Function]} + onStartShouldSetResponder={[Function]} + style={ + Object { + "opacity": 1, + } + } + testID={undefined} + tvParallaxProperties={undefined} + > + } + > Go to TabBar page - - + + accessible={true} + hitSlop={undefined} + isTVSelectable={true} + onLayout={undefined} + onResponderGrant={[Function]} + onResponderMove={[Function]} + onResponderRelease={[Function]} + onResponderTerminate={[Function]} + onResponderTerminationRequest={[Function]} + onStartShouldSetResponder={[Function]} + style={ + Object { + "opacity": 1, + } + } + testID={undefined} + tvParallaxProperties={undefined} + > + } + > Go to switcher page - - + + accessible={true} + hitSlop={undefined} + isTVSelectable={true} + onLayout={undefined} + onResponderGrant={[Function]} + onResponderMove={[Function]} + onResponderRelease={[Function]} + onResponderTerminate={[Function]} + onResponderTerminationRequest={[Function]} + onStartShouldSetResponder={[Function]} + style={ + Object { + "opacity": 1, + } + } + testID={undefined} + tvParallaxProperties={undefined} + > + } + > back - + diff --git a/Example/__tests__/index.android.js b/Example/__tests__/index.android.js deleted file mode 100644 index b49b9087f..000000000 --- a/Example/__tests__/index.android.js +++ /dev/null @@ -1,12 +0,0 @@ -import 'react-native'; -import React from 'react'; -import Index from '../index.android.js'; - -// Note: test renderer must be required after react-native. -import renderer from 'react-test-renderer'; - -it('renders correctly', () => { - const tree = renderer.create( - - ); -}); diff --git a/Example/__tests__/index.ios.js b/Example/__tests__/index.ios.js deleted file mode 100644 index ba7c5b5e1..000000000 --- a/Example/__tests__/index.ios.js +++ /dev/null @@ -1,12 +0,0 @@ -import 'react-native'; -import React from 'react'; -import Index from '../index.ios.js'; - -// Note: test renderer must be required after react-native. -import renderer from 'react-test-renderer'; - -it('renders correctly', () => { - const tree = renderer.create( - - ); -}); diff --git a/Example/jest-setup.js b/Example/jest-setup.js new file mode 100644 index 000000000..4dc940057 --- /dev/null +++ b/Example/jest-setup.js @@ -0,0 +1,7 @@ +jest.mock('Linking', () => ({ + addEventListener: jest.fn(), + removeEventListener: jest.fn(), + openURL: jest.fn(), + canOpenURL: jest.fn(), + getInitialURL: jest.fn(), +})); \ No newline at end of file diff --git a/Example/package.json b/Example/package.json index 358b7db5d..a9e3ae90c 100644 --- a/Example/package.json +++ b/Example/package.json @@ -23,7 +23,7 @@ }, "jest": { "preset": "react-native", - "setupFiles": ["./jest/setup.js"], + "setupFiles": ["./node_modules/react-native/jest/setup.js", "./jest-setup.js"], "transformIgnorePatterns": [ "node_modules/(?!react-native|native-base|react-clone-referenced-element)" ] From 0871858799435e70bb69f613143c7287f0837e2e Mon Sep 17 00:00:00 2001 From: Wei Guangcheng Date: Thu, 4 May 2017 15:33:03 +0800 Subject: [PATCH 5/6] add router-flux dependencies in devDependencies of Example for temporary pass jest test --- Example/package.json | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Example/package.json b/Example/package.json index a9e3ae90c..42db0a37e 100644 --- a/Example/package.json +++ b/Example/package.json @@ -12,14 +12,21 @@ "react-native": "0.42.3", "react-native-button": "^1.8.2", "react-native-drawer": "^2.3.0", - "react-native-router-flux": "^3.38.0" + "react-native-router-flux": "^3.38.0", }, "devDependencies": { "babel-jest": "19.0.0", "babel-preset-react-native": "1.9.1", "jest": "19.0.2", "jest-react-native": "^18.0.0", - "react-test-renderer": "~15.4.1" + "react-test-renderer": "~15.4.1", + + "lodash.isequal": "^4.5.0", + "react-addons-pure-render-mixin": "^15.4.2", + "react-dom": "^15.4.2", + "react-native-experimental-navigation": "0.26.x", + "react-native-tabs": "^1.0.9", + "react-static-container": "1.0.1" }, "jest": { "preset": "react-native", From 9bcfad1b3ee1cfa96db5ccce28be7cea6c125d8d Mon Sep 17 00:00:00 2001 From: Wei Guangcheng Date: Thu, 4 May 2017 15:37:58 +0800 Subject: [PATCH 6/6] fix package.json --- Example/package.json | 3 +-- Example/yarn.lock | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Example/package.json b/Example/package.json index 42db0a37e..79e99bdcd 100644 --- a/Example/package.json +++ b/Example/package.json @@ -12,7 +12,7 @@ "react-native": "0.42.3", "react-native-button": "^1.8.2", "react-native-drawer": "^2.3.0", - "react-native-router-flux": "^3.38.0", + "react-native-router-flux": "^3.38.0" }, "devDependencies": { "babel-jest": "19.0.0", @@ -20,7 +20,6 @@ "jest": "19.0.2", "jest-react-native": "^18.0.0", "react-test-renderer": "~15.4.1", - "lodash.isequal": "^4.5.0", "react-addons-pure-render-mixin": "^15.4.2", "react-dom": "^15.4.2", diff --git a/Example/yarn.lock b/Example/yarn.lock index 25ad54001..6a9e95986 100644 --- a/Example/yarn.lock +++ b/Example/yarn.lock @@ -1400,7 +1400,7 @@ fbjs-scripts@^0.7.0: semver "^5.1.0" through2 "^2.0.0" -fbjs@^0.8.1, fbjs@^0.8.4, fbjs@^0.8.5: +fbjs@^0.8.1, fbjs@^0.8.4, fbjs@^0.8.5, fbjs@^0.8.9: version "0.8.11" resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.11.tgz#340b590b8a2278a01ef7467c07a16da9b753db24" dependencies: @@ -2363,6 +2363,10 @@ lodash.isarray@^3.0.0: version "3.0.4" resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55" +lodash.isequal@^4.5.0: + version "4.5.0" + resolved "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0" + lodash.keys@^3.0.0: version "3.1.2" resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a" @@ -2848,6 +2852,12 @@ promise@^7.1.1: dependencies: asap "~2.0.3" +prop-types@~15.5.7: + version "15.5.8" + resolved "https://registry.npmjs.org/prop-types/-/prop-types-15.5.8.tgz#6b7b2e141083be38c8595aa51fc55775c7199394" + dependencies: + fbjs "^0.8.9" + prr@~0.0.0: version "0.0.0" resolved "https://registry.yarnpkg.com/prr/-/prr-0.0.0.tgz#1a84b85908325501411853d0081ee3fa86e2926a" @@ -2891,7 +2901,7 @@ raw-body@~2.1.2: iconv-lite "0.4.13" unpipe "1.0.0" -react-addons-pure-render-mixin@^15.0.2: +react-addons-pure-render-mixin@^15.0.2, react-addons-pure-render-mixin@^15.4.2: version "15.4.2" resolved "https://registry.yarnpkg.com/react-addons-pure-render-mixin/-/react-addons-pure-render-mixin-15.4.2.tgz#a8433c71c45e2368503721921dc47bdaf1fbabcd" dependencies: @@ -2906,6 +2916,15 @@ react-deep-force-update@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/react-deep-force-update/-/react-deep-force-update-1.0.1.tgz#f911b5be1d2a6fe387507dd6e9a767aa2924b4c7" +react-dom@^15.4.2: + version "15.5.4" + resolved "https://registry.npmjs.org/react-dom/-/react-dom-15.5.4.tgz#ba0c28786fd52ed7e4f2135fe0288d462aef93da" + dependencies: + fbjs "^0.8.9" + loose-envify "^1.1.0" + object-assign "^4.1.0" + prop-types "~15.5.7" + react-native-button@^1.8.2: version "1.8.2" resolved "https://registry.yarnpkg.com/react-native-button/-/react-native-button-1.8.2.tgz#49e5cadd22ee443adea52a85539d288aa2117ade"