test: widget test per il layer di presentazione
Prima era esercitato solo dall'integration test su emulatore: - converter_page: ricerca, stati vuoti, selezione, calcolo, swap, reset - shopping_list_page: aggiunta, contatore, sezione completati, dialog svuota - meal_planner_page: 7 card, giorno espanso, genera lista, dialog svuota, stato del pulsante Condividi - qr_share_sheet: QR per piano valido, errore oltre il limite, chiusura - app (BitePlanApp): navigazione fra i tab, bottom sheet informazioni - guide_page e info_bottom_sheet: contenuti e navigazione alla guida - empty_state: icona, titolo, sottotitolo opzionale - coverage_helper: importa tutta lib/ così lcov include anche i file non toccati da alcun test Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:biteplan/features/guide/presentation/pages/guide_page.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
|
||||
void main() {
|
||||
group('GuidePage', () {
|
||||
testWidgets('mostra titolo e le tre tab', (tester) async {
|
||||
await tester.pumpApp(const GuidePage());
|
||||
expect(find.text('Guida'), findsOneWidget);
|
||||
expect(find.text('Pasti'), findsOneWidget);
|
||||
expect(find.text('Converti'), findsOneWidget);
|
||||
expect(find.text('Spesa'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('la tab iniziale è Pasti', (tester) async {
|
||||
await tester.pumpApp(const GuidePage());
|
||||
expect(find.text('Aggiungere un alimento'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('la tab Converti mostra i suoi contenuti', (tester) async {
|
||||
await tester.pumpApp(const GuidePage());
|
||||
await tester.tap(find.text('Converti'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Come usarlo'), findsOneWidget);
|
||||
expect(find.text('Alimenti disponibili'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('la tab Spesa mostra i suoi contenuti', (tester) async {
|
||||
await tester.pumpApp(const GuidePage());
|
||||
await tester.tap(find.text('Spesa'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Aggiungere un elemento'), findsOneWidget);
|
||||
expect(find.text('Spuntare un elemento'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:biteplan/core/constants/app_constants.dart';
|
||||
import 'package:biteplan/features/guide/presentation/widgets/info_bottom_sheet.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
|
||||
Future<void> _openSheet(WidgetTester tester) async {
|
||||
await tester.pumpApp(Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => Center(
|
||||
child: FilledButton(
|
||||
onPressed: () => showInfoBottomSheet(context),
|
||||
child: const Text('apri'),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
await tester.tap(find.text('apri'));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('InfoBottomSheet', () {
|
||||
testWidgets('mostra nome app, versione, autore e licenza',
|
||||
(tester) async {
|
||||
await _openSheet(tester);
|
||||
expect(find.text('BitePlan'), findsOneWidget);
|
||||
expect(find.text('Versione $kAppVersion'), findsOneWidget);
|
||||
expect(find.text('Autore'), findsOneWidget);
|
||||
expect(find.text('Licenza'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('"Apri" sulla riga Guida naviga alla GuidePage',
|
||||
(tester) async {
|
||||
await _openSheet(tester);
|
||||
await tester.tap(find.text('Apri'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Aggiungere un alimento'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user