Skip to content

Commit 4ddb3d4

Browse files
committed
Set up index.js for progress bar tests
1 parent f3f50b8 commit 4ddb3d4

File tree

1 file changed

+139
-4
lines changed

1 file changed

+139
-4
lines changed

example/index.js

Lines changed: 139 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,144 @@
11
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
27
* @format
8+
* @flow
39
*/
410

5-
import {AppRegistry} from 'react-native';
6-
import App from './App';
7-
import {name as appName} from './app.json';
11+
import React from 'react';
12+
import {
13+
AppRegistry,
14+
Button,
15+
SafeAreaView,
16+
ScrollView,
17+
StyleSheet,
18+
Text,
19+
View,
20+
} from 'react-native';
821

9-
AppRegistry.registerComponent(appName, () => App);
22+
import ProgressBarTestModule from './ProgressBarTestModule.js';
23+
import ProgressBarAndroidExample from './ProgressBarAndroidExample.android.js';
24+
import RNTesterBlock from './RNTesterBlock.js';
25+
import RNTesterPage from './RNTesterPage.js';
26+
import RNTesterTitle from './RNTesterTitle.js';
27+
28+
// Examples which show the user how to correctly use the library
29+
const EXAMPLES = [
30+
{
31+
id: 'ProgressBarTestModule',
32+
title: 'Progress Bar Test Module',
33+
description: 'Multiple progress bars with different style attributes.',
34+
render() {
35+
return <ProgressBarTestModule />;
36+
},
37+
},
38+
{
39+
id: 'ProgressBarAndroidExample',
40+
title: 'Simple progress bar',
41+
description: 'Horizontal bar to show the progress of some operation.',
42+
render() {
43+
return <ProgressBarAndroidExample />;
44+
},
45+
},
46+
];
47+
48+
// Test cases for the e2e tests. THESE ARE NOT EXAMPLES OF BEST PRACTICE
49+
import TEST_CASES from './testCases';
50+
51+
type State = {
52+
showExamples: boolean,
53+
};
54+
55+
class ExampleApp extends React.Component<{}, State> {
56+
constructor(props) {
57+
super(props);
58+
59+
this.state = {
60+
showExamples: true,
61+
};
62+
}
63+
64+
_toggleMode = () => {
65+
this.setState(state => ({showExamples: !state.showExamples}));
66+
};
67+
68+
render() {
69+
const {showExamples} = this.state;
70+
return (
71+
<ScrollView testID="scrollView" style={styles.container}>
72+
<SafeAreaView>
73+
<Button
74+
testID="modeToggle"
75+
onPress={this._toggleMode}
76+
title={showExamples ? 'Switch to Test Cases' : 'Switch to Examples'}
77+
/>
78+
{showExamples ? (
79+
<>
80+
<Text testID="examplesTitle" style={styles.sectionTitle}>
81+
Examples
82+
</Text>
83+
{EXAMPLES.map(this._renderExample)}
84+
</>
85+
) : (
86+
<>
87+
<Text testID="testCasesTitle" style={styles.sectionTitle}>
88+
Test Cases
89+
</Text>
90+
{TEST_CASES.map(this._renderExample)}
91+
</>
92+
)}
93+
</SafeAreaView>
94+
</ScrollView>
95+
);
96+
}
97+
98+
_renderExample = example => {
99+
return (
100+
<View
101+
testID={`example-${example.id}`}
102+
key={example.title}
103+
style={styles.exampleContainer}>
104+
<Text style={styles.exampleTitle}>{example.title}</Text>
105+
<Text style={styles.exampleDescription}>{example.description}</Text>
106+
<View style={styles.exampleInnerContainer}>{example.render()}</View>
107+
</View>
108+
);
109+
};
110+
}
111+
112+
const styles = StyleSheet.create({
113+
container: {
114+
flex: 1,
115+
backgroundColor: '#F5FCFF',
116+
},
117+
sectionTitle: {
118+
fontSize: 24,
119+
marginHorizontal: 8,
120+
marginTop: 24,
121+
},
122+
exampleContainer: {
123+
padding: 16,
124+
marginVertical: 4,
125+
backgroundColor: '#FFF',
126+
borderColor: '#EEE',
127+
borderTopWidth: 1,
128+
borderBottomWidth: 1,
129+
},
130+
exampleTitle: {
131+
fontSize: 18,
132+
},
133+
exampleDescription: {
134+
color: '#333333',
135+
marginBottom: 16,
136+
},
137+
exampleInnerContainer: {
138+
borderColor: '#EEE',
139+
borderTopWidth: 1,
140+
paddingTop: 16,
141+
},
142+
});
143+
144+
AppRegistry.registerComponent(appName, () => ExampleApp);

0 commit comments

Comments
 (0)