-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Description
Problem Statement
The current application lacks automated integration tests for critical user journeys. specifically the authentication and profile management workflows. This absence poses a high risk of regressions, meaning changes to the codebase could inadvertently break the login process or expose protected routes to unauthenticated users without immediate detection.
Current Behavior / Limitation
- There is no automated testing suite configured to validate the interactions in
src/components/Auth/LoginForm.jsxor the profile update logic. - Verification of these features currently requires manual testing (clicking through the UI) every time a change is made.
package.jsonmay lack the necessary scripts and dependencies for running modern React integration tests.
Expected Improvement
- A robust testing environment established using Vitest and React Testing Library.
- Automated tests that simulate real user behavior (typing credentials, clicking submit, navigating routes).
- Assurance that critical security paths (like redirecting unauthenticated users away from protected routes) function correctly.
Proposed Approach
-
Environment Setup:
- Install development dependencies:
vitest,jsdom,@testing-library/react,@testing-library/user-event, and@testing-library/jest-dom. - Update
vite.config.js(or create avitest.config.js) to configure the test environment. - Add a
"test": "vitest"script topackage.json.
- Install development dependencies:
-
Test Implementation (
src/tests/auth.test.jsx):- Login Flow:
- Render the
LoginFormcomponent wrapped in necessary providers (Router, AuthContext). - Simulate user input for email and password.
- Mock the API response (success and failure cases).
- Assert that a successful login redirects the user or updates the UI state.
- Assert that an invalid login displays an error message.
- Render the
- Protected Routes:
- Attempt to render a protected component without a valid token.
- Assert that the router redirects to the Login page.
- Profile Update:
- Simulate a form submission on the Profile page and verify the success message.
- Login Flow:
Verification Steps
To verify that the testing suite is correctly implemented:
- Install Dependencies: Run
npm installto ensure new testing libraries are available. - Run Tests: Execute
npm test(ornpm run test) in the terminal. - Validate Output:
- Ensure the terminal shows PASS for
src/tests/auth.test.js. - Verify that individual test cases (e.g., "should log in successfully", "should show error on invalid credentials") are checked off.
- Ensure the terminal shows PASS for
- Negative Testing (Proof of Utility):
- Go to
src/components/Auth/LoginForm.jsxand intentionally break the logic (e.g., comment out the submit handler or change the button type to "button" instead of "submit"). - Run
npm testagain. - Result: The test suite should FAIL, confirming that the tests are accurately catching regressions.
- Go to
Labels: ECWoC26
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels