Files
flux/test/features/notes/ui/note_form_screen_test.dart
T
brontomark 5fcc16fb9c
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 2m20s
Build and Release FLUX (Multi-Platform) / build-linux (push) Successful in 1m35s
Build and Release FLUX (Multi-Platform) / build-windows (push) Successful in 9m41s
Build and Release FLUX (Multi-Platform) / build-macos (push) Failing after 10m33s
refactor: improve responsive layout across dashboard cards and add unit tests
2026-11-29 13:56:44 +01:00

111 lines
3.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flux/features/notes/blocs/notes_cubit.dart';
import 'package:flux/features/notes/models/note_model.dart';
import 'package:flux/features/notes/ui/notes_form_screen.dart';
class _FakeNotesCubit extends Cubit<NotesState> implements NotesCubit {
final List<NoteModel> savedNotes = [];
final List<String> deletedNoteIds = [];
_FakeNotesCubit() : super(NotesState());
@override
String? get companyId => 'comp-1';
@override
String? get staffId => 'staff-1';
@override
void startListening() {}
@override
void stopListening() {}
@override
Future<void> saveNote(NoteModel note) async {
savedNotes.add(note);
}
@override
Future<void> deleteNote(String noteId) async {
deletedNoteIds.add(noteId);
}
}
void main() {
group('NoteFormScreen outside click behavior', () {
testWidgets(
'clicking inside Post-it keeps note open, clicking outside saves and closes',
(tester) async {
tester.view.physicalSize = const Size(1200, 900);
tester.view.devicePixelRatio = 1.0;
addTearDown(() {
tester.view.resetPhysicalSize();
tester.view.resetDevicePixelRatio();
});
final fakeCubit = _FakeNotesCubit();
final note = NoteModel(
id: 'note-1',
createdBy: 'staff-1',
companyId: 'comp-1',
title: 'Titolo iniziale',
content: 'Contenuto',
collaboratorIds: const [],
);
await tester.pumpWidget(
BlocProvider<NotesCubit>.value(
value: fakeCubit,
child: MaterialApp(
home: Builder(
builder: (context) => Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => NoteFormScreen(note: note),
),
);
},
child: const Text('Apri Nota'),
),
),
),
),
),
),
);
await tester.tap(find.text('Apri Nota'));
await tester.pumpAndSettle();
expect(find.byType(NoteFormScreen), findsOneWidget);
// 1. Tap dentro il Post-it: la nota resta aperta
await tester.tap(find.text('Condividi con tutti'));
await tester.pumpAndSettle();
expect(find.byType(NoteFormScreen), findsOneWidget);
// 2. Digitiamo nel titolo e clicchiamo subito fuori (senza aspettare i 500ms del debouncer)
await tester.enterText(
find.widgetWithText(TextFormField, 'Titolo iniziale'),
'Titolo aggiornato',
);
// Tap a sinistra fuori dal Post-it centrato (maxWidth 680 su schermo 1200 -> x=50 è fuori)
await tester.tapAt(const Offset(50, 450));
await tester.pumpAndSettle();
// La nota si è chiusa e ha salvato immediatamente le modifiche pendenti
expect(find.byType(NoteFormScreen), findsNothing);
expect(fakeCubit.savedNotes.last.title, 'Titolo aggiornato');
expect(fakeCubit.deletedNoteIds, isEmpty);
},
);
});
}