appflowy-editor/test/customer/custom_editor_directionality_test.dart
Lucas 41335c54ae
chore: merge flutter 3_27_4 into main branch (#1228)
* chore: merge flutter/3_27_4 to main branch

* chore: code format

* fix: unit tests
2026-07-27 15:37:27 +08:00

64 lines
2 KiB
Dart

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:network_image_mock/network_image_mock.dart';
void main() async {
await AppFlowyEditorLocalizations.load(
const Locale.fromSubtags(languageCode: 'en'),
);
testWidgets('wrapp editor with directionality', (tester) async {
await mockNetworkImagesFor(() async {
const widget = DirectionalityTester();
await tester.pumpWidget(widget);
await tester.pumpAndSettle();
final editorState = tester
.widget(find.byType(AppFlowyEditor))
.unwrapOrNull<AppFlowyEditor>()!
.editorState;
final Node headerNode = editorState.getNodeAtPath([0])!;
final Node textNode = editorState.getNodeAtPath([1])!;
expect(headerNode.selectable?.textDirection(), TextDirection.rtl);
expect(textNode.selectable?.textDirection(), TextDirection.rtl);
});
});
}
class DirectionalityTester extends StatelessWidget {
const DirectionalityTester({super.key});
@override
Widget build(BuildContext context) {
final document = Document.blank()
..insert(
[0],
[
headingNode(level: 1, delta: Delta()..insert('سلام از Appflowy')),
paragraphNode(text: 'این یک متن راست به چپ است'),
],
);
final editorState = EditorState(document: document);
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: SizedBox(
width: 500,
child: Directionality(
textDirection: TextDirection.rtl,
child: AppFlowyEditor(
editorState: editorState,
blockComponentBuilders: standardBlockComponentBuilderMap,
commandShortcutEvents: standardCommandShortcutEvents,
characterShortcutEvents: standardCharacterShortcutEvents,
),
),
),
),
),
);
}
}