@umituz/react-native-settings 4.20.62 → 4.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -61
- package/src/domains/gamification/components/AchievementCard.tsx +142 -0
- package/src/domains/gamification/components/AchievementItem.tsx +182 -0
- package/src/domains/gamification/components/AchievementToast.tsx +122 -0
- package/src/domains/gamification/components/GamificationScreen/AchievementsList.tsx +84 -0
- package/src/domains/gamification/components/GamificationScreen/Header.tsx +29 -0
- package/src/domains/gamification/components/GamificationScreen/StatsGrid.tsx +51 -0
- package/src/domains/gamification/components/GamificationScreen/index.tsx +111 -0
- package/src/domains/gamification/components/GamificationScreen/styles.ts +43 -0
- package/src/domains/gamification/components/GamificationScreen/types.ts +77 -0
- package/src/domains/gamification/components/GamificationScreenWrapper.tsx +4 -4
- package/src/domains/gamification/components/GamificationSettingsItem.tsx +1 -1
- package/src/domains/gamification/components/LevelProgress.tsx +129 -0
- package/src/domains/gamification/components/PointsBadge.tsx +60 -0
- package/src/domains/gamification/components/StatsCard.tsx +89 -0
- package/src/domains/gamification/components/StreakDisplay.tsx +119 -0
- package/src/domains/gamification/components/index.ts +13 -0
- package/src/domains/gamification/examples/gamification.config.example.ts +1 -1
- package/src/domains/gamification/hooks/useGamification.ts +91 -0
- package/src/domains/gamification/index.ts +46 -19
- package/src/domains/gamification/store/gamificationStore.ts +162 -0
- package/src/domains/gamification/types/index.ts +95 -23
- package/src/domains/gamification/types/settings.ts +28 -0
- package/src/domains/gamification/utils/calculations.ts +85 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -51
- package/.github/ISSUE_TEMPLATE/documentation.md +0 -52
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -63
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -84
- package/AI_AGENT_GUIDELINES.md +0 -367
- package/ARCHITECTURE.md +0 -246
- package/CHANGELOG.md +0 -67
- package/CODE_OF_CONDUCT.md +0 -75
- package/CONTRIBUTING.md +0 -107
- package/DOCUMENTATION_MIGRATION.md +0 -319
- package/DOCUMENTATION_TEMPLATE.md +0 -155
- package/SECURITY.md +0 -98
- package/SETTINGS_SCREEN_GUIDE.md +0 -185
- package/TESTING.md +0 -358
- package/src/__tests__/integration.test.tsx +0 -371
- package/src/__tests__/performance.test.tsx +0 -369
- package/src/__tests__/setup.test.tsx +0 -20
- package/src/__tests__/setup.ts +0 -154
- package/src/domains/about/__tests__/integration.test.tsx +0 -328
- package/src/domains/about/__tests__/types.d.ts +0 -5
- package/src/domains/about/domain/entities/__tests__/AppInfo.test.ts +0 -93
- package/src/domains/about/infrastructure/repositories/__tests__/AboutRepository.test.ts +0 -153
- package/src/domains/about/presentation/components/__tests__/AboutContent.simple.test.tsx +0 -178
- package/src/domains/about/presentation/components/__tests__/AboutContent.test.tsx +0 -293
- package/src/domains/about/presentation/components/__tests__/AboutHeader.test.tsx +0 -201
- package/src/domains/about/presentation/components/__tests__/AboutSettingItem.test.tsx +0 -71
- package/src/domains/about/presentation/hooks/__tests__/useAboutInfo.simple.test.tsx +0 -229
- package/src/domains/about/presentation/hooks/__tests__/useAboutInfo.test.tsx +0 -240
- package/src/domains/about/presentation/screens/__tests__/AboutScreen.simple.test.tsx +0 -199
- package/src/domains/about/presentation/screens/__tests__/AboutScreen.test.tsx +0 -366
- package/src/domains/about/utils/__tests__/index.test.ts +0 -408
- package/src/domains/appearance/__tests__/components/AppearanceScreen.test.tsx +0 -195
- package/src/domains/appearance/__tests__/hooks/index.test.tsx +0 -232
- package/src/domains/appearance/__tests__/integration/index.test.tsx +0 -207
- package/src/domains/appearance/__tests__/services/appearanceService.test.ts +0 -299
- package/src/domains/appearance/__tests__/setup.ts +0 -88
- package/src/domains/appearance/__tests__/stores/appearanceStore.test.tsx +0 -175
- package/src/domains/cloud-sync/presentation/components/__tests__/CloudSyncSetting.test.tsx +0 -78
- package/src/domains/legal/__tests__/ContentValidationService.test.ts +0 -195
- package/src/domains/legal/__tests__/StyleCacheService.test.ts +0 -110
- package/src/domains/legal/__tests__/UrlHandlerService.test.ts +0 -71
- package/src/domains/legal/__tests__/setup.ts +0 -82
- package/src/presentation/components/__tests__/SettingsErrorBoundary.test.tsx +0 -186
- package/src/presentation/screens/__tests__/SettingsScreen.test.tsx +0 -322
- package/src/presentation/screens/hooks/__tests__/useFeatureDetection.test.tsx +0 -261
package/SETTINGS_SCREEN_GUIDE.md
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
# Settings Screen
|
|
2
|
-
|
|
3
|
-
## Purpose
|
|
4
|
-
Main settings screen with modular architecture for displaying app settings in an organized, user-friendly interface.
|
|
5
|
-
|
|
6
|
-
## File Path
|
|
7
|
-
`src/presentation/screens/SettingsScreen.tsx`
|
|
8
|
-
|
|
9
|
-
## Imports
|
|
10
|
-
```typescript
|
|
11
|
-
import { SettingsScreen } from '@umituz/react-native-settings';
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Strategy
|
|
15
|
-
|
|
16
|
-
### Architecture Approach
|
|
17
|
-
- Use SettingsScreen as main entry point
|
|
18
|
-
- Configure features via config object
|
|
19
|
-
- Let screen auto-detect available features
|
|
20
|
-
- Keep screen logic minimal and declarative
|
|
21
|
-
|
|
22
|
-
### Configuration Strategy
|
|
23
|
-
1. Define settings config at app root
|
|
24
|
-
2. Pass config to SettingsScreen via params or props
|
|
25
|
-
3. Use feature flags for conditional display
|
|
26
|
-
4. Customize sections as needed
|
|
27
|
-
|
|
28
|
-
### Integration Pattern
|
|
29
|
-
1. Import SettingsScreen from package
|
|
30
|
-
2. Create settings configuration object
|
|
31
|
-
3. Define navigation structure
|
|
32
|
-
4. Handle user profile if needed
|
|
33
|
-
5. Add custom sections for app-specific settings
|
|
34
|
-
|
|
35
|
-
## Restrictions (Forbidden)
|
|
36
|
-
|
|
37
|
-
### ❌ DO NOT
|
|
38
|
-
- Create custom settings screens from scratch
|
|
39
|
-
- Duplicate SettingsScreen functionality
|
|
40
|
-
- Mix settings logic with business logic
|
|
41
|
-
- Hardcode feature availability
|
|
42
|
-
- Bypass feature detection system
|
|
43
|
-
|
|
44
|
-
### ❌ NEVER
|
|
45
|
-
- Modify SettingsScreen internals
|
|
46
|
-
- Override screen navigation logic
|
|
47
|
-
- Skip config normalization
|
|
48
|
-
- Ignore feature flags
|
|
49
|
-
- Mix UI and data layers in screen
|
|
50
|
-
|
|
51
|
-
### ❌ AVOID
|
|
52
|
-
- Over-complicating config object
|
|
53
|
-
- Creating one-off settings screens
|
|
54
|
-
- Inconsistent styling with design system
|
|
55
|
-
- Skipping error boundaries
|
|
56
|
-
- Not handling loading states
|
|
57
|
-
|
|
58
|
-
## Rules
|
|
59
|
-
|
|
60
|
-
### ✅ ALWAYS
|
|
61
|
-
- Use SettingsScreen for main settings
|
|
62
|
-
- Normalize config before passing
|
|
63
|
-
- Provide proper navigation structure
|
|
64
|
-
- Handle user profile authentication
|
|
65
|
-
- Include error boundaries
|
|
66
|
-
- Support feature detection
|
|
67
|
-
|
|
68
|
-
### ✅ MUST
|
|
69
|
-
- Follow SettingsConfig interface
|
|
70
|
-
- Use proper TypeScript types
|
|
71
|
-
- Handle all required params
|
|
72
|
-
- Support custom sections
|
|
73
|
-
- Maintain navigation consistency
|
|
74
|
-
- Test on both iOS and Android
|
|
75
|
-
|
|
76
|
-
### ✅ SHOULD
|
|
77
|
-
- Use auto-detection for features
|
|
78
|
-
- Group related settings together
|
|
79
|
-
- Provide meaningful section titles
|
|
80
|
-
- Support both modal and push navigation
|
|
81
|
-
- Include user profile for authenticated users
|
|
82
|
-
- Add custom sections for app-specific features
|
|
83
|
-
|
|
84
|
-
## Configuration Reference
|
|
85
|
-
|
|
86
|
-
See types file for complete config:
|
|
87
|
-
`src/presentation/screens/types/SettingsConfig.ts`
|
|
88
|
-
|
|
89
|
-
Config sections:
|
|
90
|
-
- `appearance`: Theme and color settings
|
|
91
|
-
- `language`: Language selection
|
|
92
|
-
- `notifications`: Notification preferences
|
|
93
|
-
- `about`: App information
|
|
94
|
-
- `legal`: Legal documents
|
|
95
|
-
- `disclaimer`: Legal notices
|
|
96
|
-
- `userProfile`: User profile display
|
|
97
|
-
- `feedback`: User feedback
|
|
98
|
-
- `rating`: App rating
|
|
99
|
-
- `faqs`: FAQ access
|
|
100
|
-
- `subscription`: Subscription/upgrade
|
|
101
|
-
- `wallet`: Wallet/payment
|
|
102
|
-
|
|
103
|
-
## Related Components
|
|
104
|
-
|
|
105
|
-
- **SettingsContent**: `src/presentation/screens/components/SettingsContent/SettingsContent.tsx`
|
|
106
|
-
- Main content composer used by SettingsScreen
|
|
107
|
-
|
|
108
|
-
- **SettingsHeader**: `src/presentation/screens/components/SettingsHeader/SettingsHeader.tsx`
|
|
109
|
-
- Header component for settings screen
|
|
110
|
-
|
|
111
|
-
- **SettingsConfig**: `src/presentation/screens/types/SettingsConfig.ts`
|
|
112
|
-
- Configuration type definitions
|
|
113
|
-
|
|
114
|
-
- **normalizeSettingsConfig**: `src/presentation/screens/utils/normalizeConfig.ts`
|
|
115
|
-
- Config normalization utility
|
|
116
|
-
|
|
117
|
-
- **useFeatureDetection**: `src/presentation/screens/hooks/useFeatureDetection.ts`
|
|
118
|
-
- Feature detection hook
|
|
119
|
-
|
|
120
|
-
## AI Agent Guidelines
|
|
121
|
-
|
|
122
|
-
### When Creating Settings Screens
|
|
123
|
-
|
|
124
|
-
1. **Use Existing Component**
|
|
125
|
-
- Import: `SettingsScreen` from `@umituz/react-native-settings`
|
|
126
|
-
- Don't create custom settings screens
|
|
127
|
-
|
|
128
|
-
2. **Configuration Setup**
|
|
129
|
-
- Reference: `src/presentation/screens/types/SettingsConfig.ts`
|
|
130
|
-
- Create config object following SettingsConfig interface
|
|
131
|
-
- Use normalizeSettingsConfig utility
|
|
132
|
-
- Enable features: `true`, `false`, or `'auto'`
|
|
133
|
-
|
|
134
|
-
3. **Feature Flags**
|
|
135
|
-
- `true`: Always show
|
|
136
|
-
- `false`: Never show
|
|
137
|
-
- `'auto'`: Auto-detect based on navigation
|
|
138
|
-
|
|
139
|
-
4. **Custom Sections**
|
|
140
|
-
- Add via `customSections` prop
|
|
141
|
-
- Follow CustomSettingsSection type
|
|
142
|
-
- Provide items array
|
|
143
|
-
|
|
144
|
-
5. **What to Avoid**
|
|
145
|
-
- Don't inline settings UI
|
|
146
|
-
- Don't bypass SettingsScreen
|
|
147
|
-
- Don't hardcode features
|
|
148
|
-
- Don't ignore feature detection
|
|
149
|
-
|
|
150
|
-
6. **Navigation Setup**
|
|
151
|
-
- Add to navigation stack
|
|
152
|
-
- Provide proper route name
|
|
153
|
-
- Handle params for config
|
|
154
|
-
|
|
155
|
-
### Configuration Pattern (Conceptual)
|
|
156
|
-
|
|
157
|
-
```
|
|
158
|
-
App Config → normalizeSettingsConfig → SettingsScreen
|
|
159
|
-
↓
|
|
160
|
-
Features → useFeatureDetection → Show/Hide sections
|
|
161
|
-
↓
|
|
162
|
-
Sections → FeatureSettingsSection, IdentitySettingsSection, etc.
|
|
163
|
-
↓
|
|
164
|
-
Items → SettingsItemCard for each setting
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
## File References
|
|
168
|
-
|
|
169
|
-
For implementation details, reference:
|
|
170
|
-
- Main screen: `src/presentation/screens/SettingsScreen.tsx`
|
|
171
|
-
- Content composer: `src/presentation/screens/components/SettingsContent/SettingsContent.tsx`
|
|
172
|
-
- Config types: `src/presentation/screens/types/SettingsConfig.ts`
|
|
173
|
-
- Normalization: `src/presentation/screens/utils/normalizeConfig.ts`
|
|
174
|
-
- Feature detection: `src/presentation/screens/hooks/useFeatureDetection.ts`
|
|
175
|
-
|
|
176
|
-
## Version Compatibility
|
|
177
|
-
|
|
178
|
-
- Requires React Navigation 6.x
|
|
179
|
-
- Requires TanStack Query 4.x+
|
|
180
|
-
- Requires Zustand 4.x+
|
|
181
|
-
- Compatible with React Native 0.60+
|
|
182
|
-
|
|
183
|
-
## License
|
|
184
|
-
|
|
185
|
-
MIT
|
package/TESTING.md
DELETED
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
# Testing Guide
|
|
2
|
-
|
|
3
|
-
Comprehensive testing strategy and guidelines for the `@umituz/react-native-settings` package covering unit tests, integration tests, and end-to-end testing approaches.
|
|
4
|
-
|
|
5
|
-
## Purpose
|
|
6
|
-
|
|
7
|
-
This document defines the testing philosophy, strategies, and best practices for ensuring code quality, reliability, and maintainability of the `@umituz/react-native-settings` package. It provides guidelines for testing at each architectural layer and establishes standards for test coverage, performance, and reliability.
|
|
8
|
-
|
|
9
|
-
## File Paths
|
|
10
|
-
|
|
11
|
-
**Base Directory**: `/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-settings/`
|
|
12
|
-
|
|
13
|
-
**Test Locations**:
|
|
14
|
-
- `/src/**/__tests__/` - Test files co-located with source code
|
|
15
|
-
- `/src/**/*.test.ts` - Unit test files
|
|
16
|
-
- `/src/**/*.test.tsx` - Component test files
|
|
17
|
-
- `/src/**/*.integration.test.ts` - Integration test files
|
|
18
|
-
- `/__tests__/` - Shared test utilities and fixtures
|
|
19
|
-
|
|
20
|
-
## Testing Philosophy
|
|
21
|
-
|
|
22
|
-
The settings package follows a comprehensive testing approach:
|
|
23
|
-
|
|
24
|
-
- **Unit Tests**: Test individual functions, hooks, and components in isolation
|
|
25
|
-
- **Integration Tests**: Test how multiple components work together
|
|
26
|
-
- **E2E Tests**: Test complete user flows across the application
|
|
27
|
-
- **Snapshot Tests**: Ensure UI consistency and prevent unintended changes
|
|
28
|
-
- **Performance Tests**: Monitor rendering performance and identify bottlenecks
|
|
29
|
-
|
|
30
|
-
### Testing Pyramid
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
/\
|
|
34
|
-
/ \
|
|
35
|
-
/ E2E \
|
|
36
|
-
/------\
|
|
37
|
-
/Integration\
|
|
38
|
-
/------------\
|
|
39
|
-
/ Unit Tests \
|
|
40
|
-
/----------------\
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
**Foundation**: Unit tests provide the base, being fast and numerous
|
|
44
|
-
**Middle**: Integration tests verify component interactions
|
|
45
|
-
**Top**: E2E tests validate critical user journeys (minimal in number)
|
|
46
|
-
|
|
47
|
-
## Test Configuration
|
|
48
|
-
|
|
49
|
-
### Jest Configuration
|
|
50
|
-
|
|
51
|
-
The project uses Jest as the testing framework with React Native preset. Configuration includes:
|
|
52
|
-
|
|
53
|
-
- **Preset**: React Native environment setup
|
|
54
|
-
- **Setup Files**: Custom test environment initialization
|
|
55
|
-
- **Transform Ignore Patterns**: Handle dependencies correctly
|
|
56
|
-
- **Test Match Patterns**: Locate test files automatically
|
|
57
|
-
- **Path Mapping**: Resolve module aliases correctly
|
|
58
|
-
- **Coverage Collection**: Track code coverage metrics
|
|
59
|
-
|
|
60
|
-
### Test Setup
|
|
61
|
-
|
|
62
|
-
Test setup includes:
|
|
63
|
-
|
|
64
|
-
- **Testing Library Extensions**: Custom matchers for React Native
|
|
65
|
-
- **Async Configuration**: Timeout settings for async operations
|
|
66
|
-
- **Mock Configuration**: Global mocks for external dependencies
|
|
67
|
-
- **Navigation Mocks**: React Navigation mock implementations
|
|
68
|
-
- **Storage Mocks**: AsyncStorage mock for data persistence
|
|
69
|
-
|
|
70
|
-
## Component Testing
|
|
71
|
-
|
|
72
|
-
### Testing Approach
|
|
73
|
-
|
|
74
|
-
Components are tested using React Native Testing Library with focus on:
|
|
75
|
-
|
|
76
|
-
- **User Interactions**: Test from user's perspective, not implementation details
|
|
77
|
-
- **Accessibility**: Verify accessibility attributes and labels
|
|
78
|
-
- **Props Validation**: Ensure correct prop handling and validation
|
|
79
|
-
- **Event Handling**: Verify callbacks and event handlers work correctly
|
|
80
|
-
- **Conditional Rendering**: Test different states and configurations
|
|
81
|
-
|
|
82
|
-
### Component Test Categories
|
|
83
|
-
|
|
84
|
-
**SettingsItemCard**: Reusable card component for settings items
|
|
85
|
-
- Rendering with various prop combinations
|
|
86
|
-
- Press interactions and callback execution
|
|
87
|
-
- Switch functionality and state changes
|
|
88
|
-
- Disabled state behavior
|
|
89
|
-
- Icon and subtitle display
|
|
90
|
-
- Snapshot verification
|
|
91
|
-
|
|
92
|
-
**SettingsSection**: Section wrapper component
|
|
93
|
-
- Title display and visibility
|
|
94
|
-
- Children rendering
|
|
95
|
-
- Conditional title display
|
|
96
|
-
- Styling and layout
|
|
97
|
-
|
|
98
|
-
**SettingsScreen**: Main settings screen
|
|
99
|
-
- Navigation integration
|
|
100
|
-
- Settings content composition
|
|
101
|
-
- Feature detection integration
|
|
102
|
-
- Loading and error states
|
|
103
|
-
|
|
104
|
-
## Hook Testing
|
|
105
|
-
|
|
106
|
-
### Testing Approach
|
|
107
|
-
|
|
108
|
-
Custom hooks are tested using `renderHook` from React Testing Library:
|
|
109
|
-
|
|
110
|
-
- **State Management**: Verify state changes and updates
|
|
111
|
-
- **Side Effects**: Test useEffect and other effect hooks
|
|
112
|
-
- **Return Values**: Validate hook return structure and values
|
|
113
|
-
- **Error Handling**: Test error states and error recovery
|
|
114
|
-
- **Performance**: Ensure hooks don't cause unnecessary re-renders
|
|
115
|
-
|
|
116
|
-
### Hook Test Categories
|
|
117
|
-
|
|
118
|
-
**useSettings**: Main settings management hook
|
|
119
|
-
- Loading initial settings
|
|
120
|
-
- Updating settings values
|
|
121
|
-
- Resetting to defaults
|
|
122
|
-
- Error handling
|
|
123
|
-
- Query invalidation
|
|
124
|
-
- Mutation behavior
|
|
125
|
-
|
|
126
|
-
**useFeatureDetection**: Feature availability detection
|
|
127
|
-
- Screen availability detection
|
|
128
|
-
- Configuration validation
|
|
129
|
-
- Navigation state checking
|
|
130
|
-
- Feature flag integration
|
|
131
|
-
|
|
132
|
-
## Service Testing
|
|
133
|
-
|
|
134
|
-
### Testing Approach
|
|
135
|
-
|
|
136
|
-
Services are tested in isolation with mocked dependencies:
|
|
137
|
-
|
|
138
|
-
- **Business Logic**: Verify core business rules and validations
|
|
139
|
-
- **Data Transformation**: Test data mapping and transformation
|
|
140
|
-
- **Error Handling**: Validate error scenarios and messages
|
|
141
|
-
- **Repository Integration**: Test interaction with repositories
|
|
142
|
-
- **Validation Logic**: Verify input validation and sanitization
|
|
143
|
-
|
|
144
|
-
### Service Test Categories
|
|
145
|
-
|
|
146
|
-
**SettingsService**: Core settings business logic
|
|
147
|
-
- Settings retrieval with defaults
|
|
148
|
-
- Settings updates and validation
|
|
149
|
-
- Settings reset functionality
|
|
150
|
-
- Invalid input handling
|
|
151
|
-
- Error propagation
|
|
152
|
-
- Business rule enforcement
|
|
153
|
-
|
|
154
|
-
## Integration Testing
|
|
155
|
-
|
|
156
|
-
### Testing Approach
|
|
157
|
-
|
|
158
|
-
Integration tests verify multiple components working together:
|
|
159
|
-
|
|
160
|
-
- **User Flows**: Test complete user interactions
|
|
161
|
-
- **Navigation**: Verify screen transitions and navigation
|
|
162
|
-
- **Data Flow**: Test data flow across components
|
|
163
|
-
- **State Management**: Verify global state updates
|
|
164
|
-
- **Error Recovery**: Test error handling across components
|
|
165
|
-
|
|
166
|
-
### Integration Test Categories
|
|
167
|
-
|
|
168
|
-
**Settings Screen Integration**
|
|
169
|
-
- Navigation to detail screens
|
|
170
|
-
- Settings updates and persistence
|
|
171
|
-
- Theme switching functionality
|
|
172
|
-
- Language selection and application
|
|
173
|
-
- Multi-step workflows
|
|
174
|
-
|
|
175
|
-
**Feature Integration**
|
|
176
|
-
- Feature detection with navigation
|
|
177
|
-
- Configuration-driven UI rendering
|
|
178
|
-
- Cross-feature interactions
|
|
179
|
-
|
|
180
|
-
## Performance Testing
|
|
181
|
-
|
|
182
|
-
### Testing Approach
|
|
183
|
-
|
|
184
|
-
Performance tests ensure components render efficiently:
|
|
185
|
-
|
|
186
|
-
- **Render Time**: Measure initial render performance
|
|
187
|
-
- **Re-render Behavior**: Verify memoization and optimization
|
|
188
|
-
- **Memory Usage**: Monitor memory consumption
|
|
189
|
-
- **Update Performance**: Test state update performance
|
|
190
|
-
|
|
191
|
-
### Performance Test Categories
|
|
192
|
-
|
|
193
|
-
**Component Performance**
|
|
194
|
-
- Initial render time measurements
|
|
195
|
-
- Unnecessary re-render detection
|
|
196
|
-
- Memo effectiveness verification
|
|
197
|
-
- Large list rendering performance
|
|
198
|
-
|
|
199
|
-
**Hook Performance**
|
|
200
|
-
- Hook execution time
|
|
201
|
-
- Dependency array optimization
|
|
202
|
-
- Effect cleanup verification
|
|
203
|
-
- Stale closure prevention
|
|
204
|
-
|
|
205
|
-
## Snapshot Testing
|
|
206
|
-
|
|
207
|
-
### Testing Approach
|
|
208
|
-
|
|
209
|
-
Snapshot tests track UI changes and prevent unintended modifications:
|
|
210
|
-
|
|
211
|
-
- **Component Snapshots**: Capture component render output
|
|
212
|
-
- **Configuration Variants**: Snapshot different prop combinations
|
|
213
|
-
- **Update Verification**: Review snapshot changes carefully
|
|
214
|
-
- **Selective Updates**: Update snapshots only for intended changes
|
|
215
|
-
|
|
216
|
-
### Snapshot Guidelines
|
|
217
|
-
|
|
218
|
-
- Review snapshot changes during code review
|
|
219
|
-
- Update snapshots only when changes are intentional
|
|
220
|
-
- Keep snapshots focused on meaningful UI structure
|
|
221
|
-
- Avoid snapshotting dynamic content (dates, IDs, etc.)
|
|
222
|
-
|
|
223
|
-
## Strategy
|
|
224
|
-
|
|
225
|
-
1. **Test-Driven Development**: Write tests before or alongside implementation, ensuring requirements are understood and code is testable from the start
|
|
226
|
-
|
|
227
|
-
2. **Pyramid Distribution**: Maintain a healthy testing pyramid with many unit tests, fewer integration tests, and minimal E2E tests for optimal feedback speed and maintenance cost
|
|
228
|
-
|
|
229
|
-
3. **User-Centric Testing**: Focus on testing user behavior and outcomes rather than implementation details, ensuring tests remain valid even when implementation changes
|
|
230
|
-
|
|
231
|
-
4. **Isolation and Independence**: Ensure tests are independent and can run in any order, using proper setup/teardown and avoiding shared state between tests
|
|
232
|
-
|
|
233
|
-
5. **Continuous Improvement**: Regularly review and update tests, refactor test code, and maintain high coverage while keeping tests fast and reliable
|
|
234
|
-
|
|
235
|
-
## Restrictions
|
|
236
|
-
|
|
237
|
-
### ❌ DO NOT
|
|
238
|
-
|
|
239
|
-
- Test implementation details instead of user behavior (e.g., checking internal state, method calls)
|
|
240
|
-
- Write fragile tests that break with minor refactoring
|
|
241
|
-
- Create tests that depend on execution order
|
|
242
|
-
- Use shared mutable state between tests
|
|
243
|
-
- Write tests that are slow or flaky
|
|
244
|
-
- Test third-party libraries or external services directly
|
|
245
|
-
|
|
246
|
-
### ❌ NEVER
|
|
247
|
-
|
|
248
|
-
- Commit commented-out test code or failing tests
|
|
249
|
-
- Mock or test the framework (React, Jest, React Native)
|
|
250
|
-
- Write tests without assertions or expectations
|
|
251
|
-
- Use arbitrary timeouts or waits instead of proper async handling
|
|
252
|
-
- Test multiple concerns in a single test case
|
|
253
|
-
- Skip testing error states and edge cases
|
|
254
|
-
|
|
255
|
-
### ❌ AVOID
|
|
256
|
-
|
|
257
|
-
- Over-mocking components, making tests brittle
|
|
258
|
-
- Testing trivial code (getters, simple pass-through functions)
|
|
259
|
-
- Creating complex test setups that are hard to understand
|
|
260
|
-
- Writing tests that are as complex as the code they test
|
|
261
|
-
- Relying on implementation-specific selectors or test IDs
|
|
262
|
-
- Testing absolute values that vary across environments
|
|
263
|
-
|
|
264
|
-
## Rules
|
|
265
|
-
|
|
266
|
-
### ✅ ALWAYS
|
|
267
|
-
|
|
268
|
-
- Write descriptive test names that explain what is being tested and why
|
|
269
|
-
- Use test helpers and custom matchers to reduce duplication
|
|
270
|
-
- Test both happy paths and error scenarios
|
|
271
|
-
- Follow the Arrange-Act-Assert pattern for clear test structure
|
|
272
|
-
- Clean up resources in afterEach or cleanup functions
|
|
273
|
-
- Use TypeScript for type-safe test code
|
|
274
|
-
|
|
275
|
-
### ✅ MUST
|
|
276
|
-
|
|
277
|
-
- Achieve and maintain minimum 80% code coverage
|
|
278
|
-
- Mock all external dependencies (APIs, storage, navigation)
|
|
279
|
-
- Test async operations properly with waitFor or act
|
|
280
|
-
- Verify accessibility attributes and labels
|
|
281
|
-
- Test error boundaries and error states
|
|
282
|
-
- Ensure tests run consistently across different environments
|
|
283
|
-
|
|
284
|
-
### ✅ SHOULD
|
|
285
|
-
|
|
286
|
-
- Group related tests with describe blocks
|
|
287
|
-
- Use beforeEach for common test setup
|
|
288
|
-
- Keep tests fast and focused
|
|
289
|
-
- Prioritize testing behavior over implementation
|
|
290
|
-
- Review and update tests when modifying code
|
|
291
|
-
- Use meaningful assertions with clear failure messages
|
|
292
|
-
|
|
293
|
-
## AI Agent Guidelines
|
|
294
|
-
|
|
295
|
-
### Writing New Tests
|
|
296
|
-
|
|
297
|
-
When creating new tests:
|
|
298
|
-
|
|
299
|
-
1. **Understand Requirements**: Clearly understand what functionality needs to be tested and why before writing tests
|
|
300
|
-
2. **Choose Right Level**: Decide whether to write unit, integration, or E2E tests based on what needs verification
|
|
301
|
-
3. **Follow Patterns**: Use existing test patterns and helpers in the codebase for consistency
|
|
302
|
-
4. **Test Behavior**: Focus on testing user-facing behavior and outcomes, not implementation details
|
|
303
|
-
|
|
304
|
-
### Modifying Existing Tests
|
|
305
|
-
|
|
306
|
-
When updating tests:
|
|
307
|
-
|
|
308
|
-
1. **Maintain Coverage**: Ensure test coverage doesn't decrease when modifying code
|
|
309
|
-
2. **Update Snapshots**: Review snapshot changes carefully and update only when intentional
|
|
310
|
-
3. **Add Missing Cases**: Look for uncovered edge cases and error scenarios
|
|
311
|
-
4. **Refactor Test Code**: Improve test code quality and maintainability alongside production code
|
|
312
|
-
|
|
313
|
-
### Debugging Test Failures
|
|
314
|
-
|
|
315
|
-
When tests fail:
|
|
316
|
-
|
|
317
|
-
1. **Understand Failure**: Read the error message and understand why the test failed
|
|
318
|
-
2. **Isolate Issue**: Run the failing test in isolation to confirm the failure
|
|
319
|
-
3. **Check Environment**: Verify test environment and mocks are properly configured
|
|
320
|
-
4. **Fix Root Cause**: Address the root cause, not just the test symptom
|
|
321
|
-
|
|
322
|
-
### Test Review Checklist
|
|
323
|
-
|
|
324
|
-
Review should verify:
|
|
325
|
-
|
|
326
|
-
- Tests cover both happy paths and error cases
|
|
327
|
-
- Test names clearly describe what is being tested
|
|
328
|
-
- Tests are independent and can run in any order
|
|
329
|
-
- No implementation details are being tested
|
|
330
|
-
- Async operations are handled properly
|
|
331
|
-
- Edge cases and boundaries are covered
|
|
332
|
-
- Tests are readable and maintainable
|
|
333
|
-
- Coverage metrics meet minimum requirements
|
|
334
|
-
|
|
335
|
-
## Running Tests
|
|
336
|
-
|
|
337
|
-
### Test Execution
|
|
338
|
-
|
|
339
|
-
- Run all tests: Execute complete test suite
|
|
340
|
-
- Watch mode: Run tests in watch mode for development
|
|
341
|
-
- Coverage: Generate coverage reports
|
|
342
|
-
- Specific tests: Run individual test files or patterns
|
|
343
|
-
- Filter tests: Run tests matching specific patterns
|
|
344
|
-
|
|
345
|
-
### Test Commands
|
|
346
|
-
|
|
347
|
-
All test commands should be executed from the project root directory with proper npm/yarn scripts.
|
|
348
|
-
|
|
349
|
-
## Related Documentation
|
|
350
|
-
|
|
351
|
-
- **ARCHITECTURE.md**: Understanding the architecture helps write better tests
|
|
352
|
-
- **Jest Documentation**: Testing framework reference
|
|
353
|
-
- **React Native Testing Library**: Component testing utilities
|
|
354
|
-
- **TanStack Query Documentation**: Testing hooks and queries
|
|
355
|
-
|
|
356
|
-
## License
|
|
357
|
-
|
|
358
|
-
MIT
|