appflowy-editor/test/service/scroll_service_test.dart

82 lines
2.4 KiB
Dart
Raw Normal View History

import 'package:appflowy_editor/appflowy_editor.dart';
2022-10-28 15:25:04 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
2023-05-02 23:03:55 +08:00
import '../new/infra/testable_editor.dart';
2022-10-28 15:25:04 +02:00
void main() async {
setUpAll(() {
TestWidgetsFlutterBinding.ensureInitialized();
});
group('Testing Scroll With Gestures', () {
2023-05-02 23:03:55 +08:00
testWidgets('Test Gesture Scroll', (tester) async {
2022-10-28 15:25:04 +02:00
final editor = tester.editor;
for (var i = 0; i < 100; i++) {
2023-05-02 23:03:55 +08:00
editor.addParagraph(initialText: '$i');
2022-10-28 15:25:04 +02:00
}
2023-05-02 23:03:55 +08:00
editor.addParagraph(initialText: 'mark');
2022-10-28 15:25:04 +02:00
for (var i = 100; i < 200; i++) {
2023-05-02 23:03:55 +08:00
editor.addParagraph(initialText: '$i');
2022-10-28 15:25:04 +02:00
}
await editor.startTesting();
final listFinder = find.byType(Scrollable);
final itemFinder = find.text('mark', findRichText: true);
await tester.scrollUntilVisible(
itemFinder,
500.0,
scrollable: listFinder,
);
2022-10-28 15:25:04 +02:00
expect(itemFinder, findsOneWidget);
2023-05-02 23:03:55 +08:00
await editor.dispose();
2022-10-28 15:25:04 +02:00
});
testWidgets('remote document updates do not request local auto-scroll',
(tester) async {
final editor = tester.editor;
addTearDown(() async {
await tester.pumpWidget(const SizedBox.shrink());
editor.editorState.dispose();
});
for (var i = 0; i < 3; i++) {
editor.addParagraph(initialText: 'paragraph $i');
}
await editor.startTesting();
await editor.updateSelection(
Selection.collapsed(
Position(path: [0]),
),
);
final localSelection = editor.selection;
final autoScroller = editor.editorState.autoScroller;
expect(autoScroller, isNotNull);
if (autoScroller == null) {
return;
}
autoScroller.stopAutoScroll();
expect(autoScroller.lastOffset, isNull);
final remotelyEditedNode = editor.nodeAtPath([1]);
expect(remotelyEditedNode, isNotNull);
if (remotelyEditedNode == null) {
return;
}
final transaction = editor.editorState.transaction
..updateNode(
remotelyEditedNode,
{
ParagraphBlockKeys.delta:
(Delta()..insert('updated remotely')).toJson(),
},
);
await editor.editorState.apply(transaction, isRemote: true);
await tester.pump();
expect(editor.selection, localSelection);
expect(autoScroller.lastOffset, isNull);
});
2022-10-28 15:25:04 +02:00
});
}