diff --git a/packages/fleather/test/widgets/editor_test.dart b/packages/fleather/test/widgets/editor_test.dart index b89ebb59..37d52529 100644 --- a/packages/fleather/test/widgets/editor_test.dart +++ b/packages/fleather/test/widgets/editor_test.dart @@ -1,6 +1,7 @@ import 'package:fleather/fleather.dart'; import 'package:fleather/src/services/spell_check_suggestions_toolbar.dart'; import 'package:fleather/src/widgets/keyboard_listener.dart'; +import 'package:fleather/src/widgets/single_child_scroll_view.dart'; import 'package:fleather/src/widgets/text_selection.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; @@ -17,6 +18,94 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); group('$RawEditor', () { + testWidgets('Scrolls to reveal the cursor when keyboard pops up', + (tester) async { + final delta = Delta(); + for (int i = 0; i < 20; i++) { + delta.insert('Test\n'); + } + final controller = + FleatherController(document: ParchmentDocument.fromDelta(delta)); + final editor = MaterialApp( + home: Scaffold( + body: Column( + children: [ + Expanded(child: FleatherEditor(controller: controller)), + ], + ), + ), + ); + await tester.pumpWidget(editor); + await tester.tapAt( + tester.getBottomRight(find.byType(RawEditor)) - const Offset(1, 1)); + await tester.pumpAndSettle(); + final renderEditor = + tester.state(find.byType(RawEditor)).renderEditor; + final endpoint = + renderEditor.getEndpointsForSelection(renderEditor.selection); + expect( + tester + .getRect(find.byType(FleatherEditor)) + .contains(renderEditor.localToGlobal(endpoint[0].point)), + isTrue); + tester.view.viewInsets = const FakeViewPadding(bottom: 200); + await tester.pump(); + expect( + tester + .getRect(find.byType(FleatherEditor)) + .contains(renderEditor.localToGlobal(endpoint[0].point)), + isTrue); + tester.view.viewInsets = FakeViewPadding.zero; + }); + + testWidgets( + 'Scrolls to reveal the bottom end of cursor when keyboard pops up and cursor is bigger than screen', + (tester) async { + final delta = Delta() + ..insert('Test\n') + ..insert(EmbeddableObject('image', inline: false)) + ..insert('\n'); + final controller = + FleatherController(document: ParchmentDocument.fromDelta(delta)); + final editor = MaterialApp( + home: Scaffold( + body: Column( + children: [ + Expanded( + child: FleatherEditor( + controller: controller, + embedBuilder: (context, node) => SizedBox( + width: 100, + height: + (tester.view.physicalSize / tester.view.devicePixelRatio) + .height * + 1.5, + ), + )), + ], + ), + ), + ); + await tester.pumpWidget(editor); + await tester.tapAt( + tester.getBottomRight(find.byType(RawEditor)) - const Offset(1, 1)); + await tester.pumpAndSettle(); + + final scrollController = tester + .widget( + find.byType(FleatherSingleChildScrollView)) + .controller; + double scrollOffset = scrollController.offset; + tester.view.viewInsets = const FakeViewPadding(bottom: 20); + await tester.pump(); + expect(scrollController.offset > scrollOffset, isTrue); + scrollOffset = scrollController.offset; + tester.view.viewInsets = const FakeViewPadding(bottom: 40); + await tester.pump(); + expect(scrollController.offset > scrollOffset, isTrue); + tester.view.viewInsets = FakeViewPadding.zero; + }); + testWidgets('allows merging attribute theme data', (tester) async { var delta = Delta() ..insert(