2023-06-21 13:21:52 +08:00
|
|
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
|
group('editor state', () {
|
|
|
|
|
test('broadcast the transaction', () async {
|
|
|
|
|
final editorState = EditorState.blank(
|
|
|
|
|
withInitialText: false,
|
|
|
|
|
);
|
|
|
|
|
int count = 0;
|
|
|
|
|
editorState.transactionStream.listen((event) {
|
|
|
|
|
count++;
|
|
|
|
|
final time = event.$1;
|
|
|
|
|
switch (time) {
|
|
|
|
|
case TransactionTime.before:
|
|
|
|
|
expect(editorState.getNodeAtPath([0]), null);
|
|
|
|
|
break;
|
2025-12-23 15:12:57 +08:00
|
|
|
|
2023-06-21 13:21:52 +08:00
|
|
|
case TransactionTime.after:
|
|
|
|
|
expect(
|
|
|
|
|
editorState.getNodeAtPath([0])!.type,
|
|
|
|
|
ParagraphBlockKeys.type,
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
final transaction = editorState.transaction;
|
|
|
|
|
transaction.insertNode([0], paragraphNode(text: 'Hello World!'));
|
|
|
|
|
await editorState.apply(transaction);
|
|
|
|
|
expect(count, 2);
|
|
|
|
|
});
|
2024-11-25 11:07:47 +08:00
|
|
|
|
|
|
|
|
test('transaction stream', () async {
|
|
|
|
|
final editorState = EditorState.blank(
|
|
|
|
|
withInitialText: false,
|
|
|
|
|
);
|
|
|
|
|
var isInMemoryUpdate = false;
|
|
|
|
|
editorState.transactionStream.listen((event) {
|
|
|
|
|
isInMemoryUpdate = event.$3.inMemoryUpdate;
|
|
|
|
|
});
|
|
|
|
|
final transaction = editorState.transaction;
|
|
|
|
|
transaction.insertNode([0], paragraphNode(text: 'Hello World!'));
|
|
|
|
|
await editorState.apply(
|
|
|
|
|
transaction,
|
|
|
|
|
options: const ApplyOptions(inMemoryUpdate: true),
|
|
|
|
|
);
|
|
|
|
|
expect(isInMemoryUpdate, true);
|
|
|
|
|
});
|
2023-06-21 13:21:52 +08:00
|
|
|
});
|
|
|
|
|
}
|