Spaces:
Running
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
npm run test:integration
Run Specific Integration Test
npx vitest run src/test/integration/FilterBarWithFilterContext.test.tsx
Run in Watch Mode
npx vitest src/test/integration --reporter=verbose
π§ͺ Test Structure
Each integration test follows this pattern:
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
anduseAdminContext
- Routing: Mock
useNavigate
anduseLocation
- 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
- Filter and Export: Apply filters β Select images β Export data
- Navigation: Move between pages β Use back buttons β Logo navigation
- Admin Access: Login β Access admin features β Manage data
Component Interactions
- FilterBar β FilterContext: State updates, loading states
- HeaderNav β AdminContext: Role-based visibility
- ExportModal β AdminContext: Feature access control
- HelpPage β Routing: Navigation and page state
Error Handling
- Empty States: Handle missing data gracefully
- Loading States: Show appropriate loading indicators
- 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
- Check Mock Returns: Verify mocked functions return expected values
- Component Props: Ensure components receive required props
- Provider Wrapping: Check that all necessary context providers are included
- Async Timing: Use
waitFor
for state changes and async operations
π Adding New Integration Tests
To add a new integration test:
- Identify Integration Points: Determine which components interact
- Choose Test Scope: Decide on the level of integration to test
- Mock Dependencies: Mock external services and context hooks
- Test User Flows: Focus on realistic user interactions
- 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.