-
Notifications
You must be signed in to change notification settings - Fork 29
Add Tests for Components #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Set up complete testing framework with Vitest, @testing-library/svelte, and MSW - Create test utilities and fixtures for OneBusAway API data - Implement map provider mocks for both Leaflet and Google Maps - Add 228 passing component tests covering navigation, stops, routes, search, and trip-planner - Configure MSW handlers for realistic API response testing - Add test setup for Svelte 5 runes compatibility - Create comprehensive test fixtures with realistic transit data - Fix all ESLint errors and ensure code quality standards
- Enhanced AlertsModal.test.js with proper Svelte 5 support and mocking - Updated MobileMenu.test.js for better test reliability - Improved ModalPane.test.js with comprehensive test coverage - Fixed component implementations to support improved testing
- Enhanced RouteModal.test.js with better Svelte 5 compatibility - Improved ViewAllRoutesModal.test.js with comprehensive test coverage - Updated mocking strategies for better test reliability
- Enhanced SearchField.test.js with proper Svelte 5 support - Improved SearchPane.test.js with comprehensive test coverage - Updated SearchResultItem.test.js for better reliability - Fixed unhandled promise rejection in SearchPane.svelte by adding try-catch error handling - Updated component implementations to support improved testing
- Enhanced StopItem.test.js with better test coverage - Improved StopModal.test.js with comprehensive Svelte 5 support - Updated StopPageHeader.test.js for better reliability - Enhanced StopPane.test.js with proper mocking and test structure
- Enhanced TripPlanSearchField.test.js with proper Svelte 5 support - Updated component implementation for better testability - Improved mocking strategies for reliable test execution
- Enhanced keybinding.test.js with comprehensive test coverage - Updated keybinding.js implementation for better testability - Improved utility functions with proper error handling
- Enhanced vitest-setup.js with improved global test configuration - Added better mock setup for comprehensive test coverage - Improved test environment configuration for Svelte 5 support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive testing infrastructure and component tests for the Svelte application.
- Introduces a global Vitest setup (
vitest-setup.js
) with mocks for browser APIs, SvelteKit stores, environment variables, and i18n. - Updates
vite.config.js
to include the Svelte testing plugin, configure coverage reporters, thresholds, and setup files. - Adds MSW server setup, mock providers, shared test utilities, fixtures, and dozens of new component tests.
Reviewed Changes
Copilot reviewed 32 out of 33 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
vitest-setup.js | Adds global mocks for browser APIs, env vars, i18n |
vite.config.js | Includes @testing-library/svelte plugin and coverage config |
src/tests/setup/msw-server.js | Configures MSW server lifecycle for tests |
src/tests/mocks/mapProviders.js | Provides mock implementations for map providers |
src/tests/helpers/test-utils.js | Shared render and store mock utilities |
src/components/search/SearchField.svelte | Trim and validate search input with error handling |
src/components/search/SearchPane.svelte | Wraps route fetch in try/catch |
src/lib/keybinding.js | Refactors keybinding action to support updates |
Comments suppressed due to low confidence (3)
src/components/search/SearchField.svelte:13
- Add a check for
response.ok
before parsing JSON. If the response is not OK, handle or forward the error (e.g., callhandleSearchResults({ error: ... })
) instead of always callingresponse.json()
.
async function handleSearch() {
src/tests/mocks/handlers.js:65
- [nitpick] Using
Date.now()
directly in handlers leads to non-deterministic test data. Consider using a fixed timestamp or mockingDate.now()
withvi.useFakeTimers()
for stable and reproducible tests.
serviceDate: Date.now(),
src/lib/keybinding.js:15
- Ensure that
setHandler()
is invoked on mount (without arguments) so the initial keydown listener is registered. If omitted, the action will never listen for key events until an update occurs.
const setHandler = (newParams) => {
polyline = mapProvider.createPolyline(shape); | ||
polylines.push(polyline); | ||
try { | ||
const response = await fetch(`/api/oba/stops-for-route/${route.id}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add if (!response.ok)
handling after this fetch to avoid unhandled JSON parsing errors. Consider notifying the user or falling back gracefully instead of only logging to console.
const response = await fetch(`/api/oba/stops-for-route/${route.id}`); | |
const response = await fetch(`/api/oba/stops-for-route/${route.id}`); | |
if (!response.ok) { | |
throw new Error(`Failed to fetch route data: ${response.status} ${response.statusText}`); | |
} |
Copilot uses AI. Check for mistakes.
})); | ||
|
||
// Mock environment variables | ||
vi.mock('$env/static/public', () => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Tests import $env/dynamic/public
in some modules. Consider adding a mock for $env/dynamic/public
here to ensure consistent environment variable behavior across tests.
Copilot uses AI. Check for mistakes.
- Remove unused imports and variables - Fix ESLint no-unused-vars warnings - Apply Prettier formatting fixes
- Update caniuse-lite to latest version - Resolves outdated browser data warning
No description provided.