Skip to content

Commit 33fb70f

Browse files
CodingItWrongfacebook-github-bot
authored andcommitted
Remove persistence from RNTester app (facebook#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: facebook#22596 Differential Revision: D13413457 Pulled By: cpojer fbshipit-source-id: 3faa26a94139397b4bce6b62ff43e9c2f870b145
1 parent 794d226 commit 33fb70f

File tree

4 files changed

+12
-32
lines changed

4 files changed

+12
-32
lines changed

RNTester/e2e/__tests__/Button-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
* @format
99
*/
1010

11-
/* global element, by, expect */
11+
/* global device, element, by, expect */
1212

1313
describe('Button', () => {
1414
beforeAll(async () => {
15+
await device.reloadReactNative();
1516
await element(by.id('explorer_search')).replaceText('<Button>');
1617
await element(
1718
by.label('<Button> Simple React Native button component.'),

RNTester/e2e/__tests__/Switch-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
* @format
99
*/
1010

11-
/* global element, by, expect */
11+
/* global device, element, by, expect */
1212

1313
const jestExpect = require('expect');
1414

1515
describe('Switch', () => {
1616
beforeAll(async () => {
17+
await device.reloadReactNative();
1718
await element(by.id('explorer_search')).replaceText('<Switch>');
1819
await element(by.label('<Switch> Native boolean input')).tap();
1920
});

RNTester/js/RNTesterApp.ios.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,8 @@ class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {
7070
);
7171
const urlAction = URIActionMap(url);
7272
const launchAction = exampleAction || urlAction;
73-
if (err || !storedString) {
74-
const initialAction = launchAction || {type: 'InitialAction'};
75-
this.setState(RNTesterNavigationReducer(undefined, initialAction));
76-
return;
77-
}
78-
const storedState = JSON.parse(storedString);
79-
if (launchAction) {
80-
this.setState(RNTesterNavigationReducer(storedState, launchAction));
81-
return;
82-
}
83-
this.setState(storedState);
73+
const initialAction = launchAction || {type: 'InitialAction'};
74+
this.setState(RNTesterNavigationReducer(undefined, initialAction));
8475
});
8576
});
8677

RNTester/js/RNTesterExampleList.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ const Text = require('Text');
1818
const TextInput = require('TextInput');
1919
const TouchableHighlight = require('TouchableHighlight');
2020
const RNTesterActions = require('./RNTesterActions');
21-
const RNTesterStatePersister = require('./RNTesterStatePersister');
2221
const View = require('View');
2322

2423
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found when
2524
* making Flow check .android.js files. */
2625
import type {RNTesterExample} from './RNTesterList.ios';
27-
import type {PassProps} from './RNTesterStatePersister';
2826
import type {TextStyleProp, ViewStyleProp} from 'StyleSheet';
2927

3028
type Props = {
@@ -33,8 +31,6 @@ type Props = {
3331
ComponentExamples: Array<RNTesterExample>,
3432
APIExamples: Array<RNTesterExample>,
3533
},
36-
persister: PassProps<*>,
37-
searchTextInputStyle: TextStyleProp,
3834
style?: ?ViewStyleProp,
3935
};
4036

@@ -73,8 +69,10 @@ const renderSectionHeader = ({section}) => (
7369
);
7470

7571
class RNTesterExampleList extends React.Component<Props, $FlowFixMeState> {
72+
state = {filter: ''};
73+
7674
render() {
77-
const filterText = this.props.persister.state.filter;
75+
const filterText = this.state.filter;
7876
let filterRegex = /.*/;
7977

8078
try {
@@ -178,13 +176,13 @@ class RNTesterExampleList extends React.Component<Props, $FlowFixMeState> {
178176
autoCorrect={false}
179177
clearButtonMode="always"
180178
onChangeText={text => {
181-
this.props.persister.setState(() => ({filter: text}));
179+
this.setState(() => ({filter: text}));
182180
}}
183181
placeholder="Search..."
184182
underlineColorAndroid="transparent"
185-
style={[styles.searchTextInput, this.props.searchTextInputStyle]}
183+
style={styles.searchTextInput}
186184
testID="explorer_search"
187-
value={this.props.persister.state.filter}
185+
value={this.state.filter}
188186
/>
189187
</View>
190188
);
@@ -199,17 +197,6 @@ const ItemSeparator = ({highlighted}) => (
199197
<View style={highlighted ? styles.separatorHighlighted : styles.separator} />
200198
);
201199

202-
/* $FlowFixMe(>=0.85.0 site=react_native_fb) This comment suppresses an error
203-
* found when Flow v0.85 was deployed. To see the error, delete this comment
204-
* and run Flow. */
205-
RNTesterExampleList = RNTesterStatePersister.createContainer(
206-
RNTesterExampleList,
207-
{
208-
cacheKeySuffix: () => 'mainList',
209-
getInitialState: () => ({filter: ''}),
210-
},
211-
);
212-
213200
const styles = StyleSheet.create({
214201
listContainer: {
215202
flex: 1,

0 commit comments

Comments
 (0)