55 * LICENSE file in the root directory of this source tree.
66 */
77
8- import React , { useCallback , useState } from 'react' ;
8+ import React , { useCallback , useMemo , useState } from 'react' ;
99import {
1010 Button ,
1111 Keyboard ,
@@ -15,52 +15,42 @@ import {
1515 TouchableOpacity ,
1616 View ,
1717} from 'react-native' ;
18- import BasicExample from './examples/Basic' ;
18+ import Basic from './examples/Basic' ;
19+ import Functional from './examples/Functional' ;
1920import GetSetClear from './examples/GetSetClear' ;
2021import MergeItem from './examples/MergeItem' ;
2122
22- const TESTS = {
23- GetSetClear : {
24- title : 'Simple Get/Set value' ,
25- testId : 'get-set-clear' ,
26- description : 'Store and retrieve persisted data' ,
27- render ( ) {
28- return < GetSetClear /> ;
29- } ,
30- } ,
31- MergeItem : {
32- title : 'Merge item' ,
33- testId : 'merge-item' ,
34- description : 'Merge object with already stored data' ,
35- render ( ) {
36- return < MergeItem /> ;
37- } ,
38- } ,
39- Basic : {
40- title : 'Basic' ,
41- testId : 'basic' ,
42- description : 'Basic functionality test' ,
43- render ( ) {
44- return < BasicExample /> ;
45- } ,
46- } ,
23+ const SCREENS = {
24+ Functional,
25+ GetSetClear,
26+ MergeItem,
27+ Basic,
4728} ;
4829
4930export default function App ( ) : JSX . Element {
5031 const [ iteration , setIteration ] = useState ( 0 ) ;
51- const [ currentTest , setCurrentTest ] = useState ( TESTS . GetSetClear ) ;
32+ const [ currentTest , setCurrentTest ] = useState ( SCREENS . Functional ) ;
5233
53- const dismissKeyboard = useCallback ( ( ) => Keyboard . dismiss ( ) , [ ] ) ;
34+ const dismissKeyboard = useCallback ( Keyboard . dismiss , [ ] ) ;
5435 const simulateRestart = useCallback (
5536 ( ) => setIteration ( iteration + 1 ) ,
5637 [ iteration ]
5738 ) ;
58- const testBasic = useCallback ( ( ) => setCurrentTest ( TESTS . Basic ) , [ ] ) ;
59- const testGetSetClear = useCallback (
60- ( ) => setCurrentTest ( TESTS . GetSetClear ) ,
39+ const navigationBar = useMemo (
40+ ( ) =>
41+ Object . values ( SCREENS ) . map ( ( t ) => {
42+ const { testId, title } = t ;
43+ return (
44+ < Button
45+ key = { testId }
46+ testID = { testId }
47+ title = { title }
48+ onPress = { ( ) => setCurrentTest ( t ) }
49+ />
50+ ) ;
51+ } ) ,
6152 [ ]
6253 ) ;
63- const testMergeItem = useCallback ( ( ) => setCurrentTest ( TESTS . MergeItem ) , [ ] ) ;
6454
6555 return (
6656 < SafeAreaView style = { styles . container } >
@@ -69,7 +59,6 @@ export default function App(): JSX.Element {
6959 onPress = { dismissKeyboard }
7060 testID = "closeKeyboard"
7161 />
72-
7362 < TouchableOpacity
7463 testID = "restart_button"
7564 onPress = { simulateRestart }
@@ -79,22 +68,10 @@ export default function App(): JSX.Element {
7968 < Text > Simulate Restart</ Text >
8069 </ TouchableOpacity >
8170
82- < View style = { styles . testPickerContainer } >
83- < Button
84- testID = "testType_getSetClear"
85- title = "Get/Set/Clear"
86- onPress = { testGetSetClear }
87- />
88- < Button
89- testID = "testType_mergeItem"
90- title = "Merge Item"
91- onPress = { testMergeItem }
92- />
93- < Button title = { TESTS . Basic . title } onPress = { testBasic } />
94- </ View >
71+ < View style = { styles . testPickerContainer } > { navigationBar } </ View >
9572
9673 < View
97- testID = { `example- ${ currentTest . testId } ` }
74+ testID = { `${ currentTest . testId } -view ` }
9875 key = { currentTest . title + iteration }
9976 style = { styles . exampleContainer }
10077 >
0 commit comments