Skip to content

Commit

Permalink
Test that Picker selection is updated correctly
Browse files Browse the repository at this point in the history
Summary:
A React pull request broke the Picker: facebook/react#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.

<img width="837" alt="screen shot 2016-05-04 at 5 13 31 pm" src="https://cloud.githubusercontent.com/assets/346214/15020827/aca8d718-121b-11e6-91f6-a338293d7d92.png">
Closes facebook#7390

Differential Revision: D3305223

Pulled By: mkonicek

fbshipit-source-id: 89137812940c578efff3e76864ab7cadccc9f2ea
  • Loading branch information
Martin Konicek authored and bubblesunyum committed Aug 23, 2016
1 parent e94f034 commit f9a4934
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,36 @@ public void run() {
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);
}
Expand Down
8 changes: 8 additions & 0 deletions ReactAndroid/src/androidTest/js/PickerAndroidTestModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ var PickerAndroidTestApp = React.createClass({
<Item label="item1" />
<Item label="item2" />
</Picker>
<Picker
mode="dropdown"
selectedValue={this.state.selected}
onValueChange={this.onValueChange}>
<Item label="item in sync 1" value={0} />
<Item label="item in sync 2" value={1} />
<Item label="item in sync 3" value={2} />
</Picker>
</View>
);
},
Expand Down

0 comments on commit f9a4934

Please sign in to comment.