diff --git a/test/widget_test.dart b/test/widget_test.dart index e16a147..de2093f 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -1,30 +1,96 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility that Flutter provides. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:responsive_safe_area_tutorial/main.dart'; +import 'package:test_utils/test_utils.dart'; + +import 'package:responsive_safe_area/responsive_safe_area.dart'; void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(MyApp()); + MaterialApp materialAppWrapper(Widget widget) => + MaterialApp(home: Material(child: widget)); + + group('Testing widgets for recognition of the status bar', () { + const double screenWidth = 600, screenHeight = 800; + const Size screenSize = Size(screenWidth, screenHeight); + + final TestWidgetsFlutterBinding binding = + TestWidgetsFlutterBinding.ensureInitialized(); + + void setBinding(){ + binding.window.devicePixelRatioTestValue = 1; + binding.window.physicalSizeTestValue = screenSize; + } + + testWidgets( + 'Checks that the `LayoutBuilder` does *not* recognize the presence of ' + 'the Status Bar', (WidgetTester tester) async { + setBinding(); + + double extractedHeight; + + final MaterialApp layoutBuilderApp = materialAppWrapper( + SampleScreenWithArtificialStatusBar( + widget: LayoutBuilder( + builder: (_, BoxConstraints constraints) { + extractedHeight = constraints.biggest.height; + return Container(); + }, + ), + ), + ); + + await tester.pumpWidget(layoutBuilderApp); + + expect(extractedHeight, screenHeight); + }); - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); + testWidgets( + 'Checks that the `ResponsiveSafeArea` *does* recognize the presence of ' + 'the Status Bar', (WidgetTester tester) async { + setBinding(); - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); + double extractedHeight; - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); + final MaterialApp responsiveSafeAreaApp = materialAppWrapper( + SampleScreenWithArtificialStatusBar( + widget: ResponsiveSafeArea( + builder: (_, Size constraints) { + extractedHeight = constraints.height; + return Container(); + }, + ), + ), + ); + + await tester.pumpWidget(responsiveSafeAreaApp); + + const double safeHeight = + screenHeight - SampleScreenWithArtificialStatusBar.statusBarHeight; + + expect(extractedHeight, safeHeight); + }); }); } + +class SampleScreenWithArtificialStatusBar extends StatelessWidget { + static const double statusBarHeight = 10; + + final Widget widget; + + const SampleScreenWithArtificialStatusBar({ + Key key, + @required this.widget, + }): super(key: key); + + @override + Widget build(BuildContext context) { + return MediaQuery( + data: MediaQuery.of(context).copyWith( + padding: EdgeInsets.only( + top: statusBarHeight, + ), + ), + child: widget, + ); + } +}