Files
hidalyx-drluiscastro/test/features/prescription_test.dart
T

190 lines
6.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hidalyx_drluiscastro/features/config/presentation/store/config_store.dart';
import 'package:hidalyx_drluiscastro/features/patient/presentation/widgets/clinical_documents_dropdown.dart';
import 'package:hidalyx_drluiscastro/features/prescription/presentation/views/prescription_modal_view.dart';
import 'package:hidalyx_drluiscastro/features/prescription/services/prescription_pdf_service.dart';
void main() {
group('ClinicalDocumentsDropdown Tests', () {
testWidgets('renders dropdown button with title and icon', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ClinicalDocumentsDropdown(
onSelect: (_) {},
),
),
),
);
expect(find.text('Documentos Clínicos'), findsOneWidget);
expect(find.byIcon(Icons.description_outlined), findsOneWidget);
});
testWidgets('opens menu and displays Receta Médica option', (tester) async {
ClinicalDocumentType? selected;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ClinicalDocumentsDropdown(
onSelect: (type) => selected = type,
),
),
),
);
await tester.tap(find.text('Documentos Clínicos'));
await tester.pumpAndSettle();
expect(find.text('Receta Médica'), findsOneWidget);
expect(find.text('Formato media carta institucional'), findsOneWidget);
expect(find.text('Autorización De Seguro'), findsOneWidget);
expect(find.text('Referir a Doctor(a)'), findsOneWidget);
expect(find.text('Referir a Departamento'), findsOneWidget);
await tester.tap(find.text('Receta Médica'));
await tester.pumpAndSettle();
expect(selected, equals(ClinicalDocumentType.recetaMedica));
});
});
group('PrescriptionModalView Tests', () {
testWidgets('renders patient name, doctor header and prescription fields', (tester) async {
final configStore = ConfigStore();
configStore.nombreDoctor = 'Dr. Luis A. Castro Sosa';
configStore.especialidad = 'Cirujano Urólogo';
configStore.descripEspecialidad = 'Enfermedades Vías Urinarias';
configStore.descripGeneral = 'Santiago, RD';
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: PrescriptionModalView(
patientName: 'JUAN PEREZ',
configStore: configStore,
),
),
),
);
await tester.pumpAndSettle();
expect(find.text('Emisión de Receta Médica'), findsOneWidget);
expect(find.text('Dr. Luis A. Castro Sosa'), findsOneWidget);
expect(find.text('CIRUJANO URÓLOGO'), findsOneWidget);
expect(find.text('ENFERMEDADES VÍAS URINARIAS'), findsOneWidget);
expect(find.text('JUAN PEREZ'), findsOneWidget);
expect(find.text('Crear / Imprimir Receta'), findsOneWidget);
expect(find.text('ESC para salir'), findsOneWidget);
});
testWidgets('inserts bullet when clicking viñeta button and jumps to new line if text has content', (tester) async {
final configStore = ConfigStore();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: PrescriptionModalView(
patientName: 'CARLOS ARIAS',
configStore: configStore,
),
),
),
);
await tester.pumpAndSettle();
final bulletBtn = find.text('Insertar viñeta (•)');
expect(bulletBtn, findsOneWidget);
await tester.tap(bulletBtn);
await tester.pump();
expect(find.text('• '), findsOneWidget);
// Now enter text at end of line and test auto-newline
final prescriptionField = find.byWidgetPredicate(
(w) => w is TextField && (w.decoration?.hintText?.contains('Ciprofloxacina') ?? false),
);
await tester.enterText(prescriptionField, '1. Ciprofloxacina 500mg');
await tester.pump();
await tester.tap(bulletBtn);
await tester.pump();
expect(find.text('1. Ciprofloxacina 500mg\n• '), findsOneWidget);
});
testWidgets('inserts sequential numbers and sub-indication dosis', (tester) async {
await tester.binding.setSurfaceSize(const Size(1024, 800));
addTearDown(() => tester.binding.setSurfaceSize(null));
final configStore = ConfigStore();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: PrescriptionModalView(
patientName: 'CARLOS ARIAS',
configStore: configStore,
),
),
),
);
await tester.pumpAndSettle();
final numberBtn = find.text('1. Número');
expect(numberBtn, findsOneWidget);
await tester.tap(numberBtn);
await tester.pump();
expect(find.text('1. '), findsOneWidget);
// Tap again to get next sequential number
await tester.tap(numberBtn);
await tester.pump();
expect(find.text('1. \n2. '), findsOneWidget);
// Insert dosage sub-indication
final subIndicationBtn = find.text('↳ Dosis');
expect(subIndicationBtn, findsOneWidget);
await tester.tap(subIndicationBtn);
await tester.pump();
expect(find.text('1. \n2. \n - '), findsOneWidget);
// Open posology panel
final posologyToggleBtn = find.text('⏱ Posologías rápidas ▼');
expect(posologyToggleBtn, findsOneWidget);
await tester.tap(posologyToggleBtn);
await tester.pump();
// Tap quick dosage chip
final chip = find.text('1 tableta');
expect(chip, findsOneWidget);
await tester.tap(chip);
await tester.pump();
expect(find.text('1. \n2. \n - 1 tableta'), findsOneWidget);
// Test clear button
final clearBtn = find.text('Limpiar lienzo');
expect(clearBtn, findsOneWidget);
await tester.tap(clearBtn);
await tester.pump();
expect(find.text('Limpiar lienzo'), findsNothing);
});
});
group('PrescriptionPdfService Tests', () {
test('builds prescription pdf bytes with correct page format and layout', () async {
final bytes = await PrescriptionPdfService.buildPrescriptionPdf(
doctorName: 'Dr. Luis A. Castro Sosa',
specialty: 'Cirujano Urólogo',
subspecialty: 'Enfermedades Vias Urinarias',
generalContact: 'Santiago, RD. Tel: 809-583-2394',
patientName: 'JUAN PEREZ',
prescriptionText: '1. Ciprofloxacina 500mg\nTomar 1 tableta cada 12 horas por 7 días.',
);
expect(bytes, isNotEmpty);
expect(bytes.sublist(0, 4), equals([0x25, 0x50, 0x44, 0x46]));
});
});
}