|
@@ -1,130 +1,79 @@
|
|
|
import 'package:appflowy_editor/src/render/image/image_node_widget.dart';
|
|
|
-import 'package:appflowy_editor/src/service/editor_service.dart';
|
|
|
+import 'package:flutter/gestures.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
import 'package:network_image_mock/network_image_mock.dart';
|
|
|
|
|
|
-import '../../infra/test_editor.dart';
|
|
|
-
|
|
|
void main() async {
|
|
|
setUpAll(() {
|
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
});
|
|
|
|
|
|
group('image_node_widget.dart', () {
|
|
|
- testWidgets('render image node', (tester) async {
|
|
|
- mockNetworkImagesFor(() async {
|
|
|
- const text = 'Welcome to Appflowy 😁';
|
|
|
- const src =
|
|
|
- 'https://images.unsplash.com/photo-1471897488648-5eae4ac6686b?ixlib=rb-1.2.1&dl=sarah-dorweiler-QeVmJxZOv3k-unsplash.jpg&w=640&q=80&fm=jpg&crop=entropy&cs=tinysrgb';
|
|
|
- final editor = tester.editor
|
|
|
- ..insertTextNode(text)
|
|
|
- ..insertImageNode(src)
|
|
|
- ..insertTextNode(text);
|
|
|
- await editor.startTesting();
|
|
|
-
|
|
|
- expect(editor.documentLength, 3);
|
|
|
- expect(find.byType(Image), findsOneWidget);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- testWidgets('render image align', (tester) async {
|
|
|
+ testWidgets('build the image node widget', (tester) async {
|
|
|
mockNetworkImagesFor(() async {
|
|
|
- const text = 'Welcome to Appflowy 😁';
|
|
|
+ var onCopyHit = false;
|
|
|
+ var onDeleteHit = false;
|
|
|
+ var onAlignHit = false;
|
|
|
const src =
|
|
|
'https://images.unsplash.com/photo-1471897488648-5eae4ac6686b?ixlib=rb-1.2.1&dl=sarah-dorweiler-QeVmJxZOv3k-unsplash.jpg&w=640&q=80&fm=jpg&crop=entropy&cs=tinysrgb';
|
|
|
- final editor = tester.editor
|
|
|
- ..insertTextNode(text)
|
|
|
- ..insertImageNode(src, align: 'left')
|
|
|
- ..insertImageNode(src, align: 'center')
|
|
|
- ..insertImageNode(src, align: 'right')
|
|
|
- ..insertTextNode(text);
|
|
|
- await editor.startTesting();
|
|
|
-
|
|
|
- expect(editor.documentLength, 5);
|
|
|
- final imageFinder = find.byType(Image);
|
|
|
- expect(imageFinder, findsNWidgets(3));
|
|
|
|
|
|
- final editorFinder = find.byType(AppFlowyEditor);
|
|
|
- final editorRect = tester.getRect(editorFinder);
|
|
|
-
|
|
|
- final leftImageRect = tester.getRect(imageFinder.at(0));
|
|
|
- expect(leftImageRect.left, editorRect.left);
|
|
|
- final rightImageRect = tester.getRect(imageFinder.at(2));
|
|
|
- expect(rightImageRect.right, editorRect.right);
|
|
|
- final centerImageRect = tester.getRect(imageFinder.at(1));
|
|
|
- expect(centerImageRect.left,
|
|
|
- (leftImageRect.left + rightImageRect.left) / 2.0);
|
|
|
- expect(leftImageRect.size, centerImageRect.size);
|
|
|
- expect(rightImageRect.size, centerImageRect.size);
|
|
|
+ final widget = ImageNodeWidget(
|
|
|
+ src: src,
|
|
|
+ alignment: Alignment.center,
|
|
|
+ onCopy: () {
|
|
|
+ onCopyHit = true;
|
|
|
+ },
|
|
|
+ onDelete: () {
|
|
|
+ onDeleteHit = true;
|
|
|
+ },
|
|
|
+ onAlign: (alignment) {
|
|
|
+ onAlignHit = true;
|
|
|
+ },
|
|
|
+ );
|
|
|
|
|
|
- final imageNodeWidgetFinder = find.byType(ImageNodeWidget);
|
|
|
+ await tester.pumpWidget(
|
|
|
+ MaterialApp(
|
|
|
+ home: Material(
|
|
|
+ child: widget,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ expect(find.byType(ImageNodeWidget), findsOneWidget);
|
|
|
|
|
|
- final leftImage =
|
|
|
- tester.firstWidget(imageNodeWidgetFinder) as ImageNodeWidget;
|
|
|
+ final gesture =
|
|
|
+ await tester.createGesture(kind: PointerDeviceKind.mouse);
|
|
|
+ await gesture.addPointer(location: Offset.zero);
|
|
|
|
|
|
- leftImage.onAlign(Alignment.center);
|
|
|
- await tester.pump(const Duration(milliseconds: 100));
|
|
|
- expect(
|
|
|
- tester.getRect(imageFinder.at(0)).left,
|
|
|
- centerImageRect.left,
|
|
|
- );
|
|
|
+ expect(find.byType(ImageToolbar), findsNothing);
|
|
|
|
|
|
- leftImage.onAlign(Alignment.centerRight);
|
|
|
- await tester.pump(const Duration(milliseconds: 100));
|
|
|
- expect(
|
|
|
- tester.getRect(imageFinder.at(0)).left,
|
|
|
- rightImageRect.left,
|
|
|
- );
|
|
|
- });
|
|
|
- });
|
|
|
+ addTearDown(gesture.removePointer);
|
|
|
+ await tester.pump();
|
|
|
+ await gesture.moveTo(tester.getCenter(find.byType(ImageNodeWidget)));
|
|
|
+ await tester.pump();
|
|
|
|
|
|
- testWidgets('render image copy', (tester) async {
|
|
|
- mockNetworkImagesFor(() async {
|
|
|
- const text = 'Welcome to Appflowy 😁';
|
|
|
- const src =
|
|
|
- 'https://images.unsplash.com/photo-1471897488648-5eae4ac6686b?ixlib=rb-1.2.1&dl=sarah-dorweiler-QeVmJxZOv3k-unsplash.jpg&w=640&q=80&fm=jpg&crop=entropy&cs=tinysrgb';
|
|
|
- final editor = tester.editor
|
|
|
- ..insertTextNode(text)
|
|
|
- ..insertImageNode(src)
|
|
|
- ..insertTextNode(text);
|
|
|
- await editor.startTesting();
|
|
|
+ expect(find.byType(ImageToolbar), findsOneWidget);
|
|
|
|
|
|
- expect(editor.documentLength, 3);
|
|
|
- final imageFinder = find.byType(Image);
|
|
|
- expect(imageFinder, findsOneWidget);
|
|
|
+ final iconFinder = find.byType(IconButton);
|
|
|
+ expect(iconFinder, findsNWidgets(5));
|
|
|
|
|
|
- final imageNodeWidgetFinder = find.byType(ImageNodeWidget);
|
|
|
- final image =
|
|
|
- tester.firstWidget(imageNodeWidgetFinder) as ImageNodeWidget;
|
|
|
- image.onCopy();
|
|
|
- });
|
|
|
- });
|
|
|
+ await tester.tap(iconFinder.at(0));
|
|
|
+ expect(onAlignHit, true);
|
|
|
+ onAlignHit = false;
|
|
|
|
|
|
- testWidgets('render image delete', (tester) async {
|
|
|
- mockNetworkImagesFor(() async {
|
|
|
- const text = 'Welcome to Appflowy 😁';
|
|
|
- const src =
|
|
|
- 'https://images.unsplash.com/photo-1471897488648-5eae4ac6686b?ixlib=rb-1.2.1&dl=sarah-dorweiler-QeVmJxZOv3k-unsplash.jpg&w=640&q=80&fm=jpg&crop=entropy&cs=tinysrgb';
|
|
|
- final editor = tester.editor
|
|
|
- ..insertTextNode(text)
|
|
|
- ..insertImageNode(src)
|
|
|
- ..insertImageNode(src)
|
|
|
- ..insertTextNode(text);
|
|
|
- await editor.startTesting();
|
|
|
+ await tester.tap(iconFinder.at(1));
|
|
|
+ expect(onAlignHit, true);
|
|
|
+ onAlignHit = false;
|
|
|
|
|
|
- expect(editor.documentLength, 4);
|
|
|
- final imageFinder = find.byType(Image);
|
|
|
- expect(imageFinder, findsNWidgets(2));
|
|
|
+ await tester.tap(iconFinder.at(2));
|
|
|
+ expect(onAlignHit, true);
|
|
|
+ onAlignHit = false;
|
|
|
|
|
|
- final imageNodeWidgetFinder = find.byType(ImageNodeWidget);
|
|
|
- final image =
|
|
|
- tester.firstWidget(imageNodeWidgetFinder) as ImageNodeWidget;
|
|
|
- image.onDelete();
|
|
|
+ await tester.tap(iconFinder.at(3));
|
|
|
+ expect(onCopyHit, true);
|
|
|
|
|
|
- await tester.pump(const Duration(milliseconds: 100));
|
|
|
- expect(editor.documentLength, 3);
|
|
|
- expect(find.byType(Image), findsNWidgets(1));
|
|
|
+ await tester.tap(iconFinder.at(4));
|
|
|
+ expect(onDeleteHit, true);
|
|
|
});
|
|
|
});
|
|
|
});
|