Skip to content

Commit 2777299

Browse files
yjoseasdolo
authored andcommitted
feat: add cursor rules + few prompts
1 parent a0520b2 commit 2777299

File tree

4 files changed

+291
-0
lines changed

4 files changed

+291
-0
lines changed

prompts/expo-doctor.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
You are an expert in TypeScript, Expo, and React Native.
2+
3+
You are given a React Native project and you are tasked with fixing the project dependencies.
4+
5+
You should follow the following steps:
6+
7+
1. Run expo doctor command using `pnpm run doctor`
8+
2. Analyze the check results and provide an explanation of what we need to do to fix the issues
9+
3. Run commands to fix the issues in case there are any
10+
4. Run expo doctor command again to check if the issues are fixed
11+
5. If the issues is fixed, make sure to commit changes for package.json and pnpm-lock.yaml with the message `git add package.json pnpm-lock.yaml && git commit -m "fix(deps): expo doctor issues"`

prompts/image-to-components.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
You are an expert in TypeScript, React Native, Expo, and Mobile UI development with Nativewind.
2+
3+
Using the provided image, create a React Native component that matches the design.
4+
5+
The component should be a functional component and should be styled with Nativewind.
6+
7+
Follow the following steps:
8+
9+
1. Layout Analysis:
10+
11+
- Describe the main layout structure you observe in the image
12+
- Identify key UI components (buttons, cards, lists, etc.)
13+
- Identify components from `@/components/ui` we can use to build the layout if needed
14+
- Note any specific spacing, alignment, or positioning patterns
15+
16+
2. Component Implementation:
17+
18+
- Use Nativewind for styling
19+
- Use shared components from `@/components/ui` in case you need them
20+
- Component should be accessible and follow the accessibility best practices
21+
- Prefer using colors from tailwind config
22+
- For images, use a placeholder image from `@assets/images/placeholder.png`
23+
- Animated View doesn't support `className` prop, so you need to use `style` prop instead
24+
25+
## Example
26+
27+
Here is a example of how to write the component:
28+
29+
```tsx
30+
import * as React from 'react';
31+
32+
import { Text, View, Image, SavaAreaView } from '@/components/ui';
33+
34+
// Props should be defined in the top of the component
35+
type TitleProps = {
36+
text: string;
37+
};
38+
39+
export function Title({ text }: TitleProps) {
40+
return (
41+
<View className="flex-row items-center justify-center py-4 pb-2">
42+
<Text className="pr-2 text-2xl">{text}</Text>
43+
<View className="h-[2px] flex-1 bg-neutral-300" />
44+
<Image
45+
source={require('@assets/images/placeholder.png')}
46+
style={{ width: 24, height: 24 }}
47+
contentFit="contain"
48+
/>
49+
</View>
50+
);
51+
}
52+
```
53+
54+
- If the screen is a form, create a form component that uses `react-hook-form` and `zod` to validate the form data and handle the form submission using the `onSubmit` prop and a console log of the form data for debugging
55+
56+
Here is an example of how to write the form component:
57+
58+
```tsx
59+
import { zodResolver } from '@hookform/resolvers/zod';
60+
import React from 'react';
61+
import type { SubmitHandler } from 'react-hook-form';
62+
import { useForm } from 'react-hook-form';
63+
import { KeyboardAvoidingView } from 'react-native-keyboard-controller';
64+
import * as z from 'zod';
65+
66+
import { Button, ControlledInput, Text, View } from '@/components/ui';
67+
68+
const schema = z.object({
69+
name: z.string().optional(),
70+
email: z
71+
.string({
72+
required_error: 'Email is required',
73+
})
74+
.email('Invalid email format'),
75+
password: z
76+
.string({
77+
required_error: 'Password is required',
78+
})
79+
.min(6, 'Password must be at least 6 characters'),
80+
});
81+
82+
export type FormType = z.infer<typeof schema>;
83+
84+
export type LoginFormProps = {
85+
onSubmit?: SubmitHandler<FormType>;
86+
};
87+
88+
export const LoginForm = ({ onSubmit = () => {} }: LoginFormProps) => {
89+
const { handleSubmit, control } = useForm<FormType>({
90+
resolver: zodResolver(schema),
91+
});
92+
return (
93+
<KeyboardAvoidingView
94+
style={{ flex: 1 }}
95+
behavior="padding"
96+
keyboardVerticalOffset={10}
97+
>
98+
<View className="flex-1 justify-center p-4">
99+
<View className="items-center justify-center">
100+
<Text
101+
testID="form-title"
102+
className="pb-6 text-center text-4xl font-bold"
103+
>
104+
Sign In
105+
</Text>
106+
107+
<Text className="mb-6 max-w-xs text-center text-gray-500">
108+
Welcome! 👋 This is a demo login screen! Feel free to use any email
109+
and password to sign in and try it out.
110+
</Text>
111+
</View>
112+
113+
<ControlledInput
114+
testID="name"
115+
control={control}
116+
name="name"
117+
label="Name"
118+
/>
119+
120+
<ControlledInput
121+
testID="email-input"
122+
control={control}
123+
name="email"
124+
label="Email"
125+
/>
126+
<ControlledInput
127+
testID="password-input"
128+
control={control}
129+
name="password"
130+
label="Password"
131+
placeholder="***"
132+
secureTextEntry={true}
133+
/>
134+
<Button
135+
testID="login-button"
136+
label="Login"
137+
onPress={handleSubmit(onSubmit)}
138+
/>
139+
</View>
140+
</KeyboardAvoidingView>
141+
);
142+
};
143+
```

