|
| 1 | +import 'dart:ui'; |
| 2 | + |
| 3 | +import 'package:flutter_test/flutter_test.dart'; |
| 4 | +import 'package:flutter_test_runners/flutter_test_runners.dart'; |
| 5 | +import 'package:super_editor/super_editor_test.dart'; |
| 6 | + |
| 7 | +import 'reader_test_tools.dart'; |
| 8 | + |
| 9 | +void main() { |
| 10 | + group('SuperReader > phone rotation >', () { |
| 11 | + const screenSizePortrait = Size(400.0, 1000.0); |
| 12 | + const screenSizeLandscape = Size(1000.0, 400); |
| 13 | + |
| 14 | + testWidgetsOnMobile('does not crash the app when there is no selection', (tester) async { |
| 15 | + // Start the test in portrait mode. |
| 16 | + tester.view |
| 17 | + ..devicePixelRatio = 1.0 |
| 18 | + ..platformDispatcher.textScaleFactorTestValue = 1.0 |
| 19 | + ..physicalSize = screenSizePortrait; |
| 20 | + |
| 21 | + addTearDown(() => tester.platformDispatcher.clearAllTestValues()); |
| 22 | + |
| 23 | + await tester // |
| 24 | + .createDocument() |
| 25 | + .withSingleParagraph() |
| 26 | + .pump(); |
| 27 | + |
| 28 | + // Simulate a phone rotation. |
| 29 | + tester.view.physicalSize = screenSizeLandscape; |
| 30 | + await tester.pumpAndSettle(); |
| 31 | + |
| 32 | + // Reaching this point means the reader didn't crash. |
| 33 | + }); |
| 34 | + |
| 35 | + testWidgetsOnMobile('does not crash the app when the selection is collapsed', (tester) async { |
| 36 | + // Start the test in portrait mode. |
| 37 | + tester.view |
| 38 | + ..devicePixelRatio = 1.0 |
| 39 | + ..platformDispatcher.textScaleFactorTestValue = 1.0 |
| 40 | + ..physicalSize = screenSizePortrait; |
| 41 | + addTearDown(() => tester.platformDispatcher.clearAllTestValues()); |
| 42 | + |
| 43 | + await tester // |
| 44 | + .createDocument() |
| 45 | + .withSingleParagraph() |
| 46 | + .pump(); |
| 47 | + |
| 48 | + // Place the caret at the beginning of the document. |
| 49 | + await tester.placeCaretInParagraph('1', 0); |
| 50 | + |
| 51 | + // Simulate a phone rotation. |
| 52 | + tester.view.physicalSize = screenSizeLandscape; |
| 53 | + await tester.pumpAndSettle(); |
| 54 | + |
| 55 | + // Reaching this point means the reader didn't crash. |
| 56 | + }); |
| 57 | + |
| 58 | + testWidgetsOnMobile('does not crash the app when the selection is expanded', (tester) async { |
| 59 | + // Start the test in portrait mode. |
| 60 | + tester.view |
| 61 | + ..devicePixelRatio = 1.0 |
| 62 | + ..platformDispatcher.textScaleFactorTestValue = 1.0 |
| 63 | + ..physicalSize = screenSizePortrait; |
| 64 | + addTearDown(() => tester.platformDispatcher.clearAllTestValues()); |
| 65 | + |
| 66 | + await tester // |
| 67 | + .createDocument() |
| 68 | + .withSingleParagraph() |
| 69 | + .pump(); |
| 70 | + |
| 71 | + // Double tap to select the first word. |
| 72 | + await tester.doubleTapInParagraph('1', 0); |
| 73 | + |
| 74 | + // Simulate a phone rotation. |
| 75 | + tester.view.physicalSize = screenSizeLandscape; |
| 76 | + await tester.pumpAndSettle(); |
| 77 | + |
| 78 | + // Reaching this point means the reader didn't crash. |
| 79 | + }); |
| 80 | + }); |
| 81 | +} |
0 commit comments