Skip to content

Commit 2adbd41

Browse files
authored
chore: add test examples do example app (#2735)
## Description Adding test screens to the example application so that we can automate regression testing where-ever feasible. Currently the test screens are always visible, but we could limit it in the future to CI only. ## Test code and steps to reproduce Just run the `FabricExample` app and scroll down. ## Checklist - [x] Ensured that CI passes
1 parent 8aa80e8 commit 2adbd41

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

apps/Example.tsx

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import {
44
StyleSheet,
55
I18nManager,
66
Platform,
7-
StatusBar,
87
useColorScheme,
8+
View,
99
} from 'react-native';
1010
import {
1111
DarkTheme,
1212
DefaultTheme,
1313
NavigationContainer,
14+
NavigationIndependentTree,
1415
useTheme,
1516
} from '@react-navigation/native';
1617
import { StackNavigationProp } from '@react-navigation/stack';
@@ -37,14 +38,28 @@ import { enableFreeze } from 'react-native-screens';
3738
import { GestureDetectorProvider } from 'react-native-screens/gesture-handler';
3839
import { GestureHandlerRootView } from 'react-native-gesture-handler';
3940

41+
import * as Tests from './src/tests';
42+
4043
enableFreeze();
4144

45+
function isPlatformReady(name: keyof typeof SCREENS) {
46+
if (Platform.isTV) {
47+
return !!SCREENS[name].isTVOSReady;
48+
}
49+
50+
return true;
51+
}
52+
53+
function isTestSectionEnabled() {
54+
return true;
55+
}
56+
4257
const SCREENS: Record<
4358
string,
4459
{
4560
title: string;
4661
component: () => React.JSX.Element;
47-
type: 'example' | 'playground';
62+
type: 'example' | 'playground' | 'test';
4863
isTVOSReady?: boolean;
4964
}
5065
> = {
@@ -119,20 +134,32 @@ const SCREENS: Record<
119134
},
120135
};
121136

122-
const isPlatformReady = (name: keyof typeof SCREENS) => {
123-
if (Platform.isTV) {
124-
return !!SCREENS[name].isTVOSReady;
125-
}
137+
if (isTestSectionEnabled()) {
138+
Object.keys(Tests).forEach(testName => {
139+
SCREENS[testName] = {
140+
title: testName,
141+
component: () => {
142+
const TestComponent = Tests[testName as keyof typeof Tests];
143+
return (
144+
<NavigationIndependentTree>
145+
<TestComponent />
146+
</NavigationIndependentTree>
147+
);
148+
},
149+
type: 'test',
150+
};
151+
});
152+
}
126153

127-
return true;
128-
};
129154

130155
const screens = Object.keys(SCREENS);
131156
const examples = screens.filter(name => SCREENS[name].type === 'example');
132157
const playgrounds = screens.filter(name => SCREENS[name].type === 'playground');
158+
const tests = isTestSectionEnabled() ? screens.filter(name => SCREENS[name].type === 'test') : [];
133159

134160
type RootStackParamList = {
135161
Main: undefined;
162+
Tests: undefined;
136163
} & {
137164
[P in keyof typeof SCREENS]: undefined;
138165
};
@@ -186,6 +213,17 @@ const MainScreen = ({ navigation }: MainScreenProps): React.JSX.Element => {
186213
disabled={!isPlatformReady(name)}
187214
/>
188215
))}
216+
{isTestSectionEnabled() &&
217+
<ThemedText style={styles.label}>Tests</ThemedText>}
218+
{isTestSectionEnabled() && tests.map(name => (
219+
<ListItem
220+
key={name}
221+
testID={`root-screen-tests-${name}`}
222+
title={SCREENS[name].title}
223+
onPress={() => navigation.navigate(name)}
224+
disabled={false}
225+
/>
226+
))}
189227
</ScrollView>
190228
);
191229
};

0 commit comments

Comments
 (0)