From 907822f16806c27b05cf157a17cf294c70882a11 Mon Sep 17 00:00:00 2001 From: alfy Date: Sat, 24 Jan 2026 18:55:33 +0100 Subject: [PATCH] feat: aggiunti test per il componente UserCard nel sistema di voto Focolari --- frontend/src/components/UserCard.test.tsx | 69 +++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 frontend/src/components/UserCard.test.tsx diff --git a/frontend/src/components/UserCard.test.tsx b/frontend/src/components/UserCard.test.tsx new file mode 100644 index 0000000..57de0fe --- /dev/null +++ b/frontend/src/components/UserCard.test.tsx @@ -0,0 +1,69 @@ +/** + * Focolari Voting System - Test UserCard Component + */ +import { describe, it, expect } from 'vitest'; +import { render, screen } from '@testing-library/react'; +import { UserCard } from './UserCard'; +import type { User } from '../types'; +describe('UserCard Component', () => { + const userAmmesso: User = { + badge_code: '0008988288', + nome: 'Marco', + cognome: 'Bianchi', + url_foto: 'https://via.placeholder.com/150', + ruolo: 'Convocato', + ammesso: true, + }; + const userNonAmmesso: User = { + badge_code: '0000514162', + nome: 'Giuseppe', + cognome: 'Verdi', + url_foto: 'https://via.placeholder.com/150', + ruolo: 'Tecnico', + ammesso: false, + warning: 'Utente non ammesso al voto', + }; + it('should render user name correctly', () => { + render(); + expect(screen.getByText(/Marco/i)).toBeInTheDocument(); + expect(screen.getByText(/Bianchi/i)).toBeInTheDocument(); + }); + it('should render badge code', () => { + render(); + expect(screen.getByText(/0008988288/)).toBeInTheDocument(); + }); + it('should render role', () => { + render(); + // Il ruolo 'Convocato' non รจ nei colori predefiniti, usa default + expect(screen.getByText(/Convocato/i)).toBeInTheDocument(); + }); + it('should show AMMESSO status for ammesso user', () => { + render(); + expect(screen.getByText(/AMMESSO/i)).toBeInTheDocument(); + }); + it('should show NON AMMESSO status for non-ammesso user', () => { + render(); + // Ci sono due elementi con "NON AMMESSO", usiamo getAllByText + const elements = screen.getAllByText(/NON AMMESSO/i); + expect(elements.length).toBeGreaterThan(0); + }); + it('should show warning message when user has warning', () => { + render(); + expect(screen.getByText(/Utente non ammesso al voto/i)).toBeInTheDocument(); + }); + it('should render user photo with correct alt text', () => { + render(); + const img = screen.getByRole('img'); + expect(img).toHaveAttribute('alt', 'Marco Bianchi'); + }); + it('should apply success border for ammesso user', () => { + const { container } = render(); + // Verifica classe border-success + expect(container.querySelector('.border-success')).toBeInTheDocument(); + }); + it('should apply error border for non-ammesso user', () => { + const { container } = render(); + // Verifica classe border-error + expect(container.querySelector('.border-error')).toBeInTheDocument(); + }); +});