Showing
1 changed file
with
68 additions
and
14 deletions
| @@ -6,25 +6,79 @@ | @@ -6,25 +6,79 @@ | ||
| 6 | // tree, read text, and verify that the values of widget properties are correct. | 6 | // tree, read text, and verify that the values of widget properties are correct. |
| 7 | 7 | ||
| 8 | import 'package:flutter/material.dart'; | 8 | import 'package:flutter/material.dart'; |
| 9 | +import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
| 9 | import 'package:flutter_test/flutter_test.dart'; | 10 | import 'package:flutter_test/flutter_test.dart'; |
| 10 | 11 | ||
| 11 | -import 'package:example/src/first_method.dart'; | ||
| 12 | - | ||
| 13 | void main() { | 12 | void main() { |
| 14 | - testWidgets('Counter increments smoke test', (WidgetTester tester) async { | ||
| 15 | - // Build our app and trigger a frame. | ||
| 16 | - await tester.pumpWidget(MyApp()); | 13 | + testWidgets('Test Responsiveness', (WidgetTester tester) async { |
| 14 | + // Declare Sizes | ||
| 15 | + const Size designSize = Size(360, 640); | ||
| 16 | + const Size initialSize = designSize; | ||
| 17 | + const Size biggerSize = Size(480, 920); | ||
| 18 | + const Size smallerSize = Size(300, 560); | ||
| 19 | + | ||
| 20 | + // We'll use MediaQuery to simulate diffrent screen sizes | ||
| 21 | + MediaQueryData currentData = MediaQueryData(size: initialSize); | ||
| 22 | + const MediaQueryData biggerData = MediaQueryData(size: biggerSize); | ||
| 23 | + const MediaQueryData smallerData = MediaQueryData(size: smallerSize); | ||
| 24 | + | ||
| 25 | + // Used to find a widget. See [CommonFinders.byKey]. | ||
| 26 | + final _key = UniqueKey(); | ||
| 27 | + | ||
| 28 | + // Click on button. See code bellow. | ||
| 29 | + Future<int> tap() async { | ||
| 30 | + await tester.tap(find.byKey(_key)); | ||
| 31 | + return tester.pumpAndSettle(); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + void testSize(Size size) { | ||
| 35 | + expect(1.w, equals(size.width / designSize.width)); | ||
| 36 | + expect(1.h, equals(size.height / designSize.height)); | ||
| 37 | + print('[OK] Size: $size, width: ${1.w}, height: ${1.h}'); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + await tester.pumpWidget(StatefulBuilder( | ||
| 41 | + builder: (BuildContext context, StateSetter setState) { | ||
| 42 | + return MediaQuery( | ||
| 43 | + data: currentData, | ||
| 44 | + child: ScreenUtilInit( | ||
| 45 | + useInheritedMediaQuery: true, | ||
| 46 | + designSize: designSize, | ||
| 47 | + builder: (context, child) => MaterialApp( | ||
| 48 | + home: Material( | ||
| 49 | + child: TextButton( | ||
| 50 | + key: _key, | ||
| 51 | + child: Text('Change data'), | ||
| 52 | + onPressed: () { | ||
| 53 | + setState(() { | ||
| 54 | + currentData = currentData.size == initialSize | ||
| 55 | + // First test with bigger screen | ||
| 56 | + ? biggerData | ||
| 57 | + // Test with smaller screen | ||
| 58 | + : smallerData; | ||
| 59 | + }); | ||
| 60 | + }, | ||
| 61 | + ), | ||
| 62 | + ), | ||
| 63 | + ), | ||
| 64 | + ), | ||
| 65 | + ); | ||
| 66 | + }, | ||
| 67 | + )); | ||
| 68 | + | ||
| 69 | + // Tests with initial screen size | ||
| 70 | + testSize(initialSize); | ||
| 17 | 71 | ||
| 18 | - // Verify that our counter starts at 0. | ||
| 19 | - expect(find.text('0'), findsOneWidget); | ||
| 20 | - expect(find.text('1'), findsNothing); | 72 | + // Click On button to simulate changing screen size |
| 73 | + await tap(); | ||
| 74 | + // Tests with bigger screen size | ||
| 75 | + testSize(biggerSize); | ||
| 21 | 76 | ||
| 22 | - // Tap the '+' icon and trigger a frame. | ||
| 23 | - await tester.tap(find.byIcon(Icons.add)); | ||
| 24 | - await tester.pump(); | 77 | + // Click On button to simulate changing screen size |
| 78 | + await tap(); | ||
| 79 | + // Tests with bigger screen size | ||
| 80 | + testSize(smallerSize); | ||
| 25 | 81 | ||
| 26 | - // Verify that our counter has incremented. | ||
| 27 | - expect(find.text('0'), findsNothing); | ||
| 28 | - expect(find.text('1'), findsOneWidget); | 82 | + await tester.pumpAndSettle(); |
| 29 | }); | 83 | }); |
| 30 | } | 84 | } |
-
Please register or login to post a comment