Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

test: add edit link menu test (#7097)

Morn3d4d4cf70975
diff --git a/frontend/appflowy_flutter/integration_test/mobile/document/document_test_runner.dart b/frontend/appflowy_flutter/integration_test/mobile/document/document_test_runner.dart
index 67fdaaa204..e19896b310 100644
--- a/frontend/appflowy_flutter/integration_test/mobile/document/document_test_runner.dart
+++ b/frontend/appflowy_flutter/integration_test/mobile/document/document_test_runner.dart
@@ -4,6 +4,7 @@ import 'page_style_test.dart' as page_style_test;
import 'plus_menu_test.dart' as plus_menu_test;
import 'simple_table_test.dart' as simple_table_test;
import 'title_test.dart' as title_test;
+import 'toolbar_test.dart' as toolbar_test;
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
@@ -13,4 +14,5 @@ void main() {
page_style_test.main();
plus_menu_test.main();
simple_table_test.main();
+ toolbar_test.main();
}
diff --git a/frontend/appflowy_flutter/integration_test/mobile/document/toolbar_test.dart b/frontend/appflowy_flutter/integration_test/mobile/document/toolbar_test.dart
new file mode 100644
index 0000000000..72da283cd6
--- /dev/null
+++ b/frontend/appflowy_flutter/integration_test/mobile/document/toolbar_test.dart
@@ -0,0 +1,117 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/mobile/presentation/editor/mobile_editor_screen.dart';
+import 'package:appflowy/mobile/presentation/mobile_bottom_navigation_bar.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/appflowy_mobile_toolbar_item.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/util.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:easy_localization/easy_localization.dart';
+import 'package:flowy_infra_ui/style_widget/text_field.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:integration_test/integration_test.dart';
+
+import '../../shared/util.dart';
+
+void main() {
+ IntegrationTestWidgetsFlutterBinding.ensureInitialized();
+
+ group('toolbar menu:', () {
+ testWidgets('insert links', (tester) async {
+ await tester.launchInAnonymousMode();
+
+ final createPageButton = find.byKey(
+ BottomNavigationBarItemType.add.valueKey,
+ );
+ await tester.tapButton(createPageButton);
+ expect(find.byType(MobileDocumentScreen), findsOneWidget);
+
+ final editor = find.byType(AppFlowyEditor);
+ expect(editor, findsOneWidget);
+ final editorState = tester.editor.getCurrentEditorState();
+
+ /// move cursor to content
+ final root = editorState.document.root;
+ final lastNode = root.children.lastOrNull;
+ await editorState.updateSelectionWithReason(
+ Selection.collapsed(Position(path: lastNode!.path)),
+ );
+ await tester.pumpAndSettle();
+
+ /// insert two lines of text
+ const strFirst = 'FirstLine',
+ strSecond = 'SecondLine',
+ link = 'google.com';
+ await editorState.insertTextAtCurrentSelection(strFirst);
+ await tester.pumpAndSettle();
+ await editorState.insertNewLine();
+ await tester.pumpAndSettle();
+ await editorState.insertTextAtCurrentSelection(strSecond);
+ await tester.pumpAndSettle();
+ final firstLine = find.text(strFirst, findRichText: true),
+ secondLine = find.text(strSecond, findRichText: true);
+ expect(firstLine, findsOneWidget);
+ expect(secondLine, findsOneWidget);
+
+ /// select the first line
+ await tester.longPress(firstLine);
+ await tester.pumpAndSettle();
+
+ /// find aa item and tap it
+ final aaItem = find.byWidgetPredicate(
+ (widget) =>
+ widget is AppFlowyMobileToolbarIconItem &&
+ widget.icon == FlowySvgs.m_toolbar_aa_m,
+ );
+ expect(aaItem, findsOneWidget);
+ await tester.tapButton(aaItem);
+
+ /// find link button and tap it
+ final linkButton = find.byWidgetPredicate(
+ (widget) =>
+ widget is MobileToolbarMenuItemWrapper &&
+ widget.icon == FlowySvgs.m_toolbar_link_m,
+ );
+ expect(linkButton, findsOneWidget);
+ await tester.tapButton(linkButton);
+
+ /// input the link
+ final linkField = find.byWidgetPredicate(
+ (w) =>
+ w is FlowyTextField &&
+ w.hintText == LocaleKeys.document_inlineLink_url_placeholder.tr(),
+ );
+ await tester.enterText(linkField, link);
+ await tester.pumpAndSettle();
+
+ /// complete inputting
+ await tester.tapButton(find.text(LocaleKeys.button_done.tr()));
+
+ /// do it again
+ /// select the second line
+ await tester.longPress(secondLine);
+ await tester.pumpAndSettle();
+ await tester.tapButton(aaItem);
+ await tester.tapButton(linkButton);
+ await tester.enterText(linkField, link);
+ await tester.pumpAndSettle();
+ await tester.tapButton(find.text(LocaleKeys.button_done.tr()));
+
+ final firstNode = editorState.getNodeAtPath([0]);
+ final secondNode = editorState.getNodeAtPath([1]);
+
+ Map commonDeltaJson(String insert) => {
+ "insert": insert,
+ "attributes": {"href": link},
+ };
+
+ expect(
+ firstNode?.delta?.toJson(),
+ commonDeltaJson(strFirst),
+ );
+ expect(
+ secondNode?.delta?.toJson(),
+ commonDeltaJson(strSecond),
+ );
+ });
+ });
+}