Skip to content

Commit 10bda69

Browse files
vanGalileastevegalili
andauthored
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]>
1 parent d31c05a commit 10bda69

29 files changed

+1022
-217
lines changed

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/custom-render/WelcomeScreen.test.tsx renamed to examples/cookbook/__tests__/app/custom-render/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';
33
import { renderWithProviders } from './test-utils';
4-
import { WelcomeScreen } from './WelcomeScreen';
4+
import WelcomeScreen from "../../../app/custom-render";
55

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

examples/cookbook/custom-render/test-utils.tsx renamed to examples/cookbook/__tests__/app/custom-render/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;

examples/cookbook/jotai/TaskList.test.tsx renamed to examples/cookbook/__tests__/app/jotai/index.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as React from 'react';
22
import { render, screen, userEvent } from '@testing-library/react-native';
3+
import TaskList from '../../../app/jotai';
34
import { renderWithAtoms } from './test-utils';
4-
import { TaskList } from './TaskList';
5-
import { addTask, getAllTasks, newTaskTitleAtom, store, tasksAtom } from './state';
6-
import { Task } from './types';
5+
import { Task } from '../../../app/jotai/types';
6+
import { addTask, getAllTasks, newTaskTitleAtom, store, tasksAtom } from '../../../app/jotai/state';
77

88
jest.useFakeTimers();
99

examples/cookbook/app.json

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
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
1617
},
17-
"assetBundlePatterns": ["**/*"],
18+
"assetBundlePatterns": [
19+
"**/*"
20+
],
1821
"ios": {
1922
"supportsTablet": true
2023
},
@@ -26,6 +29,18 @@
2629
},
2730
"web": {
2831
"favicon": "./assets/favicon.png"
29-
}
32+
},
33+
"plugins": [
34+
"expo-router",
35+
[
36+
"expo-font",
37+
{
38+
"fonts": [
39+
"./assets/fonts/OpenSans-Regular.ttf",
40+
"./assets/fonts/OpenSans-Bold.ttf"
41+
]
42+
}
43+
]
44+
]
3045
}
3146
}

examples/cookbook/app/_layout.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Stack } from 'expo-router';
2+
import theme from '../theme';
3+
4+
export default function RootLayout() {
5+
return (
6+
<Stack
7+
screenOptions={{
8+
headerStyle: {
9+
backgroundColor: theme.colors.primary,
10+
},
11+
headerTintColor: '#fff',
12+
headerTitleStyle: {
13+
fontWeight: 'bold',
14+
},
15+
headerBackTitleVisible: false,
16+
}}
17+
>
18+
<Stack.Screen name="index" options={{ headerTitle: '' }} />
19+
</Stack>
20+
);
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Slot } from 'expo-router';
2+
import { UserProvider } from './providers/user-provider';
3+
import { ThemeProvider } from './providers/theme-provider';
4+
5+
export default function CustomRenderLayout() {
6+
return (
7+
<UserProvider.Provider value={null}>
8+
<ThemeProvider.Provider value={'light'}>
9+
<Slot />
10+
</ThemeProvider.Provider>
11+
</UserProvider.Provider>
12+
);
13+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import * as React from 'react';
2-
import { View, Text } from 'react-native';
2+
import { 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={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
1212
<Text>Hello {user ? user.name : 'Stranger'}</Text>
1313
<Text>Theme: {theme}</Text>
1414
</View>

0 commit comments

Comments
 (0)