Skip to content

Commit 2f4568a

Browse files
vanGalileamdjastrzebski
authored andcommitted
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 <[email protected]> refactor: tweak cookbook (#1636) * refactor: move files around * refactor: simplify * chore: remove custom fonts * chore: tweak eslint * chore: update yarn.lock
1 parent d31c05a commit 2f4568a

File tree

29 files changed

+1020
-217
lines changed

29 files changed

+1020
-217
lines changed

examples/cookbook/.eslintrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
{
2-
"extends": "@callstack"
2+
"extends": "@callstack",
3+
"rules": {
4+
"react-native-a11y/has-valid-accessibility-ignores-invert-colors": "off",
5+
"react-native/no-color-literals": "off",
6+
"react-native-a11y/has-valid-accessibility-descriptors": "off",
7+
}
38
}

examples/cookbook/App.tsx

Lines changed: 0 additions & 8 deletions
This file was deleted.

examples/cookbook/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# RNTL Cookbook
22

3-
This example app gathers recipes from the [RNTL Cookbook](https://callstack.github.io/react-native-testing-library/cookbook).
3+
This example app gathers recipes from
4+
the [RNTL Cookbook](https://callstack.github.io/react-native-testing-library/cookbook).
45

5-
Each recipe described in the Cookbook should have a corresponding code example in this repo.
6+
Each recipe described in the Cookbook should have a corresponding code example screen in this repo.
67

78
Note:
8-
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 🐶☕️🔥.
9+
Since examples will showcase usage of different dependencies, the dependencies in `package.json`
10+
file will grow much larger that in a normal React Native. This is fine 🐶☕️🔥.

examples/cookbook/app.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
"expo": {
33
"name": "RNTL Cookbook App",
44
"slug": "rntl-cookbook",
5+
"scheme": "rntlcookbook",
56
"version": "1.0.0",
67
"orientation": "portrait",
78
"icon": "./assets/icon.png",
89
"userInterfaceStyle": "light",
910
"splash": {
1011
"image": "./assets/splash.png",
11-
"resizeMode": "contain",
12-
"backgroundColor": "#ffffff"
12+
"resizeMode": "cover",
13+
"backgroundColor": "#FFFFFF"
1314
},
1415
"updates": {
1516
"fallbackToCacheTimeout": 0
@@ -26,6 +27,7 @@
2627
},
2728
"web": {
2829
"favicon": "./assets/favicon.png"
29-
}
30+
},
31+
"plugins": ["expo-router"]
3032
}
3133
}

examples/cookbook/app/_layout.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as React from 'react';
2+
import { Stack } from 'expo-router';
3+
import theme from '../theme';
4+
5+
export default function RootLayout() {
6+
return (
7+
<Stack
8+
screenOptions={{
9+
headerStyle: {
10+
backgroundColor: theme.colors.primary,
11+
},
12+
headerTintColor: '#fff',
13+
headerTitleStyle: {
14+
fontWeight: 'bold',
15+
},
16+
headerBackTitleVisible: false,
17+
}}
18+
>
19+
<Stack.Screen name="index" options={{ headerTitle: '' }} />
20+
</Stack>
21+
);
22+
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
import * as React from 'react';
2-
import { View, Text } from 'react-native';
2+
import { StyleSheet, Text, View } from 'react-native';
33
import { useUser } from './providers/user-provider';
44
import { useTheme } from './providers/theme-provider';
55

6-
export function WelcomeScreen() {
6+
export default function WelcomeScreen() {
77
const theme = useTheme();
88
const user = useUser();
99

1010
return (
11-
<View>
11+
<View style={styles.container}>
1212
<Text>Hello {user ? user.name : 'Stranger'}</Text>
1313
<Text>Theme: {theme}</Text>
1414
</View>
1515
);
1616
}
17+
18+
const styles = StyleSheet.create({
19+
container: {
20+
flex: 1,
21+
justifyContent: 'center',
22+
alignItems: 'center',
23+
},
24+
});

examples/cookbook/custom-render/WelcomeScreen.test.tsx renamed to examples/cookbook/app/custom-render/__tests__/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { screen } from '@testing-library/react-native';
3+
import WelcomeScreen from '../WelcomeScreen';
34
import { renderWithProviders } from './test-utils';
4-
import { WelcomeScreen } from './WelcomeScreen';
55

66
test('renders WelcomeScreen in light theme', () => {
77
renderWithProviders(<WelcomeScreen />, { theme: 'light' });

examples/cookbook/custom-render/test-utils.tsx renamed to examples/cookbook/app/custom-render/__tests__/test-utils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { render } from '@testing-library/react-native';
3-
import { User, UserProvider } from './providers/user-provider';
4-
import { Theme, ThemeProvider } from './providers/theme-provider';
3+
import { User, UserProvider } from '../../../app/custom-render/providers/user-provider';
4+
import { Theme, ThemeProvider } from '../../../app/custom-render/providers/theme-provider';
55

66
interface RenderWithProvidersProps {
77
user?: User | null;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as React from 'react';
2+
import { UserProvider } from './providers/user-provider';
3+
import { ThemeProvider } from './providers/theme-provider';
4+
import WelcomeScreen from './WelcomeScreen';
5+
6+
export default function Example() {
7+
return (
8+
<UserProvider.Provider value={null}>
9+
<ThemeProvider.Provider value={'light'}>
10+
<WelcomeScreen />
11+
</ThemeProvider.Provider>
12+
</UserProvider.Provider>
13+
);
14+
}

0 commit comments

Comments
 (0)