test: added test cases for categories
Description:
Added extensive unit test coverage for the Categories component to ensure reliability, proper user interaction handling, and robust validation across multiple scenarios.
This test suite covers:
-
Component Rendering: Verified initial loading state, header (SwechaLogo & Corpus branding), navigation bar, and page content.
-
Category Display Logic: Ensured categories are fetched correctly from the API, unpublished categories are filtered out, and results are sorted by rank. Also tested icons, descriptions, empty states, and API error handling.
-
Category Selection Flow: Validated user interaction when selecting categories, including modal display, selected category state, and back navigation.
-
Upload Options: Tested all supported upload modes (Text, Audio, Video, Image, Document) with correct icons and descriptions.
-
User Interactions: Covered logout, back navigation, search toggle, and profile navigation functionality.
-
Session Management: Verified handling of expired sessions (401/403), JWT validation, and proper triggering of
onSessionExpiredor fallback toonLogout. -
Props Handling: Ensured correct usage of props like token, preSelectedMediaType, and callback functions.
-
Edge Cases & Error Handling: Added robust tests for network failures, invalid JWTs, missing user data, geolocation issues, invalid coordinates, unknown categories, and sorting behavior.
-
Navigation Links: Verified routing for Home, Peer Review, Annotate, and Profile pages.
-
Responsive Layout: Tested grid layouts for categories and upload options.
-
Accessibility: Ensured proper roles for buttons and links.
-
Upload Validation: Covered validation logic for required fields such as category, title, location, user ID, release rights, language, and file/text inputs.
-
Upload Error Handling & Success Flow: Tested error scenarios (network failures, chunk upload errors, logging) and successful upload flow including toast notifications, state reset, and redirect behavior.
Overall, this significantly improves test coverage and ensures stability for core user flows.
Type of Change:
-
Bug Fix -
Feature Development -
Documentation
Testing:
-
Tested on desktop -
Tested on mobile -
Tested in different browsers
Tested using:
npm run testnpm run test:coverage
Checklist:
-
Code follows project style guidelines -
Self-review completed -
No console errors -
TypeScript types are correct
closes #251 (closed)
