-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: revamp the cookbook app (#1635)
* create a Jotai examples dir in cookbook with related utils, add state management recipes dir * add docs with examples * extract state from component to state, utils, simplify types and custom render func. * refactor: tweaks & cleanup * make cookbook app runnable * update yarn.lock file * fix TS issue and spelling * remove duplicate files and adjust testMatch in config to ensure no utils test run --------- Co-authored-by: stevegalili <steve.galili@mywheels.nl>
- Loading branch information
1 parent
d31c05a
commit 10bda69
Showing
29 changed files
with
1,022 additions
and
217 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
# RNTL Cookbook | ||
|
||
This example app gathers recipes from the [RNTL Cookbook](https://callstack.github.io/react-native-testing-library/cookbook). | ||
This example app gathers recipes from | ||
the [RNTL Cookbook](https://callstack.github.io/react-native-testing-library/cookbook). | ||
|
||
Each recipe described in the Cookbook should have a corresponding code example in this repo. | ||
Each recipe described in the Cookbook should have a corresponding code example screen in this repo. | ||
|
||
Note: | ||
Since examples will showcase usage of different dependencies, the dependencies in `package.json` fill will grow much larger that in an normal React Native. This is fine 🐶☕️🔥. | ||
Since examples will showcase usage of different dependencies, the dependencies in `package.json` | ||
file will grow much larger that in a normal React Native. This is fine 🐶☕️🔥. |
2 changes: 1 addition & 1 deletion
2
...book/custom-render/WelcomeScreen.test.tsx → ..._tests__/app/custom-render/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...les/cookbook/custom-render/test-utils.tsx → ..._tests__/app/custom-render/test-utils.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
examples/cookbook/jotai/TaskList.test.tsx → ...okbook/__tests__/app/jotai/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Stack } from 'expo-router'; | ||
import theme from '../theme'; | ||
|
||
export default function RootLayout() { | ||
return ( | ||
<Stack | ||
screenOptions={{ | ||
headerStyle: { | ||
backgroundColor: theme.colors.primary, | ||
}, | ||
headerTintColor: '#fff', | ||
headerTitleStyle: { | ||
fontWeight: 'bold', | ||
}, | ||
headerBackTitleVisible: false, | ||
}} | ||
> | ||
<Stack.Screen name="index" options={{ headerTitle: '' }} /> | ||
</Stack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Slot } from 'expo-router'; | ||
import { UserProvider } from './providers/user-provider'; | ||
import { ThemeProvider } from './providers/theme-provider'; | ||
|
||
export default function CustomRenderLayout() { | ||
return ( | ||
<UserProvider.Provider value={null}> | ||
<ThemeProvider.Provider value={'light'}> | ||
<Slot /> | ||
</ThemeProvider.Provider> | ||
</UserProvider.Provider> | ||
); | ||
} |
6 changes: 3 additions & 3 deletions
6
.../cookbook/custom-render/WelcomeScreen.tsx → ...ples/cookbook/app/custom-render/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React, {useCallback, useEffect} from 'react'; | ||
import { FlatList, Image, Pressable, StyleSheet, Text, View } from 'react-native'; | ||
import { useRouter } from 'expo-router'; | ||
import * as SplashScreen from 'expo-splash-screen'; | ||
import { useFonts } from 'expo-font'; | ||
import theme from '../theme'; | ||
|
||
void SplashScreen.preventAutoHideAsync(); | ||
|
||
export default function Home() { | ||
const router = useRouter(); | ||
const [loaded, error] = useFonts({ | ||
'OpenSans-Bold': require('../assets/fonts/OpenSans-Bold.ttf'), | ||
'OpenSans-Regular': require('../assets/fonts/OpenSans-Regular.ttf'), | ||
}); | ||
|
||
useEffect(() => { | ||
if (loaded || error) { | ||
void SplashScreen.hideAsync(); | ||
} | ||
}, [loaded, error]); | ||
|
||
if (!loaded && !error) { | ||
return null; | ||
} | ||
const renderItem = useCallback(({ item }: {item: Recipe}) => ( | ||
<Pressable style={styles.pressable} onPress={() => router.push(item.path)}> | ||
<Text style={styles.pressableText}>{item.title}</Text> | ||
</Pressable> | ||
),[]); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<View style={styles.bannerContainer}> | ||
<Image source={require('../assets/icon.png')} style={styles.logo} /> | ||
<Image | ||
resizeMode={'contain'} | ||
source={require('../assets/gradientRNBanner.png')} | ||
style={styles.banner} | ||
/> | ||
<Text style={styles.title}>Testing Library</Text> | ||
<Text style={styles.subTitle}>Cookbook App</Text> | ||
</View> | ||
<FlatList<Recipe> | ||
data={recipes} | ||
renderItem={renderItem} | ||
keyExtractor={(item) => item.id.toString()} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: '#F5F5F5', | ||
paddingVertical: 20, | ||
}, | ||
bannerContainer: { | ||
alignItems: 'center', | ||
marginBottom: 20, | ||
}, | ||
title: { | ||
fontSize: 20, | ||
fontFamily: 'OpenSans-Bold', | ||
color: theme.colors.black, | ||
}, | ||
subTitle: { | ||
fontSize: 14, | ||
fontFamily: 'OpenSans-Regular', | ||
color: theme.colors.gray, | ||
}, | ||
banner: { | ||
height: 40, | ||
}, | ||
logo: { | ||
width: 80, | ||
height: 80, | ||
marginBottom: 20, | ||
}, | ||
pressable: { | ||
backgroundColor: '#9b6dff', | ||
padding: 12, | ||
marginBottom: 8, | ||
borderRadius: 16, | ||
}, | ||
pressableText: { | ||
color: '#fff', | ||
fontSize: 14, | ||
fontFamily: 'OpenSans-Bold', | ||
textAlign: 'center', | ||
}, | ||
}); | ||
|
||
type Recipe = { | ||
id: number; | ||
title: string; | ||
path: string; | ||
}; | ||
const recipes: Recipe[] = [ | ||
{ id: 2, title: 'Welcome Screen with Custom Render', path: 'custom-render/' }, | ||
{ id: 1, title: 'Task List with Jotai', path: 'jotai/' }, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
colors: { | ||
primary: '#9b6dff', | ||
secondary: '#58baad', | ||
black: '#323232', | ||
gray: '#5b5a5b', | ||
}, | ||
}; |
Oops, something went wrong.