import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:hidalyx_drluiscastro/features/auth/data/models/auth_session_model.dart'; import 'package:hidalyx_drluiscastro/features/dashboard/presentation/widgets/dashboard_app_bar.dart'; import 'package:hidalyx_drluiscastro/features/patient/data/models/patient_model.dart'; import 'package:hidalyx_drluiscastro/features/patient/presentation/views/patient_modal_view.dart'; import 'package:hidalyx_drluiscastro/features/patient/presentation/widgets/clinical_documents_dropdown.dart'; import 'package:hidalyx_drluiscastro/features/patient/presentation/widgets/patient_clinical_tabs.dart'; import 'package:hidalyx_drluiscastro/features/patient/presentation/widgets/secretary_appointment_section.dart'; void main() { group('AuthSessionModel Role Detection Tests', () { test('correctly identifies Doctor vs Secretary roles', () { const doctorSession = AuthSessionModel( accessToken: 'token_123', userId: 'u1', firstName: 'Luis A.', lastName: 'Castro Sosa', email: 'castro@hidalyx.com', roleName: 'Doctor', ); expect(doctorSession.isSecretary, isFalse); expect(doctorSession.isDoctorOrAdmin, isTrue); const secretarySession = AuthSessionModel( accessToken: 'token_456', userId: 'u2', firstName: 'Ana', lastName: 'Pérez', email: 'secretaria@hidalyx.com', roleName: 'Secretaria', ); expect(secretarySession.isSecretary, isTrue); expect(secretarySession.isDoctorOrAdmin, isFalse); const receptionistSession = AuthSessionModel( accessToken: 'token_789', userId: 'u3', firstName: 'Maria', lastName: 'Gomez', email: 'recepcion@hidalyx.com', roleName: 'Recepcionista', ); expect(receptionistSession.isSecretary, isTrue); const assistantSession = AuthSessionModel( accessToken: 'token_101', userId: 'u4', firstName: 'Carmen', lastName: 'Díaz', email: 'asistente@hidalyx.com', roleName: 'Asistente Médico', ); expect(assistantSession.isSecretary, isTrue); }); }); group('DashboardAppBar Role-based Tests', () { testWidgets('renders RECEPCIÓN badge and hides Configuración for secretary', (tester) async { await tester.pumpWidget( const MaterialApp( home: Scaffold( appBar: DashboardAppBar( doctorName: 'Ana Pérez', specialty: 'Recepción y Consultas', isSecretary: true, ), ), ), ); await tester.pumpAndSettle(); expect(find.text('RECEPCIÓN'), findsOneWidget); expect(find.text('Ana Pérez'), findsOneWidget); // Direct quick action buttons are immediately visible without opening a menu expect(find.text('Nuevo Paciente'), findsOneWidget); expect(find.text('Buscar Paciente'), findsOneWidget); expect(find.byIcon(Icons.settings_outlined), findsNothing); }); testWidgets('shows Configuración in QuickActions for Doctor', (tester) async { await tester.pumpWidget( const MaterialApp( home: Scaffold( appBar: DashboardAppBar( doctorName: 'Dr. Luis A. Castro Sosa', specialty: 'Cirujano Urólogo', isSecretary: false, ), ), ), ); await tester.pumpAndSettle(); expect(find.text('RECEPCIÓN'), findsNothing); // Direct quick action buttons are immediately visible expect(find.text('Nuevo Paciente'), findsOneWidget); expect(find.text('Buscar Paciente'), findsOneWidget); expect(find.byIcon(Icons.settings_outlined), findsOneWidget); }); }); group('PatientModalView Role-based Streamlined View Tests', () { testWidgets('renders streamlined reception view for secretary', (tester) async { final patient = PatientModel( id: 101, nombre: 'JUAN', apellido: 'MARTINEZ', fecProxcita: '25/09/2026', ); await tester.pumpWidget( MaterialApp( home: Scaffold( body: PatientModalView( initialPatient: patient, isSecretary: true, ), ), ), ); await tester.pumpAndSettle(); // Verify title reflects reception expect(find.text('Ficha de Recepción'), findsOneWidget); expect(find.text('Recepción, datos personales y programación de citas'), findsOneWidget); // Confidential clinical documents, clinical tabs and delete button MUST NOT exist expect(find.byType(ClinicalDocumentsDropdown), findsNothing); expect(find.byType(PatientClinicalTabs), findsNothing); expect(find.text('Eliminar'), findsNothing); // Secretary appointment section MUST exist expect(find.byType(SecretaryAppointmentSection), findsOneWidget); expect(find.text('Gestión de Citas y Turno del Paciente'), findsOneWidget); expect(find.text('Próxima Cita Programada: 25/09/2026'), findsOneWidget); expect(find.text('Elegir en Calendario'), findsOneWidget); }); testWidgets('renders full clinical tabs and documents dropdown for Doctor', (tester) async { final patient = PatientModel( id: 102, nombre: 'PEDRO', apellido: 'RAMIREZ', ); await tester.pumpWidget( MaterialApp( home: Scaffold( body: PatientModalView( initialPatient: patient, isSecretary: false, ), ), ), ); await tester.pumpAndSettle(); // Verify title reflects doctor editing expect(find.text('Editar Paciente'), findsOneWidget); // Doctor gets clinical documents dropdown, clinical tabs and delete button expect(find.byType(ClinicalDocumentsDropdown), findsOneWidget); expect(find.byType(PatientClinicalTabs), findsOneWidget); expect(find.text('Eliminar'), findsOneWidget); expect(find.byType(SecretaryAppointmentSection), findsNothing); }); }); }