From d43c71a68d3cd0bb0befa824818c49600f889bc6 Mon Sep 17 00:00:00 2001 From: derdilla <82763757+derdilla@users.noreply.github.com> Date: Sun, 3 Nov 2024 21:10:56 +0100 Subject: [PATCH] Fix horizontal graph theme (#464) * add missing scaffold * test for scaffold existence --- app/lib/screens/home_screen.dart | 2 +- app/test/screens/home_screen_test.dart | 14 +++++- app/test/util.dart | 68 ++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 3 deletions(-) diff --git a/app/lib/screens/home_screen.dart b/app/lib/screens/home_screen.dart index c264d2cf..caacb5f2 100644 --- a/app/lib/screens/home_screen.dart +++ b/app/lib/screens/home_screen.dart @@ -66,7 +66,7 @@ class AppHome extends StatelessWidget { _appStart++; } - if (orientation == Orientation.landscape) return _buildValueGraph(context); + if (orientation == Orientation.landscape) return Scaffold(body: _buildValueGraph(context)); return DefaultTabController( length: 2, child: Scaffold( diff --git a/app/test/screens/home_screen_test.dart b/app/test/screens/home_screen_test.dart index 06fa498f..68eed766 100644 --- a/app/test/screens/home_screen_test.dart +++ b/app/test/screens/home_screen_test.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:blood_pressure_app/data_util/interval_picker.dart'; import 'package:blood_pressure_app/features/home/navigation_action_buttons.dart'; import 'package:blood_pressure_app/features/measurement_list/compact_measurement_list.dart'; @@ -7,6 +5,7 @@ import 'package:blood_pressure_app/features/measurement_list/measurement_list.da import 'package:blood_pressure_app/features/statistics/value_graph.dart'; import 'package:blood_pressure_app/model/storage/settings_store.dart'; import 'package:blood_pressure_app/screens/home_screen.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import '../model/analyzer_test.dart'; @@ -67,4 +66,15 @@ void main() { expect(find.byType(MeasurementList), findsNothing); expect(find.byType(CompactMeasurementList), findsOneWidget); }); + + testWidgets('landscape graph is wrapped in theming', (tester) async { + await binding.setSurfaceSize(const Size(800, 400)); + + await tester.pumpWidget(appBaseForScreen(const AppHome())); + await tester.pumpAndSettle(); + + expect(find.byType(BloodPressureValueGraph), findsOneWidget); + expect(find.ancestor(of: find.byType(BloodPressureValueGraph), matching: find.byType(Scaffold)), findsOneWidget); + expect(find.ancestor(of: find.byType(BloodPressureValueGraph), matching: find.byType(MaterialApp)), findsOneWidget); + }); } diff --git a/app/test/util.dart b/app/test/util.dart index 5e271f4c..fe35736c 100644 --- a/app/test/util.dart +++ b/app/test/util.dart @@ -128,6 +128,74 @@ Future appBaseWithData(Widget child, { ); } +/// [materialApp] variant that doesn't assume scaffold. +Widget materialForScreens(Widget child, { + Settings? settings, + ExportSettings? exportSettings, + CsvExportSettings? csvExportSettings, + PdfExportSettings? pdfExportSettings, + IntervalStoreManager? intervallStoreManager, +}) { + settings ??= Settings(); + exportSettings ??= ExportSettings(); + csvExportSettings ??= CsvExportSettings(); + pdfExportSettings ??= PdfExportSettings(); + intervallStoreManager ??= IntervalStoreManager(IntervalStorage(), IntervalStorage(), IntervalStorage()); + return MultiProvider( + providers: [ + ChangeNotifierProvider.value(value: settings), + ChangeNotifierProvider.value(value: exportSettings), + ChangeNotifierProvider.value(value: csvExportSettings), + ChangeNotifierProvider.value(value: pdfExportSettings), + ChangeNotifierProvider.value(value: intervallStoreManager), + ], + child: MaterialApp( + localizationsDelegates: AppLocalizations.localizationsDelegates, + locale: const Locale('en'), + home: child, + ), + ); +} + +Widget appBaseForScreen(Widget child, { + Settings? settings, + ExportSettings? exportSettings, + CsvExportSettings? csvExportSettings, + PdfExportSettings? pdfExportSettings, + IntervalStoreManager? intervallStoreManager, + BloodPressureRepository? bpRepo, + MedicineRepository? medRepo, + NoteRepository? noteRepo, + MedicineIntakeRepository? intakeRepo, + BodyweightRepository? weightRepo, +}) { + HealthDataStore? db; + if (bpRepo == null + || medRepo == null + || intakeRepo == null + || noteRepo == null + || weightRepo == null + ) { + db = MockHealthDataSore(); + } + + return MultiRepositoryProvider( + providers: [ + RepositoryProvider(create: (context) => bpRepo ?? db!.bpRepo), + RepositoryProvider(create: (context) => medRepo ?? db!.medRepo), + RepositoryProvider(create: (context) => intakeRepo ?? db!.intakeRepo), + RepositoryProvider(create: (context) => noteRepo ?? db!.noteRepo), + RepositoryProvider(create: (context) => weightRepo ?? db!.weightRepo), + ], + child: materialForScreens(child, + settings: settings, + exportSettings: exportSettings, + csvExportSettings: csvExportSettings, + pdfExportSettings: pdfExportSettings, + intervallStoreManager: intervallStoreManager, + ), + ); +} /// Open a dialoge through a button press. ///