Remove persistence from RNTester app (#22596)

Summary:
Previously the RNTester app saved what screen you were on and what filter text was entered into the initial screen. This made e2e testing complex, as each test needed to manually restore the state to the home screen. If the state ever got out of sync with the test's expectations, it could lead to multiple failed tests.

There is still one specific component that uses persistence: `RNTesterSettingSwitchRow`. Persistence can be removed from this component next time tests for it are updated. As a result, `RNTesterStatePersister` is not yet entirely removed from the app.
Pull Request resolved: https://github.com/facebook/react-native/pull/22596

Differential Revision: D13413457

Pulled By: cpojer

fbshipit-source-id: 3faa26a94139397b4bce6b62ff43e9c2f870b145
This commit is contained in:
Josh Justice 2018-12-10 21:31:19 -08:00 коммит произвёл Facebook Github Bot
Родитель 794d2264f9
Коммит 33fb70f6b6
4 изменённых файлов: 12 добавлений и 32 удалений

Просмотреть файл

@ -8,10 +8,11 @@
* @format
*/
/* global element, by, expect */
/* global device, element, by, expect */
describe('Button', () => {
beforeAll(async () => {
await device.reloadReactNative();
await element(by.id('explorer_search')).replaceText('<Button>');
await element(
by.label('<Button> Simple React Native button component.'),

Просмотреть файл

@ -8,12 +8,13 @@
* @format
*/
/* global element, by, expect */
/* global device, element, by, expect */
const jestExpect = require('expect');
describe('Switch', () => {
beforeAll(async () => {
await device.reloadReactNative();
await element(by.id('explorer_search')).replaceText('<Switch>');
await element(by.label('<Switch> Native boolean input')).tap();
});

Просмотреть файл

@ -70,17 +70,8 @@ class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {
);
const urlAction = URIActionMap(url);
const launchAction = exampleAction || urlAction;
if (err || !storedString) {
const initialAction = launchAction || {type: 'InitialAction'};
this.setState(RNTesterNavigationReducer(undefined, initialAction));
return;
}
const storedState = JSON.parse(storedString);
if (launchAction) {
this.setState(RNTesterNavigationReducer(storedState, launchAction));
return;
}
this.setState(storedState);
});
});

Просмотреть файл

@ -18,13 +18,11 @@ const Text = require('Text');
const TextInput = require('TextInput');
const TouchableHighlight = require('TouchableHighlight');
const RNTesterActions = require('./RNTesterActions');
const RNTesterStatePersister = require('./RNTesterStatePersister');
const View = require('View');
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found when
* making Flow check .android.js files. */
import type {RNTesterExample} from './RNTesterList.ios';
import type {PassProps} from './RNTesterStatePersister';
import type {TextStyleProp, ViewStyleProp} from 'StyleSheet';
type Props = {
@ -33,8 +31,6 @@ type Props = {
ComponentExamples: Array<RNTesterExample>,
APIExamples: Array<RNTesterExample>,
},
persister: PassProps<*>,
searchTextInputStyle: TextStyleProp,
style?: ?ViewStyleProp,
};
@ -73,8 +69,10 @@ const renderSectionHeader = ({section}) => (
);
class RNTesterExampleList extends React.Component<Props, $FlowFixMeState> {
state = {filter: ''};
render() {
const filterText = this.props.persister.state.filter;
const filterText = this.state.filter;
let filterRegex = /.*/;
try {
@ -178,13 +176,13 @@ class RNTesterExampleList extends React.Component<Props, $FlowFixMeState> {
autoCorrect={false}
clearButtonMode="always"
onChangeText={text => {
this.props.persister.setState(() => ({filter: text}));
this.setState(() => ({filter: text}));
}}
placeholder="Search..."
underlineColorAndroid="transparent"
style={[styles.searchTextInput, this.props.searchTextInputStyle]}
style={styles.searchTextInput}
testID="explorer_search"
value={this.props.persister.state.filter}
value={this.state.filter}
/>
</View>
);
@ -199,17 +197,6 @@ const ItemSeparator = ({highlighted}) => (
<View style={highlighted ? styles.separatorHighlighted : styles.separator} />
);
/* $FlowFixMe(>=0.85.0 site=react_native_fb) This comment suppresses an error
* found when Flow v0.85 was deployed. To see the error, delete this comment
* and run Flow. */
RNTesterExampleList = RNTesterStatePersister.createContainer(
RNTesterExampleList,
{
cacheKeySuffix: () => 'mainList',
getInitialState: () => ({filter: ''}),
},
);
const styles = StyleSheet.create({
listContainer: {
flex: 1,