-
Notifications
You must be signed in to change notification settings - Fork 7
Description
This plan covers testing for the new data fetching example added in this PR #279, including unit tests, integration tests, and component tests.
1. Component Tests
Test PostComponent renders loading state initially
Test PostComponent fetches and displays post data correctly
Test PostComponent fetches and displays comments correctly
Test PostComponent handles different postId props
Test PostComponent handles API errors gracefully (post fetch failure)
Test PostComponent handles API errors gracefully (comments fetch failure)
Test PostComponent displays empty comments array when no comments exist
Verify correct API endpoints are called with proper parameters
Test that postId changes trigger re-fetching
2. API Layer Tests
Test getPost() successfully fetches post data
Test getPost() handles network errors
Test getPost() handles non-200 responses
Test getComments() successfully fetches comments
Test getComments() handles network errors
Test getComments() handles non-200 responses
Verify correct URL construction for both functions
Test error messages are properly formatted
3. Service Layer Handler Tests
Test getPost() handler validates post ID parameter (valid integer)
Test getPost() handler rejects invalid post ID (non-numeric, negative, etc.)
Test getPost() handler successfully proxies to external API
Test getPost() handler handles external API errors (404, 500, etc.)
Test getPost() handler handles network failures
Test getComments() handler validates postId query parameter exists
Test getComments() handler rejects missing postId
Test getComments() handler successfully proxies to external API
Test getComments() handler handles external API errors
Test getComments() handler handles network failures
Verify proper HTTP status codes are returned
Verify proper error messages in responses
4. External Handler Tests
Test getExternalPost() returns correct post for valid ID
Test getExternalPost() returns 404 for non-existent post ID
Test getExternalPost() validates post ID format (rejects non-numeric)
Test getExternalPost() validates post ID format (rejects negative numbers)
Test getExternalComments() returns comments for valid postId
Test getExternalComments() returns empty array for post with no comments
Test getExternalComments() validates postId query parameter exists
Test getExternalComments() validates postId format (numeric)
Test getExternalComments() rejects missing postId
Verify response structure matches expected format
Test simulated network delay doesn't break functionality
5. Dashboard URL Parameters Tests
Test Dashboard displays path parameter (id) when present
Test Dashboard displays query parameters (q, name) when present
Test Dashboard handles multiple query parameters
Test Dashboard handles missing parameters gracefully
Test Dashboard renders greeting when name parameter is present
Test Dashboard renders all parameter information correctly
Test Dashboard link example works correctly