From bcd09994782a5920c227582f230a9b5c34daa5c9 Mon Sep 17 00:00:00 2001
From: Sun Jiao
Date: Fri, 15 Sep 2023 14:27:05 +0800
Subject: [PATCH] fix: added lines were not covered by tests
---
.../image_upload_widget_test.dart | 49 +++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/test/editor/block_component/image_block_component/image_upload_widget_test.dart b/test/editor/block_component/image_block_component/image_upload_widget_test.dart
index 276d5cb52..0413d842d 100644
--- a/test/editor/block_component/image_block_component/image_upload_widget_test.dart
+++ b/test/editor/block_component/image_block_component/image_upload_widget_test.dart
@@ -1,7 +1,11 @@
+import 'dart:convert';
+
import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../new/util/util.dart';
+import '../../../test_helper.dart';
void main() {
group('InsertImage', () {
@@ -19,4 +23,49 @@ void main() {
expect(editorState.document.root.children.length, 2);
});
});
+
+ group('ImageWidget', () {
+ testWidgets('invalidURL', (tester) async {
+ await tester.buildAndPump(
+ UploadImageMenu(
+ onSubmitted: (String text) {},
+ onUpload: (String text) {},
+ ),
+ );
+
+ final urlButtonFinder = find.widgetWithText(Tab, 'URL Image');
+ expect(urlButtonFinder, findsOneWidget);
+ await tester.tap(urlButtonFinder);
+ await tester.pumpAndSettle();
+ final urlFieldFinder = find.widgetWithText(TextField, 'URL');
+ expect(urlFieldFinder, findsOneWidget);
+ await tester.enterText(urlFieldFinder, 'Hello World!');
+ final uploadButtonFinder = find.text('Upload');
+ expect(uploadButtonFinder, findsOneWidget);
+ await tester.tap(uploadButtonFinder);
+ await tester.pumpAndSettle();
+ final incorrectLinkFinder = find.text('Incorrect Link');
+ expect(incorrectLinkFinder, findsOneWidget);
+ });
+
+ testWidgets('imageLoadError', (tester) async {
+ await AppFlowyEditorLocalizations.load(
+ const Locale.fromSubtags(languageCode: 'en'),
+ );
+
+ await tester.buildAndPump(
+ AppFlowyEditor(
+ editorState: EditorState(
+ document: Document.fromJson(
+ json.decode(
+ '{"document":{"type":"page","children":[{"type":"heading","data":{"level":2,"delta":[]}},{"type":"image","data":{"url":"https://127.0.0.1/image/not/exist.jpg","align":"center"}}]}}',
+ ),
+ ),
+ ),
+ ),
+ );
+ final couldNotLoadFinder = find.text('Could not load the image');
+ expect(couldNotLoadFinder, findsOneWidget);
+ });
+ });
}