From e21b48b7d373c78e2334ae502a2f43d682a4ed50 Mon Sep 17 00:00:00 2001 From: Morn Date: Wed, 9 Apr 2025 12:59:33 +0800 Subject: [PATCH] fix: test errors --- .../document_copy_and_paste_test.dart | 47 ++++++++----------- .../copy_and_paste/custom_paste_command.dart | 1 + .../lib/util/default_extensions.dart | 8 ++++ .../lib/src/theme/data/builder.dart | 4 +- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart index fa98ef4eca..ee82f01d3f 100644 --- a/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart +++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart @@ -1,10 +1,11 @@ +import 'dart:async'; import 'dart:io'; import 'package:appflowy/generated/locale_keys.g.dart'; -import 'package:appflowy/plugins/document/presentation/editor_plugins/block_menu/block_menu_button.dart'; import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart'; import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart'; import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview.dart'; +import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/link_preview_menu.dart'; import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/paste_as/paste_as_menu.dart'; import 'package:appflowy/startup/startup.dart'; import 'package:appflowy_editor/appflowy_editor.dart'; @@ -323,16 +324,12 @@ void main() { await tester.pasteContent(plainText: url, (editorState) async { final pasteAsMenu = find.byType(PasteAsMenu); expect(pasteAsMenu, findsOneWidget); - final bookmarkButton = find.descendant( - of: pasteAsMenu, - matching: find.text( - LocaleKeys.document_plugins_linkPreview_typeSelection_bookmark - .tr(), - ), + final bookmarkButton = find.text( + LocaleKeys.document_plugins_linkPreview_typeSelection_bookmark.tr(), ); await tester.tapButton(bookmarkButton); // the second one is the paragraph node - expect(editorState.document.root.children.length, 2); + expect(editorState.document.root.children.length, 1); final node = editorState.getNodeAtPath([0])!; expect(node.type, LinkPreviewBlockKeys.type); expect(node.attributes[LinkPreviewBlockKeys.url], url); @@ -344,19 +341,19 @@ void main() { await tester.hoverOnWidget( find.byType(CustomLinkPreviewWidget), onHover: () async { - final convertToLinkButton = find.byWidgetPredicate((widget) { - return widget is MenuBlockButton && - widget.tooltip == - LocaleKeys.document_plugins_urlPreview_convertToLink.tr(); - }); + /// show menu + final menu = find.byType(CustomLinkPreviewMenu); + expect(menu, findsOneWidget); + await tester.tapButton(menu); + + final convertToLinkButton = find.text( + LocaleKeys.document_plugins_linkPreview_linkPreviewMenu_toUrl.tr(), + ); expect(convertToLinkButton, findsOneWidget); - await tester.tap(convertToLinkButton); - await tester.pumpAndSettle(); + await tester.tapButton(convertToLinkButton); }, ); - await tester.pumpAndSettle(); - final editorState = tester.editor.getCurrentEditorState(); final textNode = editorState.getNodeAtPath([0])!; expect(textNode.type, ParagraphBlockKeys.type); @@ -376,22 +373,18 @@ void main() { await tester.pasteContent(plainText: url, (editorState) async { final pasteAsMenu = find.byType(PasteAsMenu); expect(pasteAsMenu, findsOneWidget); - final bookmarkButton = find.descendant( - of: pasteAsMenu, - matching: find.text( - LocaleKeys.document_plugins_linkPreview_typeSelection_bookmark - .tr(), - ), + final bookmarkButton = find.text( + LocaleKeys.document_plugins_linkPreview_typeSelection_bookmark.tr(), ); await tester.tapButton(bookmarkButton); // the second one is the paragraph node - expect(editorState.document.root.children.length, 2); + expect(editorState.document.root.children.length, 1); final node = editorState.getNodeAtPath([0])!; expect(node.type, LinkPreviewBlockKeys.type); expect(node.attributes[LinkPreviewBlockKeys.url], url); }); - await tester.editor.tapLineOfEditorAt(0); + await tester.simulateKeyEvent( LogicalKeyboardKey.keyZ, isControlPressed: @@ -542,7 +535,7 @@ void main() { extension on WidgetTester { Future pasteContent( - void Function(EditorState editorState) test, { + FutureOr Function(EditorState editorState) test, { Future Function(EditorState editorState)? beforeTest, String? plainText, String? html, @@ -579,6 +572,6 @@ extension on WidgetTester { ); await pumpAndSettle(const Duration(milliseconds: 1000)); - test(editor.getCurrentEditorState()); + await test(editor.getCurrentEditorState()); } } diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart index 5c5ac3a162..dd3f7362a9 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart @@ -254,6 +254,7 @@ Future doPlainPaste(EditorState editorState) async { } Future _isImageUrl(String text) async { + if (isNotImageUrl(text)) return false; final response = await http.head(Uri.parse(text)); if (response.statusCode == 200) { diff --git a/frontend/appflowy_flutter/lib/util/default_extensions.dart b/frontend/appflowy_flutter/lib/util/default_extensions.dart index 36bbdcb6b4..e13e50f23c 100644 --- a/frontend/appflowy_flutter/lib/util/default_extensions.dart +++ b/frontend/appflowy_flutter/lib/util/default_extensions.dart @@ -13,3 +13,11 @@ const List defaultImageExtensions = [ 'webp', 'bmp', ]; + +bool isNotImageUrl(String url) { + final nonImageSuffixRegex = RegExp( + r'\.(io|html|php|json|txt|js|css|xml|md|log)(\?.*)?(#.*)?$', + caseSensitive: false, + ); + return nonImageSuffixRegex.hasMatch(url); +} diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/builder.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/builder.dart index 668644f196..c17dd14578 100644 --- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/builder.dart +++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/builder.dart @@ -151,7 +151,7 @@ class AppFlowyThemeBuilder { Brightness brightness, ) { return switch (brightness) { - Brightness.light => AppFlowyFillColorScheme( + Brightness.dark => AppFlowyFillColorScheme( primary: colorScheme.neutral.neutral100, primaryHover: colorScheme.neutral.neutral200, secondary: colorScheme.neutral.neutral300, @@ -196,7 +196,7 @@ class AppFlowyThemeBuilder { purpleThick: colorScheme.purple.purple500, purpleThickHover: colorScheme.purple.purple600, ), - Brightness.dark => AppFlowyFillColorScheme( + Brightness.light => AppFlowyFillColorScheme( primary: colorScheme.neutral.neutral1000, primaryHover: colorScheme.neutral.neutral900, secondary: colorScheme.neutral.neutral600,