feat: add document rules (#1071)

This commit is contained in:
Lucas 2025-03-19 10:21:20 +08:00 • committed by GitHub
commit f2685cb900
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,31 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('at least one editable node rule', () async {
final rule = AtLeastOneEditableNodeRule();
final node1 = paragraphNode(text: 'Hello World!');
final node2 = paragraphNode(text: 'Hello World!');
final node3 = paragraphNode(text: 'Hello World!');
final document = Document(
root: pageNode(
children: [
node1,
node2,
node3,
],
),
);
final editorState = EditorState(document: document)..documentRules = [rule];
// delete all the nodes
final transaction = editorState.transaction;
transaction.deleteNodes([node1, node2, node3]);
await editorState.apply(transaction);
await Future.delayed(const Duration(milliseconds: 100));
final node = editorState.document.root.children[0];
expect(node.type, ParagraphBlockKeys.type);
editorState.dispose();
});
}