Spaces:
Running
Running
File size: 5,903 Bytes
60b6623 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# Frontend Integration Tests
This directory contains integration tests that verify how different components work together in the PromptAid Vision frontend application.
## π― What are Integration Tests?
Integration tests verify that:
- **Components interact correctly** with each other
- **Context providers** work with their consumers
- **Routing** functions properly between components
- **State management** flows correctly through the app
- **User workflows** work end-to-end across multiple components
## π Test Files
### 1. **FilterBarWithFilterContext.test.tsx** (4 tests)
Tests the integration between `FilterBar` component and `FilterContext`:
- Filter updates trigger context changes
- Clear button resets context
- Loading states are properly displayed
- Current filters are shown from context
### 2. **HeaderNavWithRouting.test.tsx** (5 tests)
Tests the integration between `HeaderNav` component and routing:
- Logo click navigates to explore page
- Help link navigation works
- Admin link visibility based on user role
- Current page highlighting
### 3. **ExportModalWithAdminContext.test.tsx** (8 tests)
Tests the integration between `ExportModal` component and `AdminContext`:
- Admin-only features visibility
- Image selection handling
- Export button states
- Modal interactions
### 4. **HelpPageWithRouting.test.tsx** (7 tests)
Tests the integration between `HelpPage` component and routing:
- All help sections are displayed
- Back button navigation
- Admin-specific help visibility
- Contact information display
### 5. **AppWorkflow.test.tsx** (6 tests)
Tests complete application workflows:
- Complete user workflow (navigate, filter, export)
- Admin workflow (access admin features)
- Filter workflow (apply and clear filters)
- Navigation workflow (page transitions)
- Context integration (filters and admin state)
- Error handling workflow
## π Running Integration Tests
### Run All Integration Tests
```bash
npm run test:integration
```
### Run Specific Integration Test
```bash
npx vitest run src/test/integration/FilterBarWithFilterContext.test.tsx
```
### Run in Watch Mode
```bash
npx vitest src/test/integration --reporter=verbose
```
## π§ͺ Test Structure
Each integration test follows this pattern:
```typescript
describe('Component + Context Integration', () => {
beforeEach(() => {
// Setup mocks and reset state
});
test('Specific integration scenario', async () => {
// Render components with providers
// Simulate user interactions
// Verify component interactions
// Check context state changes
});
});
```
## π§ Mocking Strategy
Integration tests use strategic mocking:
- **Context Hooks**: Mock `useFilterContext` and `useAdminContext`
- **Routing**: Mock `useNavigate` and `useLocation`
- **External Libraries**: Mock `jszip` for export functionality
- **Component Dependencies**: Mock child components when needed
## π Test Coverage
Integration tests cover:
| Component | Context Integration | Routing Integration | Workflow Integration |
|-----------|-------------------|-------------------|-------------------|
| FilterBar | β
FilterContext | β | β |
| HeaderNav | β
AdminContext | β
React Router | β |
| ExportModal | β
AdminContext | β | β |
| HelpPage | β
AdminContext | β
React Router | β |
| App Workflow | β
All Contexts | β
React Router | β
Complete Workflows |
## π Test Scenarios
### User Workflows
1. **Filter and Export**: Apply filters β Select images β Export data
2. **Navigation**: Move between pages β Use back buttons β Logo navigation
3. **Admin Access**: Login β Access admin features β Manage data
### Component Interactions
1. **FilterBar β FilterContext**: State updates, loading states
2. **HeaderNav β AdminContext**: Role-based visibility
3. **ExportModal β AdminContext**: Feature access control
4. **HelpPage β Routing**: Navigation and page state
### Error Handling
1. **Empty States**: Handle missing data gracefully
2. **Loading States**: Show appropriate loading indicators
3. **Access Control**: Hide features based on user permissions
## π¨ Common Issues
### Mock Configuration
- Ensure all context hooks are properly mocked
- Verify routing mocks return expected values
- Check that component props match expected interfaces
### Async Operations
- Use `await userEvent.setup()` for user interactions
- Wait for state updates with `waitFor`
- Handle async context changes properly
### Component Rendering
- Wrap components with necessary providers
- Mock external dependencies (JSZip, etc.)
- Ensure test environment supports all required APIs
## π Debugging Tips
1. **Check Mock Returns**: Verify mocked functions return expected values
2. **Component Props**: Ensure components receive required props
3. **Provider Wrapping**: Check that all necessary context providers are included
4. **Async Timing**: Use `waitFor` for state changes and async operations
## π Adding New Integration Tests
To add a new integration test:
1. **Identify Integration Points**: Determine which components interact
2. **Choose Test Scope**: Decide on the level of integration to test
3. **Mock Dependencies**: Mock external services and context hooks
4. **Test User Flows**: Focus on realistic user interactions
5. **Verify State Changes**: Check that state flows correctly between components
## π― Best Practices
- **Test Real Interactions**: Focus on actual user workflows
- **Minimize Mocking**: Only mock what's necessary for isolation
- **Verify Integration**: Ensure components actually work together
- **Test Edge Cases**: Include error states and boundary conditions
- **Keep Tests Focused**: Each test should verify one integration aspect
Integration tests ensure that your components work together as expected, providing confidence that the application functions correctly as a whole system.
|