浏览代码

feat: add link menu test

Lucas.Xu 2 年之前
父节点
当前提交
1262457755

+ 15 - 14
frontend/app_flowy/packages/appflowy_editor/lib/src/render/link_menu/link_menu.dart

@@ -40,24 +40,25 @@ class _LinkMenuState extends State<LinkMenu> {
 
   @override
   Widget build(BuildContext context) {
-    return Container(
-      decoration: BoxDecoration(
-        color: Colors.white,
-        boxShadow: [
-          BoxShadow(
-            blurRadius: 5,
-            spreadRadius: 1,
-            color: Colors.black.withOpacity(0.1),
-          ),
-        ],
-        borderRadius: BorderRadius.circular(6.0),
-      ),
-      child: SizedBox(
-        width: 350,
+    return SizedBox(
+      width: 350,
+      child: Container(
+        decoration: BoxDecoration(
+          color: Colors.white,
+          boxShadow: [
+            BoxShadow(
+              blurRadius: 5,
+              spreadRadius: 1,
+              color: Colors.black.withOpacity(0.1),
+            ),
+          ],
+          borderRadius: BorderRadius.circular(6.0),
+        ),
         child: Padding(
           padding: const EdgeInsets.all(20.0),
           child: Column(
             crossAxisAlignment: CrossAxisAlignment.start,
+            mainAxisSize: MainAxisSize.min,
             children: [
               _buildHeader(),
               const SizedBox(height: 16.0),

+ 1 - 3
frontend/app_flowy/packages/appflowy_editor/lib/src/render/toolbar/toolbar_item.dart

@@ -181,11 +181,9 @@ void _showLinkMenu(EditorState editorState, BuildContext context) {
   final length = (selection.start.offset - selection.end.offset).abs();
   final node = editorState.service.selectionService.currentSelectedNodes.first
       as TextNode;
-  final String linkText;
+  String? linkText;
   if (node.allSatisfyLinkInSelection(selection)) {
     linkText = node.getAttributeInSelection(selection, StyleKey.href);
-  } else {
-    linkText = '';
   }
   _linkMenuOverlay = OverlayEntry(builder: (context) {
     return Positioned(

+ 41 - 0
frontend/app_flowy/packages/appflowy_editor/test/render/link_menu/link_menu_test.dart

@@ -0,0 +1,41 @@
+import 'package:appflowy_editor/src/render/link_menu/link_menu.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+void main() async {
+  setUpAll(() {
+    TestWidgetsFlutterBinding.ensureInitialized();
+  });
+
+  group('link_menu.dart', () {
+    testWidgets('test empty link menu actions', (tester) async {
+      const link = 'appflowy.io';
+      var submittedText = '';
+      final linkMenu = LinkMenu(
+        onCopyLink: () {},
+        onRemoveLink: () {},
+        onSubmitted: (text) {
+          submittedText = text;
+        },
+      );
+      await tester.pumpWidget(
+        MaterialApp(
+          home: Material(
+            child: linkMenu,
+          ),
+        ),
+      );
+
+      expect(find.byType(TextButton), findsNothing);
+      expect(find.byType(TextField), findsOneWidget);
+
+      await tester.tap(find.byType(TextField));
+      await tester.enterText(find.byType(TextField), link);
+      await tester.pumpAndSettle();
+      await tester.testTextInput.receiveAction(TextInputAction.done);
+      await tester.pumpAndSettle();
+
+      expect(submittedText, link);
+    });
+  });
+}