feat: Introduce category selection functionality in NoteEditorScreen and related components

This commit is contained in:
2026-05-21 19:31:29 +02:00
parent 7e210871dd
commit 8be7819528
7 changed files with 421 additions and 58 deletions
+81
View File
@@ -0,0 +1,81 @@
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>[
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<String>('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: <Category>[],
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);
});
}
+21
View File
@@ -0,0 +1,21 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:notas/models/note.dart';
void main() {
test('copyWith can clear categoryId explicitly', () {
final Note note = Note(
title: 'A',
body: 'B',
createdAt: DateTime(2026, 5, 21),
updatedAt: DateTime(2026, 5, 21),
position: 0,
categoryId: 'cat-1',
);
final Note cleared = note.copyWith(categoryId: null);
expect(cleared.categoryId, isNull);
expect(cleared.id, note.id);
});
}