Reestructuracion de la app

This commit is contained in:
2026-06-29 20:32:47 +02:00
parent 710be805ee
commit 82515960f6
6 changed files with 1040 additions and 1868 deletions
+36 -23
View File
@@ -8,11 +8,19 @@ 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', (
testWidgets('autosaves a note when only the category changes', (
WidgetTester tester,
) async {
Note? savedNote;
final Note initialNote = Note(
title: 'Sin título',
body: '',
createdAt: DateTime(2026, 5, 21),
updatedAt: DateTime(2026, 5, 21),
position: 0,
);
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
@@ -23,8 +31,8 @@ void main() {
],
home: Scaffold(
body: NoteEditorScreen(
note: null,
categoryId: null,
repository: null,
note: initialNote,
categories: <Category>[
Category(
id: 'work',
@@ -32,8 +40,9 @@ void main() {
updatedAt: DateTime(2026, 5, 21),
),
],
onComplete: (dynamic result) {
savedNote = result as Note?;
saveNote: (Note note) async => note,
onSaved: (Note result) {
savedNote = result;
},
),
),
@@ -46,20 +55,26 @@ void main() {
await tester.pumpAndSettle();
await tester.tap(find.text('Trabajo').last);
await tester.pumpAndSettle();
await tester.tap(find.text('Guardar'));
await tester.pumpAndSettle();
await tester.pump();
await tester.pump(const Duration(seconds: 2));
expect(savedNote, isNotNull);
expect(savedNote!.categoryId, 'work');
expect(savedNote!.title, 'Sin título');
});
testWidgets('only completes once when save is tapped twice', (
testWidgets('debounces multiple edits into a single save', (
WidgetTester tester,
) async {
int completionCount = 0;
int saveCount = 0;
final Note initialNote = Note(
title: 'Sin título',
body: '',
createdAt: DateTime(2026, 5, 21),
updatedAt: DateTime(2026, 5, 21),
position: 0,
);
await tester.pumpWidget(
MaterialApp(
@@ -71,25 +86,23 @@ void main() {
],
home: Scaffold(
body: NoteEditorScreen(
note: null,
categoryId: null,
repository: null,
note: initialNote,
categories: <Category>[],
onComplete: (dynamic result) {
if (result is Note) {
completionCount += 1;
}
saveNote: (Note note) async {
saveCount += 1;
return note;
},
),
),
),
);
await tester.enterText(find.byType(TextField).first, 'Nota de prueba');
await tester.enterText(find.byType(TextField).first, 'Primera versión');
await tester.pump(const Duration(milliseconds: 300));
await tester.enterText(find.byType(TextField).first, 'Segunda versión');
await tester.pump(const Duration(seconds: 2));
await tester.tap(find.text('Guardar'));
await tester.tap(find.text('Guardar'));
await tester.pumpAndSettle();
expect(completionCount, 1);
expect(saveCount, 1);
});
}