170 lines
5.9 KiB
Dart
170 lines
5.9 KiB
Dart
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: '[email protected]',
|
|
roleName: 'Doctor',
|
|
);
|
|
expect(doctorSession.isSecretary, isFalse);
|
|
expect(doctorSession.isDoctorOrAdmin, isTrue);
|
|
|
|
const secretarySession = AuthSessionModel(
|
|
accessToken: 'token_456',
|
|
userId: 'u2',
|
|
firstName: 'Ana',
|
|
lastName: 'Pérez',
|
|
email: '[email protected]',
|
|
roleName: 'Secretaria',
|
|
);
|
|
expect(secretarySession.isSecretary, isTrue);
|
|
expect(secretarySession.isDoctorOrAdmin, isFalse);
|
|
|
|
const receptionistSession = AuthSessionModel(
|
|
accessToken: 'token_789',
|
|
userId: 'u3',
|
|
firstName: 'Maria',
|
|
lastName: 'Gomez',
|
|
email: '[email protected]',
|
|
roleName: 'Recepcionista',
|
|
);
|
|
expect(receptionistSession.isSecretary, isTrue);
|
|
|
|
const assistantSession = AuthSessionModel(
|
|
accessToken: 'token_101',
|
|
userId: 'u4',
|
|
firstName: 'Carmen',
|
|
lastName: 'Díaz',
|
|
email: '[email protected]',
|
|
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 and clinical tabs MUST NOT exist
|
|
expect(find.byType(ClinicalDocumentsDropdown), findsNothing);
|
|
expect(find.byType(PatientClinicalTabs), 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 and clinical tabs
|
|
expect(find.byType(ClinicalDocumentsDropdown), findsOneWidget);
|
|
expect(find.byType(PatientClinicalTabs), findsOneWidget);
|
|
expect(find.byType(SecretaryAppointmentSection), findsNothing);
|
|
});
|
|
});
|
|
}
|