Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir-P committed Apr 21, 2024
1 parent 5cd7e66 commit 0e60b16
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions packages/fleather/test/widgets/editor_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<EditorState>(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<FleatherSingleChildScrollView>(
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(
Expand Down

0 comments on commit 0e60b16

Please sign in to comment.