1+ import 'dart:async' ;
12import 'dart:io' ;
23
34import 'package:appflowy/generated/locale_keys.g.dart' ;
4- import 'package:appflowy/plugins/document/presentation/editor_plugins/block_menu/block_menu_button.dart' ;
55import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart' ;
66import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart' ;
77import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview.dart' ;
8+ import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/link_preview_menu.dart' ;
9+ import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/paste_as/paste_as_menu.dart' ;
810import 'package:appflowy/startup/startup.dart' ;
911import 'package:appflowy_editor/appflowy_editor.dart' ;
1012import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart' ;
@@ -320,8 +322,14 @@ void main() {
320322 (tester) async {
321323 const url = 'https://appflowy.io' ;
322324 await tester.pasteContent (plainText: url, (editorState) async {
325+ final pasteAsMenu = find.byType (PasteAsMenu );
326+ expect (pasteAsMenu, findsOneWidget);
327+ final bookmarkButton = find.text (
328+ LocaleKeys .document_plugins_linkPreview_typeSelection_bookmark.tr (),
329+ );
330+ await tester.tapButton (bookmarkButton);
323331 // the second one is the paragraph node
324- expect (editorState.document.root.children.length, 2 );
332+ expect (editorState.document.root.children.length, 1 );
325333 final node = editorState.getNodeAtPath ([0 ])! ;
326334 expect (node.type, LinkPreviewBlockKeys .type);
327335 expect (node.attributes[LinkPreviewBlockKeys .url], url);
@@ -333,19 +341,19 @@ void main() {
333341 await tester.hoverOnWidget (
334342 find.byType (CustomLinkPreviewWidget ),
335343 onHover: () async {
336- final convertToLinkButton = find.byWidgetPredicate ((widget) {
337- return widget is MenuBlockButton &&
338- widget.tooltip ==
339- LocaleKeys .document_plugins_urlPreview_convertToLink.tr ();
340- });
344+ /// show menu
345+ final menu = find.byType (CustomLinkPreviewMenu );
346+ expect (menu, findsOneWidget);
347+ await tester.tapButton (menu);
348+
349+ final convertToLinkButton = find.text (
350+ LocaleKeys .document_plugins_linkPreview_linkPreviewMenu_toUrl.tr (),
351+ );
341352 expect (convertToLinkButton, findsOneWidget);
342- await tester.tap (convertToLinkButton);
343- await tester.pumpAndSettle ();
353+ await tester.tapButton (convertToLinkButton);
344354 },
345355 );
346356
347- await tester.pumpAndSettle ();
348-
349357 final editorState = tester.editor.getCurrentEditorState ();
350358 final textNode = editorState.getNodeAtPath ([0 ])! ;
351359 expect (textNode.type, ParagraphBlockKeys .type);
@@ -363,14 +371,20 @@ void main() {
363371 (tester) async {
364372 const url = 'https://appflowy.io' ;
365373 await tester.pasteContent (plainText: url, (editorState) async {
374+ final pasteAsMenu = find.byType (PasteAsMenu );
375+ expect (pasteAsMenu, findsOneWidget);
376+ final bookmarkButton = find.text (
377+ LocaleKeys .document_plugins_linkPreview_typeSelection_bookmark.tr (),
378+ );
379+ await tester.tapButton (bookmarkButton);
366380 // the second one is the paragraph node
367- expect (editorState.document.root.children.length, 2 );
381+ expect (editorState.document.root.children.length, 1 );
368382 final node = editorState.getNodeAtPath ([0 ])! ;
369383 expect (node.type, LinkPreviewBlockKeys .type);
370384 expect (node.attributes[LinkPreviewBlockKeys .url], url);
371385 });
372386
373- await tester.editor. tapLineOfEditorAt ( 0 );
387+
374388 await tester.simulateKeyEvent (
375389 LogicalKeyboardKey .keyZ,
376390 isControlPressed:
@@ -521,7 +535,7 @@ void main() {
521535
522536extension on WidgetTester {
523537 Future <void > pasteContent (
524- void Function (EditorState editorState) test, {
538+ FutureOr < void > Function (EditorState editorState) test, {
525539 Future <void > Function (EditorState editorState)? beforeTest,
526540 String ? plainText,
527541 String ? html,
@@ -558,6 +572,6 @@ extension on WidgetTester {
558572 );
559573 await pumpAndSettle (const Duration (milliseconds: 1000 ));
560574
561- test (editor.getCurrentEditorState ());
575+ await test (editor.getCurrentEditorState ());
562576 }
563577}
0 commit comments