mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-24 14:47:13 -04:00
fix: test errors
This commit is contained in:
parent
136e0dbb7d
commit
e21b48b7d3
4 changed files with 31 additions and 29 deletions
|
@ -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<void> pasteContent(
|
||||
void Function(EditorState editorState) test, {
|
||||
FutureOr<void> Function(EditorState editorState) test, {
|
||||
Future<void> 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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -254,6 +254,7 @@ Future<void> doPlainPaste(EditorState editorState) async {
|
|||
}
|
||||
|
||||
Future<bool> _isImageUrl(String text) async {
|
||||
if (isNotImageUrl(text)) return false;
|
||||
final response = await http.head(Uri.parse(text));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
|
|
@ -13,3 +13,11 @@ const List<String> 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);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue