import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:notas/models/category.dart'; import 'package:notas/models/note.dart'; import 'package:notas/screens/note_editor_screen.dart'; void main() { testWidgets('saves a note when only the category changes', ( WidgetTester tester, ) async { Note? savedNote; await tester.pumpWidget( MaterialApp( home: Scaffold( body: NoteEditorScreen( note: null, categoryId: null, categories: [ Category( id: 'work', name: 'Trabajo', updatedAt: DateTime(2026, 5, 21), ), ], onComplete: (dynamic result) { savedNote = result as Note?; }, ), ), ), ); expect(find.text('Sin categoría'), findsWidgets); await tester.tap(find.byKey(const ValueKey('category_selector'))); await tester.pumpAndSettle(); await tester.tap(find.text('Trabajo').last); await tester.pumpAndSettle(); await tester.tap(find.text('Guardar')); await tester.pumpAndSettle(); expect(savedNote, isNotNull); expect(savedNote!.categoryId, 'work'); expect(savedNote!.title, 'Sin título'); }); testWidgets('only completes once when save is tapped twice', ( WidgetTester tester, ) async { int completionCount = 0; await tester.pumpWidget( MaterialApp( home: Scaffold( body: NoteEditorScreen( note: null, categoryId: null, categories: [], onComplete: (dynamic result) { if (result is Note) { completionCount += 1; } }, ), ), ), ); await tester.enterText(find.byType(TextField).first, 'Nota de prueba'); await tester.tap(find.text('Guardar')); await tester.tap(find.text('Guardar')); await tester.pumpAndSettle(); expect(completionCount, 1); }); }