From 10429b58223dac91b2ca72f5272e58990b371a3f Mon Sep 17 00:00:00 2001 From: Martin Konicek Date: Mon, 16 May 2016 09:07:34 -0700 Subject: [PATCH] Test that Picker selection is updated correctly Summary: A React pull request broke the Picker: https://github.com/facebook/react/pull/6572 This pull request adds a test so that we prevent breakages like this in the future. `PickerAndroidExample` in the UIExplorer before the breakage (video): https://vid.me/h5Rg `PickerAndroidExample` in the UIExplorer after the breakage (video): https://vid.me/atFc **Test plan** `./scripts/run-android-local-integration-test.sh` The test is failing, we can only merge this once React is fixed. screen shot 2016-05-04 at 5 13 31 pm Closes https://github.com/facebook/react-native/pull/7390 Differential Revision: D3305223 Pulled By: mkonicek fbshipit-source-id: 89137812940c578efff3e76864ab7cadccc9f2ea --- .../react/tests/ReactPickerTestCase.java | 30 +++++++++++++++++++ .../androidTest/js/PickerAndroidTestModule.js | 8 +++++ 2 files changed, 38 insertions(+) diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/ReactPickerTestCase.java b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/ReactPickerTestCase.java index b27d9ecc0..5ad6d82e6 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/ReactPickerTestCase.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/ReactPickerTestCase.java @@ -171,6 +171,36 @@ public class ReactPickerTestCase extends ReactAppInstrumentationTestCase { assertEquals(2, (int) selections.get(0)); } + public void testOnSelectSequence() throws Throwable { + updateFirstSpinnerAndCheckLastSpinnerMatches(0); + updateFirstSpinnerAndCheckLastSpinnerMatches(2); + updateFirstSpinnerAndCheckLastSpinnerMatches(0); + updateFirstSpinnerAndCheckLastSpinnerMatches(2); + } + + private void updateFirstSpinnerAndCheckLastSpinnerMatches( + final int indexToSelect + ) throws Throwable { + // The last spinner has the same selected value as the first one. + // Test that user selection is propagated correctly to JS, to setState, and to Spinners. + runTestOnUiThread( + new Runnable() { + @Override + public void run() { + ReactPicker spinner = getViewAtPath(0, 0); + spinner.setSelection(indexToSelect); + } + }); + getInstrumentation().waitForIdleSync(); + waitForBridgeAndUIIdle(); + + ReactPicker spinnerInSync = getViewAtPath(0, 3); + assertEquals( + "Picker selection was not updated correctly via setState.", + indexToSelect, + spinnerInSync.getSelectedItemPosition()); + } + private PickerAndroidTestModule getTestModule() { return getReactContext().getCatalystInstance().getJSModule(PickerAndroidTestModule.class); } diff --git a/ReactAndroid/src/androidTest/js/PickerAndroidTestModule.js b/ReactAndroid/src/androidTest/js/PickerAndroidTestModule.js index 95e31937d..e354d8fae 100644 --- a/ReactAndroid/src/androidTest/js/PickerAndroidTestModule.js +++ b/ReactAndroid/src/androidTest/js/PickerAndroidTestModule.js @@ -52,6 +52,14 @@ var PickerAndroidTestApp = React.createClass({ + + + + + ); },