* feat: support in memory transaction update * test: support in memory transaction update
49 lines
1.5 KiB
Dart
49 lines
1.5 KiB
Dart
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;
|
|
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);
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|
|
}
|