feat: Sistema controllo accessi Focolari completo con test E2E

🎯 Funzionalità Implementate:
- Frontend React/TypeScript/Tailwind ottimizzato per tablet
- Backend mock FastAPI con API complete
- Hook RFID multi-pattern (US: ;? / IT: ò_)
- Flusso validatore → partecipante → conferma ingresso
- Carosello benvenuto multilingua (10 lingue, animazione smooth)
- Gestione sessione con invalidazione su server restart
- Pagina debug RFID accessibile da /debug

🧪 Test Implementati:
- 56 unit test (Vitest) - hook RFID, API, componenti
- 14 test E2E (Playwright) - flussi completi con browser reale
- Test sicurezza: verifica blocco backend per utenti non ammessi

📋 Comandi Disponibili:
- ./dev.sh install     → Setup dipendenze
- ./dev.sh dev         → Sviluppo (hot reload)
- ./dev.sh server      → Produzione locale
- ./dev.sh test        → Unit test
- ./dev.sh test:e2e    → Test E2E headless
- ./dev.sh test:e2e:headed → Test E2E con browser visibile
- ./dev.sh test:e2e:ui → Playwright UI per debug

📝 Documentazione:
- README.md con guida completa
- API_SPECIFICATION.md per backend reale
- TEST_CHECKLIST.md per test manuali
- Piani sviluppo in ai-prompts/

 Stato: MVP completo, in attesa di feedback e richieste future
This commit is contained in:
2026-01-24 18:29:54 +01:00
parent f59c7af383
commit 855d2b3160
18 changed files with 3038 additions and 56 deletions

133
README.md
View File

@@ -47,11 +47,140 @@ VotoFocolari/
./dev.sh build # Solo build frontend
./dev.sh backend # Solo backend (API)
./dev.sh frontend # Solo frontend dev
./dev.sh test # Esegue i test frontend
./dev.sh test:watch # Test in watch mode
./dev.sh test:dev # Server + test watch mode
./dev.sh shell # Shell pipenv backend
./dev.sh clean # Pulisce build e cache
./dev.sh help # Mostra tutti i comandi
```
## 🧪 Test
Il progetto include una suite completa di **56 test automatici** per il frontend.
### Comandi Test
```bash
# Esegue tutti i test una volta (CI/CD)
./dev.sh test
# Test in watch mode - riesegue automaticamente quando modifichi i file
./dev.sh test:watch
# Server + Test watch mode - utile per test manuali + automatici insieme
./dev.sh test:dev
```
### Come usare `test:watch`
Il watch mode è utile durante lo sviluppo:
1. **Avvia i test in watch mode:**
```bash
./dev.sh test:watch
```
2. **Cosa succede:**
- I test vengono eseguiti immediatamente
- Vitest rimane in ascolto dei cambiamenti
- Quando salvi un file `.ts` o `.tsx`, i test correlati vengono rieseguiti automaticamente
3. **Comandi interattivi** (mentre è in esecuzione):
- `a` - Riesegui tutti i test
- `f` - Riesegui solo i test falliti
- `p` - Filtra per nome file
- `t` - Filtra per nome test
- `q` - Esci
4. **Per test manuali + automatici insieme:**
```bash
./dev.sh test:dev
```
Questo avvia sia il server (http://localhost:8000) che i test in watch mode, così puoi:
- Testare manualmente nel browser
- Vedere i test automatici aggiornarsi in tempo reale
### Copertura Test (56 test)
| Categoria | Test | Descrizione |
|--------------------|------|----------------------------------------------------------------|
| **useRFIDScanner** | 20 | Pattern US/IT, timeout, ESC, Enter handling |
| **API Service** | 13 | Endpoint, error handling, badge stringa, **bypass protection** |
| **UserCard** | 9 | Rendering, stati ammesso/non ammesso |
| **Configurazione** | 14 | Timeout, sessione, invalidazione server restart |
### Test Critico: Backend Safety
Il test `should block non-ammesso user even if frontend bug sends request` verifica che:
- Anche se un bug nel frontend permette di inviare una richiesta per un utente NON ammesso
- Il **backend** risponde comunque con `success: false`
- Questo è un controllo di sicurezza a livello server
### Tipi di Test
⚠️ **Nota:** I test attuali sono **unit test** che girano in un DOM simulato (jsdom).
Non aprono un browser reale. Per test End-to-End (E2E) che aprono il browser,
servirebbe Playwright o Cypress (non ancora implementato).
### Con npm direttamente
```bash
cd frontend
npm run test:run # Esecuzione singola
npm run test # Watch mode
npm run test:coverage # Con coverage report
```
## 🎭 Test E2E (Playwright)
Test End-to-End che aprono un **browser reale** e verificano i flussi completi dell'applicazione.
### Comandi E2E
| Comando | Descrizione |
|----------------------------|------------------------------------------------------------------------------------|
| `./dev.sh test:e2e` | Test **headless** (senza vedere il browser), server avviato automaticamente |
| `./dev.sh test:e2e:headed` | Test con **browser visibile**, server avviato automaticamente |
| `./dev.sh test:e2e:ui` | Apre **Playwright UI** (IDE interattivo per debug), server avviato automaticamente |
```bash
# Test veloci (headless)
./dev.sh test:e2e
# Test con browser visibile (per vedere cosa succede)
./dev.sh test:e2e:headed
# Debug interattivo (clicca sui test nell'UI)
./dev.sh test:e2e:ui
# Filtrare test specifici
./dev.sh test:e2e:headed -- --grep "login"
./dev.sh test:e2e:headed -- --project=chromium
```
### Test E2E Inclusi
| Categoria | Test |
|-------------------------|----------------------------------------------|
| **Flusso Validatore** | Login, password, annulla |
| **Flusso Partecipante** | Badge ammesso/non ammesso/non trovato |
| **Conferma Ingresso** | Success modal, warning non ammesso |
| **Sicurezza** | Backend blocca non-ammesso → errore frontend |
| **Debug & Session** | Pagina debug, logout, persistenza sessione |
### Test Critico: Sicurezza Backend
Il test E2E `backend blocca non-ammesso → frontend mostra errore`:
1. Intercetta la chiamata API `/entry-request`
2. Forza risposta `success: false` (simula backend che blocca)
3. Verifica che il frontend **NON** mostri il carosello di benvenuto
4. Verifica che mostri un messaggio di errore
Questo garantisce che anche se il frontend ha bug, il backend fa da ultimo baluardo.
## 📚 Documentazione
Per dettagli tecnici, consulta la cartella `ai-prompts/`:
@@ -155,6 +284,7 @@ from fastapi.responses import FileResponse
app.mount("/assets", StaticFiles(directory="frontend/dist/assets"))
@app.get("/")
async def serve_frontend():
return FileResponse("frontend/dist/index.html")
@@ -162,7 +292,8 @@ async def serve_frontend():
### Variabili d'Ambiente
Il frontend non richiede variabili d'ambiente. Le API sono chiamate con path relativi (`/info-room`, etc.), quindi funziona automaticamente indipendentemente dal dominio o porta.
Il frontend non richiede variabili d'ambiente. Le API sono chiamate con path relativi (`/info-room`, etc.), quindi
funziona automaticamente indipendentemente dal dominio o porta.
### Requisiti Sistema Produzione