2024-12-31 09:46:13 +08:00
|
|
|
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
|
|
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
2025-04-23 13:40:04 +08:00
|
|
|
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_edit_link_widget.dart';
|
2024-12-31 09:46:13 +08:00
|
|
|
import 'package:appflowy/mobile/presentation/editor/mobile_editor_screen.dart';
|
|
|
|
import 'package:appflowy/mobile/presentation/mobile_bottom_navigation_bar.dart';
|
|
|
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2025-04-23 13:40:04 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2024-12-31 09:46:13 +08:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:integration_test/integration_test.dart';
|
|
|
|
|
|
|
|
import '../../shared/util.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
2025-04-23 13:40:04 +08:00
|
|
|
Future<void> createNeaPage(WidgetTester tester) async {
|
|
|
|
final createPageButton =
|
|
|
|
find.byKey(BottomNavigationBarItemType.add.valueKey);
|
|
|
|
await tester.tapButton(createPageButton);
|
|
|
|
expect(find.byType(MobileDocumentScreen), findsOneWidget);
|
|
|
|
final editor = find.byType(AppFlowyEditor);
|
|
|
|
expect(editor, findsOneWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
const testLink = 'https://appflowy.io/';
|
|
|
|
|
|
|
|
group('links', () {
|
2024-12-31 09:46:13 +08:00
|
|
|
testWidgets('insert links', (tester) async {
|
|
|
|
await tester.launchInAnonymousMode();
|
|
|
|
|
2025-04-23 13:40:04 +08:00
|
|
|
await createNeaPage(tester);
|
|
|
|
await tester.editor.tapLineOfEditorAt(0);
|
2024-12-31 09:46:13 +08:00
|
|
|
final editorState = tester.editor.getCurrentEditorState();
|
|
|
|
|
|
|
|
/// insert two lines of text
|
2025-04-23 13:40:04 +08:00
|
|
|
const strFirst = 'FirstLine', strSecond = 'SecondLine';
|
|
|
|
await tester.ime.insertText(strFirst);
|
2024-12-31 09:46:13 +08:00
|
|
|
await editorState.insertNewLine();
|
2025-04-23 13:40:04 +08:00
|
|
|
await tester.ime.insertText(strSecond);
|
2024-12-31 09:46:13 +08:00
|
|
|
final firstLine = find.text(strFirst, findRichText: true),
|
|
|
|
secondLine = find.text(strSecond, findRichText: true);
|
|
|
|
expect(firstLine, findsOneWidget);
|
|
|
|
expect(secondLine, findsOneWidget);
|
|
|
|
|
|
|
|
/// select the first line
|
2025-04-23 13:40:04 +08:00
|
|
|
await tester.doubleTapAt(tester.getCenter(firstLine));
|
2024-12-31 09:46:13 +08:00
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
|
|
/// find link button and tap it
|
2025-04-23 13:40:04 +08:00
|
|
|
final linkButton = find.byFlowySvg(FlowySvgs.toolbar_link_m);
|
2024-12-31 09:46:13 +08:00
|
|
|
await tester.tapButton(linkButton);
|
|
|
|
|
|
|
|
/// input the link
|
2025-04-23 13:40:04 +08:00
|
|
|
final textFormField = find.byType(TextFormField);
|
|
|
|
expect(textFormField, findsNWidgets(2));
|
|
|
|
final linkField = textFormField.last;
|
|
|
|
await tester.enterText(linkField, testLink);
|
2024-12-31 09:46:13 +08:00
|
|
|
await tester.pumpAndSettle();
|
2025-04-23 13:40:04 +08:00
|
|
|
await tester.tapButton(find.byFlowySvg(FlowySvgs.toolbar_link_earth_m));
|
2024-12-31 09:46:13 +08:00
|
|
|
|
2025-04-23 13:40:04 +08:00
|
|
|
/// apply the link
|
2024-12-31 09:46:13 +08:00
|
|
|
await tester.tapButton(find.text(LocaleKeys.button_done.tr()));
|
|
|
|
|
|
|
|
/// do it again
|
|
|
|
/// select the second line
|
2025-04-23 13:40:04 +08:00
|
|
|
await tester.doubleTapAt(tester.getCenter(secondLine));
|
2024-12-31 09:46:13 +08:00
|
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tapButton(linkButton);
|
2025-04-23 13:40:04 +08:00
|
|
|
await tester.enterText(linkField, testLink);
|
2024-12-31 09:46:13 +08:00
|
|
|
await tester.pumpAndSettle();
|
2025-04-23 13:40:04 +08:00
|
|
|
await tester.tapButton(find.byFlowySvg(FlowySvgs.toolbar_link_earth_m));
|
2024-12-31 09:46:13 +08:00
|
|
|
await tester.tapButton(find.text(LocaleKeys.button_done.tr()));
|
|
|
|
|
|
|
|
final firstNode = editorState.getNodeAtPath([0]);
|
|
|
|
final secondNode = editorState.getNodeAtPath([1]);
|
|
|
|
|
|
|
|
Map commonDeltaJson(String insert) => {
|
2025-04-23 13:40:04 +08:00
|
|
|
'insert': insert,
|
|
|
|
'attributes': {'href': testLink, 'is_page_link': false},
|
2024-12-31 09:46:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(
|
|
|
|
firstNode?.delta?.toJson(),
|
2025-04-23 13:40:04 +08:00
|
|
|
[commonDeltaJson(strFirst)],
|
2024-12-31 09:46:13 +08:00
|
|
|
);
|
|
|
|
expect(
|
|
|
|
secondNode?.delta?.toJson(),
|
2025-04-23 13:40:04 +08:00
|
|
|
[commonDeltaJson(strSecond)],
|
2024-12-31 09:46:13 +08:00
|
|
|
);
|
|
|
|
});
|
2025-04-23 13:40:04 +08:00
|
|
|
|
|
|
|
testWidgets('change a link', (tester) async {
|
|
|
|
await tester.launchInAnonymousMode();
|
|
|
|
|
|
|
|
await createNeaPage(tester);
|
|
|
|
await tester.editor.tapLineOfEditorAt(0);
|
|
|
|
final editorState = tester.editor.getCurrentEditorState();
|
|
|
|
const testText = 'TestText';
|
|
|
|
await tester.ime.insertText(testText);
|
|
|
|
final textFinder = find.text(testText, findRichText: true);
|
|
|
|
|
|
|
|
/// select the first line
|
|
|
|
await tester.doubleTapAt(tester.getCenter(textFinder));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
|
|
/// find link button and tap it
|
|
|
|
final linkButton = find.byFlowySvg(FlowySvgs.toolbar_link_m);
|
|
|
|
await tester.tapButton(linkButton);
|
|
|
|
|
|
|
|
/// input the link
|
|
|
|
final textFormField = find.byType(TextFormField);
|
|
|
|
expect(textFormField, findsNWidgets(2));
|
|
|
|
final linkField = textFormField.last;
|
|
|
|
await tester.enterText(linkField, testLink);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tapButton(find.byFlowySvg(FlowySvgs.toolbar_link_earth_m));
|
|
|
|
|
|
|
|
/// apply the link
|
|
|
|
await tester.tapButton(find.text(LocaleKeys.button_done.tr()));
|
|
|
|
|
|
|
|
/// show edit link menu
|
|
|
|
await tester.longPress(textFinder);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
final linkEditMenu = find.byType(MobileBottomSheetEditLinkWidget);
|
|
|
|
expect(linkEditMenu, findsOneWidget);
|
|
|
|
|
|
|
|
/// remove the link
|
|
|
|
await tester.tapButton(find.byFlowySvg(FlowySvgs.toolbar_link_unlink_m));
|
|
|
|
final node = editorState.getNodeAtPath([0]);
|
|
|
|
expect(node?.delta?.toJson(), [{'insert': testText}]);
|
|
|
|
});
|
2024-12-31 09:46:13 +08:00
|
|
|
});
|
|
|
|
}
|