Implement Phase 8: Testing & Deployment
Testing Infrastructure: - Configure Jest with Next.js integration and TypeScript support - Add React Testing Library with proper setup for Next.js components - Install and configure Playwright for E2E testing - Create jest.setup.ts with mocks for Next.js router and browser APIs - Add CSS module mocking with identity-obj-proxy Unit Tests: - Create LoadingFallback component tests covering all 5 variants - Create tracking API tests for data transformation logic - Test createActivity, getActivities data structure conversions - Verify frontend (timestamp/data) to backend (startedAt/metadata) mapping E2E Tests (Playwright): - Create comprehensive tracking flow tests - Test navigation to all tracker pages (feeding, sleep, diaper) - Test homepage Today's Summary display - Test AI Assistant and Analytics navigation - Test feeding, sleep, and diaper tracker UI elements - Configure multi-browser testing (Chrome, Firefox, Safari, Mobile) CI/CD Pipeline (GitHub Actions): - Create automated CI/CD workflow for master/main branches - Run linting on every push and PR - Execute unit tests with coverage reporting - Run E2E tests (Chromium) in CI environment - Build application and upload artifacts - Upload test coverage to Codecov - Upload Playwright test reports as artifacts Test Scripts: - npm test: Run Jest unit tests - npm run test⌚ Run tests in watch mode - npm run test:coverage: Generate coverage report - npm run test:e2e: Run Playwright E2E tests - npm run test:e2e:ui: Run E2E tests with UI mode - npm run test:e2e:headed: Run E2E tests in headed mode Documentation: - Create comprehensive testing guide (tests/README.md) - Document test structure and best practices - Add troubleshooting section for common issues - Include useful commands for debugging tests Coverage Thresholds: - Branches: 70% - Functions: 70% - Lines: 70% - Statements: 70% 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
104
maternal-web/lib/api/__tests__/tracking.test.ts
Normal file
104
maternal-web/lib/api/__tests__/tracking.test.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { trackingApi } from '../tracking'
|
||||
import apiClient from '../client'
|
||||
|
||||
jest.mock('../client')
|
||||
|
||||
const mockedApiClient = apiClient as jest.Mocked<typeof apiClient>
|
||||
|
||||
describe('trackingApi', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('createActivity', () => {
|
||||
it('transforms frontend data to backend format', async () => {
|
||||
const mockActivity = {
|
||||
id: 'act_123',
|
||||
childId: 'chd_456',
|
||||
type: 'feeding',
|
||||
startedAt: '2024-01-01T12:00:00Z',
|
||||
metadata: { amount: 120, type: 'bottle' },
|
||||
loggedBy: 'usr_789',
|
||||
createdAt: '2024-01-01T12:00:00Z',
|
||||
}
|
||||
|
||||
mockedApiClient.post.mockResolvedValue({
|
||||
data: { data: { activity: mockActivity } },
|
||||
} as any)
|
||||
|
||||
const result = await trackingApi.createActivity('chd_456', {
|
||||
type: 'feeding',
|
||||
timestamp: '2024-01-01T12:00:00Z',
|
||||
data: { amount: 120, type: 'bottle' },
|
||||
})
|
||||
|
||||
expect(mockedApiClient.post).toHaveBeenCalledWith(
|
||||
'/api/v1/activities?childId=chd_456',
|
||||
{
|
||||
type: 'feeding',
|
||||
startedAt: '2024-01-01T12:00:00Z',
|
||||
metadata: { amount: 120, type: 'bottle' },
|
||||
notes: undefined,
|
||||
}
|
||||
)
|
||||
|
||||
expect(result).toEqual({
|
||||
...mockActivity,
|
||||
timestamp: mockActivity.startedAt,
|
||||
data: mockActivity.metadata,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('getActivities', () => {
|
||||
it('transforms backend data to frontend format', async () => {
|
||||
const mockActivities = [
|
||||
{
|
||||
id: 'act_123',
|
||||
childId: 'chd_456',
|
||||
type: 'feeding',
|
||||
startedAt: '2024-01-01T12:00:00Z',
|
||||
metadata: { amount: 120 },
|
||||
},
|
||||
{
|
||||
id: 'act_124',
|
||||
childId: 'chd_456',
|
||||
type: 'sleep',
|
||||
startedAt: '2024-01-01T14:00:00Z',
|
||||
metadata: { duration: 120 },
|
||||
},
|
||||
]
|
||||
|
||||
mockedApiClient.get.mockResolvedValue({
|
||||
data: { data: { activities: mockActivities } },
|
||||
} as any)
|
||||
|
||||
const result = await trackingApi.getActivities('chd_456', 'feeding')
|
||||
|
||||
expect(mockedApiClient.get).toHaveBeenCalledWith('/api/v1/activities', {
|
||||
params: { childId: 'chd_456', type: 'feeding' },
|
||||
})
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
id: 'act_123',
|
||||
childId: 'chd_456',
|
||||
type: 'feeding',
|
||||
startedAt: '2024-01-01T12:00:00Z',
|
||||
metadata: { amount: 120 },
|
||||
timestamp: '2024-01-01T12:00:00Z',
|
||||
data: { amount: 120 },
|
||||
},
|
||||
{
|
||||
id: 'act_124',
|
||||
childId: 'chd_456',
|
||||
type: 'sleep',
|
||||
startedAt: '2024-01-01T14:00:00Z',
|
||||
metadata: { duration: 120 },
|
||||
timestamp: '2024-01-01T14:00:00Z',
|
||||
data: { duration: 120 },
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user