From e99472ab7d1d5ad83264592c5edc96fee3a0a48e Mon Sep 17 00:00:00 2001 From: Cillian Myles Date: Mon, 19 Aug 2024 08:58:38 +0100 Subject: [PATCH] chore: add failing tests to highlight issue where scroll offsets are out of sync on mobile --- .../super_textfield_gesture_scrolling_test.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/super_editor/test/super_textfield/super_textfield_gesture_scrolling_test.dart b/super_editor/test/super_textfield/super_textfield_gesture_scrolling_test.dart index b6fdd598a..9351772e9 100644 --- a/super_editor/test/super_textfield/super_textfield_gesture_scrolling_test.dart +++ b/super_editor/test/super_textfield/super_textfield_gesture_scrolling_test.dart @@ -272,6 +272,7 @@ void main() { var textTop = tester.getTopRight(find.byType(SuperTextField)).dy; var viewportTop = tester.getTopRight(find.byType(SuperText)).dy; expect(textTop, moreOrLessEquals(viewportTop)); + expect(SuperTextFieldInspector.findScrollOffset(), 0.0); // Scroll down to reveal the last line of text. await tester.drag(find.byType(SuperTextField), const Offset(0, -1000.0)); @@ -281,6 +282,10 @@ void main() { var textBottom = tester.getBottomRight(find.byType(SuperTextField)).dy; var viewportBottom = tester.getBottomRight(find.byType(SuperText)).dy; expect(textBottom, moreOrLessEquals(viewportBottom)); + // Since the scrollable content is taller than the viewport, and since + // the bottom of the text field is aligned with the bottom of the + // viewport, the scroll offset should be greater than 0. + expect(SuperTextFieldInspector.findScrollOffset(), greaterThan(0.0)); // Scroll back up to the top of the text field. await tester.drag(find.byType(SuperTextField), const Offset(0, 1000.0)); @@ -290,6 +295,7 @@ void main() { textTop = tester.getTopRight(find.byType(SuperTextField)).dy; viewportTop = tester.getTopRight(find.byType(SuperText)).dy; expect(textTop, moreOrLessEquals(viewportTop)); + expect(SuperTextFieldInspector.findScrollOffset(), 0.0); }); testWidgetsOnDesktop("multi-line is vertically scrollable when text spans more lines than maxLines", (tester) async { @@ -314,6 +320,7 @@ void main() { var textTop = tester.getTopRight(find.byType(SuperTextField)).dy; var viewportTop = tester.getTopRight(find.byType(SuperText)).dy; expect(textTop, moreOrLessEquals(viewportTop)); + expect(SuperTextFieldInspector.findScrollOffset(), 0.0); // Scroll down to reveal the last line of text. await tester.drag( @@ -327,6 +334,10 @@ void main() { var textBottom = tester.getBottomRight(find.byType(SuperTextField)).dy; var viewportBottom = tester.getBottomRight(find.byType(SuperText)).dy; expect(textBottom, moreOrLessEquals(viewportBottom)); + // Issue is not present on desktop, further leading me to think that the + // issue is somehow related to that comment about the scroll offsets + // being out of sync in the mobile scroll view. + expect(SuperTextFieldInspector.findScrollOffset(), greaterThan(0.0)); // Scroll back up to the top of the text field. await tester.drag( @@ -340,6 +351,7 @@ void main() { textTop = tester.getTopRight(find.byType(SuperTextField)).dy; viewportTop = tester.getTopRight(find.byType(SuperText)).dy; expect(textTop, moreOrLessEquals(viewportTop)); + expect(SuperTextFieldInspector.findScrollOffset(), 0.0); }); }); }