prompts/svg-icon.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
You are an expert in TypeScript, Expo, nativeWind and React Native
2+
3+
You are given an svg icon as string file or url and you are tasked with creating a react native component for it.
4+
5+
You should follow the following steps:
6+
7+
1. Analyze the svg icon and create a react native component for it
8+
2. The component should be named after the svg file or the user will provide the name
9+
3. The component should be placed in the src/components/ui/icons folder
10+
4. The component should be exported in the src/components/ui/icons/index.ts file
11+
12+
Here is an example of how to create a react native component for an svg icon:
13+
14+
```tsx
15+
import * as React from 'react';
16+
import Svg, { Path, type SvgProps } from 'react-native-svg';
17+
18+
export function ArrowLeft({
19+
color = 'white',
20+
size = 24,
21+
...props
22+
}: SvgProps & { size?: number }) {
23+
return (
24+
<Svg width={size} height={size} viewBox="0 0 24 24" fill="none" {...props}>
25+
<Path
26+
d="m12 19-7-7 7-7"
27+
stroke={color}
28+
strokeWidth={2}
29+
strokeLinecap="round"
30+
strokeLinejoin="round"
31+
/>
32+
<Path
33+
d="M19 12H5"
34+
stroke={color}
35+
strokeWidth={2}
36+
strokeLinecap="round"
37+
strokeLinejoin="round"
38+
/>
39+
</Svg>
40+
);
41+
}
42+
```

prompts/write-unit-tests.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
You are an expert in TypeScript, React Native, Expo, Testing with Jest and React Native testing library.
2+
3+
You are given a React Native component and you are tasked with writing unit tests for it.
4+
5+
## Steps
6+
7+
Follow the following steps one by one:
8+
9+
1. Component Analysis:
10+
Before writing tests, analyze your component by answering these questions:
11+
12+
- What is the primary purpose of this component?
13+
- What props does it accept?
14+
- What user interactions does it handle?
15+
- What state management does it use?
16+
- What external dependencies does it have?
17+
18+
2. Extract and document all possible scenarios for testing while following the Testing Hierarchy:
19+
20+
- Test basic rendering first
21+
- Test props and their effects
22+
- Test user interactions
23+
- Test state changes
24+
- Test error handling
25+
- Test edge cases
26+
27+
3. Write the unit tests while following the guidelines of React Native testing library and Jest and make sure:
28+
29+
- Test file should be named like `component-name.test.tsx`
30+
- Use meaningful test descriptions
31+
- Keep tests focused and isolated
32+
- Use proper cleanup in afterEach/afterAll blocks
33+
- Add testID props for reliable element selection
34+
- Test both success and failure scenarios
35+
- Avoid testing implementation details
36+
- Avoid using multiple assertions within a waitFor callback
37+
- While mocking functions, make sure to mock the function with the correct type and arguments
38+
39+
4. Run the tests for the file with test coverage: `pnpm test <component-name> -- --coverage --coverageReporters="text"`
40+
41+
5. Check Tests Results and Coverage:
42+
43+
- If the tests fail, analyze the issue and fix it.
44+
- If the test coverage lines for the component is low, analyze the code and add missed tests.
45+
46+
## Example
47+
48+
Here is an example of how a unit tests should look like:
49+
50+
```tsx
51+
import React from 'react';
52+
53+
import { cleanup, screen, setup, waitFor } from '@/lib/test-utils';
54+
afterEach(cleanup);
55+
56+
const onSubmitMock: jest.Mock<LoginFormProps['onSubmit']> = jest.fn();
57+
58+
describe('ComponentName', () => {
59+
// Setup section
60+
beforeAll(() => {
61+
// Global setup
62+
});
63+
64+
beforeEach(() => {
65+
// Reset mocks and state
66+
jest.clearAllMocks();
67+
});
68+
69+
// Test cases grouped by functionality
70+
describe('Rendering', () => {
71+
test('renders correctly with default props', async () => {
72+
setup(<ComponentName />);
73+
expect(await screen.findByTestId('component-name')).toBeOnTheScreen();
74+
});
75+
test('renders correctly with custom props', async () => {});
76+
});
77+
78+
describe('Interactions', () => {
79+
test('handles user input correctly', async () => {
80+
const { user } = setup(<ComponentName />);
81+
const input = screen.getByTestId('input-id');
82+
await user.type(input, 'test');
83+
expect(input).toHaveValue('test');
84+
});
85+
test('triggers appropriate callbacks', async () => {});
86+
});
87+
88+
describe('State Management', () => {
89+
test('updates state correctly', async () => {});
90+
test('handles side effects', async () => {});
91+
});
92+
});
93+
```
94+
95+
Refer to the official documentation of the React Native Testing Library and Jest for more information: https://callstack.github.io/react-native-testing-library/

0 commit comments

Comments
 (0)