215 lines
6.5 KiB
Markdown
215 lines
6.5 KiB
Markdown
# Testing Patterns
|
|
|
|
**Analysis Date:** 2026-02-15
|
|
|
|
## Test Framework
|
|
|
|
**Runner:**
|
|
- Not detected - no test runner configured in package.json
|
|
- No Vitest, Jest, Mocha, or other test framework installed
|
|
- No test scripts in `package.json` for either frontend or backend
|
|
|
|
**Assertion Library:**
|
|
- Not installed - no testing dependencies found
|
|
|
|
**Run Commands:**
|
|
- No test commands available
|
|
- Frontend: `npm run dev`, `npm run build`, `npm run preview`
|
|
- Backend: `npm start`, `npm run dev` (nodemon)
|
|
|
|
## Test File Organization
|
|
|
|
**Location:**
|
|
- No test files found in project
|
|
- No `.test.js`, `.spec.js`, `.test.jsx`, or `.spec.jsx` files in source directories
|
|
- No `__tests__` directories present
|
|
|
|
**Naming:**
|
|
- Not applicable - no tests exist
|
|
|
|
**Structure:**
|
|
- Not applicable - no tests exist
|
|
|
|
## Current Test Status
|
|
|
|
**Coverage:**
|
|
- Not tested - zero test files, no coverage tooling
|
|
- No test requirements or targets defined
|
|
- No test configuration files (vitest.config.*, jest.config.*, etc.)
|
|
|
|
**View Coverage:**
|
|
- Not applicable - no coverage tools present
|
|
|
|
## Testing Gaps
|
|
|
|
### High Priority
|
|
|
|
**Authentication Flow:**
|
|
- Location: `frontend/src/context/AuthContext.jsx`, `frontend/src/pages/LoginPage.jsx`, `frontend/src/pages/RegisterPage.jsx`, `backend/src/index.js` (routes)
|
|
- Missing: Token validation, login/register error handling, token expiration, protected route behavior
|
|
- Risk: Auth system could silently fail or allow unauthorized access
|
|
|
|
**Workout Logging:**
|
|
- Location: `frontend/src/App.jsx` (logSet function), `backend/src/index.js` (POST /api/logs)
|
|
- Missing: Set creation/update, duplicate handling, weight/reps validation, concurrent updates
|
|
- Risk: Incorrect workout data, lost entries, or duplicate logs
|
|
|
|
**API Error Handling:**
|
|
- Location: All fetch calls in `frontend/src/**`, all route handlers in `backend/src/index.js`
|
|
- Missing: Network failures, timeout handling, malformed responses, edge cases
|
|
- Risk: Silent failures, infinite loading states, unhandled exceptions
|
|
|
|
### Medium Priority
|
|
|
|
**Profile Management:**
|
|
- Location: `frontend/src/pages/ProfilePage.jsx`, `frontend/src/pages/OnboardingWizard.jsx`, `backend/src/index.js` (user routes)
|
|
- Missing: Profile updates, measurements tracking, strength tracking, optional field handling
|
|
- Risk: Lost user data, incorrect profile state
|
|
|
|
**Program Navigation:**
|
|
- Location: `frontend/src/pages/Dashboard.jsx`, `frontend/src/App.jsx`, `backend/src/index.js` (program routes)
|
|
- Missing: Week/day navigation, today's workout calculation, day cycling logic
|
|
- Risk: Wrong workout shown, incorrect day assignments
|
|
|
|
**Data Validation:**
|
|
- Location: All form submissions (Login, Register, Profile updates), API inputs
|
|
- Missing: Email format validation, password requirements, numeric field bounds, null checks
|
|
- Risk: Invalid data persisted, server errors, SQL injection (though using parameterized queries)
|
|
|
|
### Low Priority
|
|
|
|
**UI State Management:**
|
|
- Location: `frontend/src/App.jsx`, `frontend/src/pages/Dashboard.jsx`
|
|
- Missing: View transitions, state consistency between pages, race conditions in state updates
|
|
- Risk: Inconsistent UI, stale data display
|
|
|
|
**Warmup Tracking:**
|
|
- Location: `frontend/src/pages/WorkoutPage.jsx`
|
|
- Missing: Warmup completion tracking, persistence, session state
|
|
- Risk: Lost warmup progress on page reload
|
|
|
|
## Recommended Testing Strategy
|
|
|
|
### Phase 1: Core Functionality
|
|
1. **Auth Integration Tests**
|
|
- Register → Login → Protected Route → Logout flow
|
|
- Error cases (invalid credentials, duplicate email)
|
|
- Token persistence across page reloads
|
|
|
|
2. **Workout Logging Integration Tests**
|
|
- Log set → Verify in state → Verify in API
|
|
- Update existing log vs create new
|
|
- Progression calculation
|
|
|
|
3. **API Unit Tests**
|
|
- Backend route handlers with mocked database
|
|
- Error handling (400, 401, 404, 500 status codes)
|
|
- Database constraint handling (duplicate email, foreign keys)
|
|
|
|
### Phase 2: Data Integrity
|
|
1. Form validation tests (Login, Register, Profile, Measurements)
|
|
2. Profile update consistency tests
|
|
3. Program/day/exercise relationship tests
|
|
|
|
### Phase 3: UI/UX
|
|
1. Component rendering tests (pages, conditional displays)
|
|
2. State transition tests (view changes, navigation)
|
|
3. Loading/error states display
|
|
|
|
## Testing Patterns (When Tests Are Added)
|
|
|
|
### Frontend (React) Pattern
|
|
```javascript
|
|
// Expected pattern for future tests
|
|
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
import { BrowserRouter } from 'react-router-dom';
|
|
import { AuthProvider } from '../context/AuthContext';
|
|
import LoginPage from '../pages/LoginPage';
|
|
|
|
describe('LoginPage', () => {
|
|
it('should submit login form with valid credentials', async () => {
|
|
render(
|
|
<BrowserRouter>
|
|
<AuthProvider>
|
|
<LoginPage />
|
|
</AuthProvider>
|
|
</BrowserRouter>
|
|
);
|
|
|
|
fireEvent.change(screen.getByPlaceholderText('E-post'), { target: { value: 'test@example.com' } });
|
|
fireEvent.change(screen.getByPlaceholderText('Lösenord'), { target: { value: 'password123' } });
|
|
fireEvent.click(screen.getByText('Logga in'));
|
|
|
|
await waitFor(() => {
|
|
expect(screen.queryByText('Loggar in...')).not.toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
```
|
|
|
|
### Backend (Express) Pattern
|
|
```javascript
|
|
// Expected pattern for future tests
|
|
const request = require('supertest');
|
|
const app = require('../index');
|
|
|
|
describe('POST /api/auth/login', () => {
|
|
it('should return 401 for invalid credentials', async () => {
|
|
const res = await request(app)
|
|
.post('/api/auth/login')
|
|
.send({ email: 'test@example.com', password: 'wrong' });
|
|
|
|
expect(res.status).toBe(401);
|
|
expect(res.body).toHaveProperty('error');
|
|
});
|
|
|
|
it('should return token for valid credentials', async () => {
|
|
const res = await request(app)
|
|
.post('/api/auth/login')
|
|
.send({ email: 'test@example.com', password: 'correct' });
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(res.body).toHaveProperty('token');
|
|
expect(res.body).toHaveProperty('user');
|
|
});
|
|
});
|
|
```
|
|
|
|
## Setup Recommendations
|
|
|
|
**Install testing dependencies:**
|
|
```bash
|
|
# Frontend
|
|
npm install --save-dev @testing-library/react @testing-library/jest-dom vitest
|
|
|
|
# Backend
|
|
npm install --save-dev supertest jest
|
|
```
|
|
|
|
**Create config files:**
|
|
- `frontend/vitest.config.js` - Configure for React components
|
|
- `backend/jest.config.js` - Configure for Node.js
|
|
|
|
**Test structure:**
|
|
```
|
|
frontend/src/
|
|
__tests__/
|
|
context/
|
|
AuthContext.test.jsx
|
|
pages/
|
|
LoginPage.test.jsx
|
|
Dashboard.test.jsx
|
|
components/
|
|
Icons.test.jsx
|
|
|
|
backend/src/
|
|
__tests__/
|
|
auth.test.js
|
|
programs.test.js
|
|
logs.test.js
|
|
```
|
|
|
|
---
|
|
|
|
*Testing analysis: 2026-02-15*
|