Skip to content

Commit

Permalink
Fix horizontal graph theme (#464)
Browse files Browse the repository at this point in the history
* add missing scaffold

* test for scaffold existence
  • Loading branch information
derdilla authored Nov 3, 2024
1 parent 637ca46 commit d43c71a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 12 additions & 2 deletions app/test/screens/home_screen_test.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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';
import 'package:blood_pressure_app/features/measurement_list/measurement_list.dart';
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';
Expand Down Expand Up @@ -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);
});
}
68 changes: 68 additions & 0 deletions app/test/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,74 @@ Future<Widget> 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.
///
Expand Down

0 comments on commit d43c71a

Please sign in to comment.