2023-04-27 16:13:29 +08:00
|
|
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
|
|
|
|
|
|
import '../util/util.dart';
|
|
|
|
|
|
|
|
|
|
Future<void> testFormatCharacterShortcut(
|
|
|
|
|
CharacterShortcutEvent event,
|
|
|
|
|
String prefix,
|
|
|
|
|
int index,
|
2023-08-28 14:41:58 +05:30
|
|
|
void Function(bool result, Node before, Node after, EditorState editorState)
|
|
|
|
|
test, {
|
2023-04-27 16:13:29 +08:00
|
|
|
String text = 'Welcome to AppFlowy Editor 🔥!',
|
|
|
|
|
}) async {
|
2023-04-28 10:54:21 +08:00
|
|
|
final document = Document.blank().addParagraph(
|
2023-04-28 19:48:34 +08:00
|
|
|
builder: (index) => Delta()..insert('$prefix$text'),
|
2023-04-27 16:13:29 +08:00
|
|
|
);
|
|
|
|
|
final editorState = EditorState(document: document);
|
|
|
|
|
|
|
|
|
|
final selection = Selection.collapsed(
|
|
|
|
|
Position(path: [0], offset: index),
|
|
|
|
|
);
|
|
|
|
|
editorState.selection = selection;
|
|
|
|
|
final before = editorState.getNodesInSelection(selection).first;
|
|
|
|
|
final result = await event.execute(editorState);
|
|
|
|
|
final after = editorState.getNodesInSelection(selection).first;
|
|
|
|
|
|
2023-08-28 14:41:58 +05:30
|
|
|
test(result, before, after, editorState);
|
2023-04-27 16:13:29 +08:00
|
|
|
}
|