test: migrate page up and down
This commit is contained in:
parent
0f4c5241b7
commit
fd1a1b1551
4 changed files with 18 additions and 22 deletions
|
|
@ -158,6 +158,10 @@ class SimpleEditor extends StatelessWidget {
|
|||
outdentCommand,
|
||||
|
||||
exitEditingCommand,
|
||||
|
||||
//
|
||||
pageUpCommand,
|
||||
pageDownCommand,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ CommandShortcutEventHandler _pageUpCommandHandler = (editorState) {
|
|||
|
||||
final scrollHeight = scrollService.onePageHeight;
|
||||
final dy = scrollService.dy;
|
||||
if (dy <= 0 || scrollHeight == null) {
|
||||
if (dy < 0 || scrollHeight == null) {
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
scrollService.scrollTo(
|
||||
|
|
|
|||
|
|
@ -109,6 +109,10 @@ class TestableEditor {
|
|||
outdentCommand,
|
||||
|
||||
exitEditingCommand,
|
||||
|
||||
//
|
||||
pageUpCommand,
|
||||
pageDownCommand,
|
||||
],
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import '../../infra/test_editor.dart';
|
||||
import '../../new/infra/testable_editor.dart';
|
||||
|
||||
void main() async {
|
||||
setUpAll(() {
|
||||
|
|
@ -12,38 +12,26 @@ void main() async {
|
|||
testWidgets('Presses PageUp and pageDown key in large document',
|
||||
(tester) async {
|
||||
const text = 'Welcome to Appflowy 😁';
|
||||
final editor = tester.editor;
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
editor.insertTextNode(text);
|
||||
}
|
||||
final editor = tester.editor..addParagraphs(1000, initialText: text);
|
||||
await editor.startTesting();
|
||||
await editor.updateSelection(
|
||||
Selection.single(path: [0], startOffset: 0),
|
||||
);
|
||||
|
||||
final scrollService = editor.editorState.service.scrollService;
|
||||
|
||||
expect(scrollService != null, true);
|
||||
|
||||
if (scrollService == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final page = scrollService.page;
|
||||
final onePageHeight = scrollService.onePageHeight;
|
||||
expect(page != null, true);
|
||||
expect(onePageHeight != null, true);
|
||||
final scrollService = editor.editorState.service.scrollService!;
|
||||
final page = scrollService.page!;
|
||||
final onePageHeight = scrollService.onePageHeight!;
|
||||
|
||||
// Pressing the pageDown key continuously.
|
||||
var currentOffsetY = 0.0;
|
||||
for (int i = 1; i <= page!; i++) {
|
||||
for (int i = 1; i <= page; i++) {
|
||||
await editor.pressLogicKey(
|
||||
key: LogicalKeyboardKey.pageDown,
|
||||
);
|
||||
if (i == page) {
|
||||
currentOffsetY = scrollService.maxScrollExtent;
|
||||
} else {
|
||||
currentOffsetY += onePageHeight!;
|
||||
currentOffsetY += onePageHeight;
|
||||
}
|
||||
final dy = scrollService.dy;
|
||||
expect(dy, currentOffsetY);
|
||||
|
|
@ -65,9 +53,9 @@ void main() async {
|
|||
if (i == 1) {
|
||||
currentOffsetY = scrollService.minScrollExtent;
|
||||
} else {
|
||||
currentOffsetY -= onePageHeight!;
|
||||
currentOffsetY -= onePageHeight;
|
||||
}
|
||||
final dy = editor.editorState.service.scrollService?.dy;
|
||||
final dy = scrollService.dy;
|
||||
expect(dy, currentOffsetY);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue