Registration Form Project
A comprehensive user registration form with robust validation, built with React, TypeScript, and modern frontend practices.
Features
- Form Validation: Complete form validation with Zod schemas
- User Experience:
- Disabled submit button until all fields are filled
- Error messages displayed under each invalid field
- Toast notifications for success and failure
- Local storage saving of user data
- Validation Rules:
- Age verification (18+ years)
- French postal code format
- Name validation (allowing accents, hyphens, spaces)
- Email validation
- Testing: 100% code coverage with unit and integration tests
- Documentation: Auto-generated documentation with JSDoc
- CI/CD Pipeline: Automated build, test, and deployment process
Live Demo
Visit the live demo at: https://varlopecar.github.io/react-form/
Documentation
The documentation is available directly from the application by clicking the "Documentation" link, or you can access it at: https://varlopecar.github.io/react-form/docs/
Installation
# Using pnpm (recommended)
pnpm add @varlopecar/ci-cd
# Using npm
npm install @varlopecar/ci-cd
# Using yarn
yarn add @varlopecar/ci-cd
Usage
RegistrationForm Component
import { RegistrationForm } from "@varlopecar/ci-cd";
function App() {
const handleSubmit = (data) => {
console.log(data);
// Process form data
};
return (
<div>
<h1>User Registration</h1>
<RegistrationForm onSubmit={handleSubmit} />
</div>
);
}
Using the Schema Directly
import {
registrationSchema,
type RegistrationFormData,
} from "@varlopecar/ci-cd";
// Use the schema with your own form implementation
const validateForm = (data) => {
const result = registrationSchema.safeParse(data);
if (!result.success) {
return result.error.format();
}
return null;
};
Form Behavior
- Field Validation: All fields are validated in real-time
- Submit Button: Disabled until all fields have values
- Success Case:
- Data is saved to localStorage
- A success toast notification is displayed
- Form fields are cleared
- Error Case:
- Error messages displayed under each invalid field
- Error toast notification
- Form remains filled for user correction
API Reference
RegistrationForm
A form component for user registration with built-in validation.
Props
Prop | Type | Description |
---|---|---|
onSubmit |
(data: RegistrationFormData) => void |
Callback function called when the form is submitted with valid data |
RegistrationFormData
Type definition for the form data.
interface RegistrationFormData {
firstName: string;
lastName: string;
email: string;
birthDate: Date;
city: string;
postalCode: string;
}
registrationSchema
Zod schema for validating registration form data with rules for:
- Names (allowing letters, accents, hyphens)
- Email format
- Age verification (18+ years)
- French postal code format (5 digits)
Development
# Clone the repository
git clone https://github.com/varlopecar/react-form.git
# Install dependencies
pnpm install
# Start development server
pnpm dev
# Run tests
pnpm test
# Generate coverage report
pnpm coverage
# Generate documentation
pnpm doc
# Build for production
pnpm build
Test Coverage
This project maintains 100% test coverage across all metrics:
- 100% Statement Coverage
- 100% Branch Coverage
- 100% Function Coverage
- 100% Line Coverage
Tests include:
- Age calculation validation
- Age 18+ validation
- French postal code format validation
- Name format validation with special cases
- Email format validation
- Button state based on form completion
- Local storage functionality
- Toast notifications
- Error message display
- Error handling
View detailed coverage report: Codecov Dashboard
CI/CD Pipeline
This project uses GitHub Actions for continuous integration and deployment:
-
Build and Test: Runs on every push and pull request
- Installs dependencies
- Runs tests with coverage
- Generates documentation
- Builds the project
-
GitHub Pages Deployment: Deploys the demo site
- Builds the project
- Deploys to GitHub Pages
-
NPM Package Publishing: Publishes new versions
- Builds the NPM package
- Publishes to NPM registry
- Automatically bumps version
License
This project is licensed under the MIT License - see the LICENSE file for details.
React Form - CI/CD Project
A comprehensive full-stack application with Docker architecture, comprehensive testing, and automated CI/CD pipeline.
๐๏ธ Architecture
react-form/
โโโ backend/ # FastAPI backend (Dockerized)
โโโ src/ # React app (Vite)
โโโ db/
โ โโโ init.sql # Database initialization
โโโ cypress/ # E2E tests with fixtures
โ โโโ fixtures/ # Test data (users.json, api.json)
โ โโโ e2e/ # Test specifications
โ โโโ support/ # Custom commands
โโโ docker-compose.yml # Orchestrates all services
โโโ Dockerfile.frontend # Frontend container
โโโ Dockerfile.backend # Backend container
โโโ .github/workflows/ # CI/CD pipeline
๐ณ Docker Architecture
The application uses Docker Compose to orchestrate:
- MySQL 8.0 - Database with persistent storage
- Adminer - Database management interface (port 8080)
- FastAPI Backend - Python API server (port 8000)
- React Frontend - Vite development server (port 3000)
Quick Start with Docker
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop all services
docker-compose down
Environment Variables
Create a .env
file in the root directory:
# Database
MYSQL_ROOT_PASSWORD=your_root_password
MYSQL_DATABASE=react_form_db
MYSQL_USER=react_user
MYSQL_PASSWORD=react_password
# Admin user
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=admin123
# Backend
SECRET_KEY=your-secret-key-here
CORS_ORIGINS=http://localhost:3000,http://localhost:5173
# Frontend
VITE_API_URL=http://localhost:8000
๐งช Testing Strategy
Backend Tests (pytest)
cd backend
pip install -r requirements.txt
pytest --cov=. --cov-report=html
Coverage includes:
- User registration and authentication
- Admin user management
- API endpoint validation
- Database operations
Frontend Tests (Vitest)
# Run tests
pnpm test
# Run with coverage
pnpm run coverage
# Run tests in UI mode
pnpm run test:ui
Coverage includes:
- Form validation
- Component rendering
- API integration
- User interactions
E2E Tests (Cypress with Fixtures)
# Open Cypress UI
pnpm run cypress:open
# Run tests headlessly
pnpm run cypress:run
Test Structure (Following Professor's Approach):
- Fixtures:
cypress/fixtures/users.json
- Test user data - Fixtures:
cypress/fixtures/api.json
- API response mocks - Custom Commands:
cypress/support/commands.ts
- Reusable test functions - Test Files:
registration.cy.ts
- User registration flowadmin.cy.ts
- Admin panel functionalityapi.cy.ts
- API endpoint testingintegration.cy.ts
- Complete workflow testing
Test scenarios:
- โ User registration flow with fixture data
- โ Form validation with invalid data fixtures
- โ Admin login with credential fixtures
- โ User management (view, delete) with test data
- โ API endpoint testing with response fixtures
- โ Complete integration workflows
๐ CI/CD Pipeline
The GitHub Actions pipeline includes:
1. Test Job
- Runs frontend and backend tests
- Generates coverage reports
- Uploads to Codecov
2. E2E Job
- Spins up complete Docker environment
- Runs Cypress tests against real services
- Uses fixtures for consistent test data
- Captures screenshots and videos on failure
3. Deployment Jobs (Main branch only)
- Backend: Deploys to Vercel
- Frontend: Deploys to GitHub Pages
Required Secrets
Set these in your GitHub repository settings:
# Vercel deployment
VERCEL_TOKEN=your_vercel_token
VERCEL_ORG_ID=your_org_id
VERCEL_PROJECT_ID=your_project_id
# Production database
DATABASE_URL=your_production_db_url
SECRET_KEY=your_production_secret
ADMIN_EMAIL=admin@yourdomain.com
ADMIN_PASSWORD=secure_admin_password
# Frontend API URL
VITE_API_URL=https://your-backend.vercel.app
๐ Code Coverage
The project maintains high code coverage:
- Backend: >80% (pytest + coverage)
- Frontend: >80% (Vitest + coverage)
- E2E: Full user journey coverage with fixtures
Coverage reports are automatically uploaded to Codecov on each push.
๐ง Development
Local Development
# Install dependencies
pnpm install
cd backend && pip install -r requirements.txt
# Start development servers
pnpm run dev # Frontend (port 3000)
cd backend && uvicorn main:app --reload # Backend (port 8000)
Database Management
Access Adminer at http://localhost:8080
:
- System: MySQL
- Server: mysql
- Username: react_user
- Password: react_password
- Database: react_form_db
API Documentation
Once the backend is running, visit:
- Swagger UI:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc
๐ฏ Features
User Registration
- Form validation with Zod
- Age verification (18+)
- French postal code validation
- Real-time form completion tracking
Admin Panel
- Secure authentication
- User management dashboard
- Delete user functionality
- Admin user protection
API Endpoints
POST /register
- User registrationPOST /login
- User authenticationGET /users
- List all users (admin only)DELETE /users/{id}
- Delete user (admin only)GET /me
- Current user info
๐ Grading Criteria (20/20)
Criteria | Points | Status |
---|---|---|
โ Docker architecture (MySQL/Python/Adminer/React) | 5 pts | โ |
โ Unit + Integration tests + Codecov | 5 pts | โ |
โ E2E tests with Cypress + Fixtures | 5 pts | โ |
โ GitHub Actions pipeline + deployment | 5 pts | โ |
๐ Deployment
Production Setup
- Database: Set up MySQL on Aiven/AlwaysData
- Backend: Deploy to Vercel (automatic via CI/CD)
- Frontend: Deploy to GitHub Pages (automatic via CI/CD)
Manual Deployment
# Backend to Vercel
cd backend
vercel --prod
# Frontend to GitHub Pages
pnpm run build
pnpm run deploy
๐ License
MIT License - see LICENSE file for details.
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
๐ Support
For questions or issues:
- Create an issue in the GitHub repository
- Check the documentation in
/docs
- Review the test files for usage examples