mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-24 22:57:12 -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 'dart:io';
|
||||||
|
|
||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
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/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/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/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/plugins/document/presentation/editor_plugins/link_preview/paste_as/paste_as_menu.dart';
|
||||||
import 'package:appflowy/startup/startup.dart';
|
import 'package:appflowy/startup/startup.dart';
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
|
@ -323,16 +324,12 @@ void main() {
|
||||||
await tester.pasteContent(plainText: url, (editorState) async {
|
await tester.pasteContent(plainText: url, (editorState) async {
|
||||||
final pasteAsMenu = find.byType(PasteAsMenu);
|
final pasteAsMenu = find.byType(PasteAsMenu);
|
||||||
expect(pasteAsMenu, findsOneWidget);
|
expect(pasteAsMenu, findsOneWidget);
|
||||||
final bookmarkButton = find.descendant(
|
final bookmarkButton = find.text(
|
||||||
of: pasteAsMenu,
|
LocaleKeys.document_plugins_linkPreview_typeSelection_bookmark.tr(),
|
||||||
matching: find.text(
|
|
||||||
LocaleKeys.document_plugins_linkPreview_typeSelection_bookmark
|
|
||||||
.tr(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
await tester.tapButton(bookmarkButton);
|
await tester.tapButton(bookmarkButton);
|
||||||
// the second one is the paragraph node
|
// 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])!;
|
final node = editorState.getNodeAtPath([0])!;
|
||||||
expect(node.type, LinkPreviewBlockKeys.type);
|
expect(node.type, LinkPreviewBlockKeys.type);
|
||||||
expect(node.attributes[LinkPreviewBlockKeys.url], url);
|
expect(node.attributes[LinkPreviewBlockKeys.url], url);
|
||||||
|
@ -344,19 +341,19 @@ void main() {
|
||||||
await tester.hoverOnWidget(
|
await tester.hoverOnWidget(
|
||||||
find.byType(CustomLinkPreviewWidget),
|
find.byType(CustomLinkPreviewWidget),
|
||||||
onHover: () async {
|
onHover: () async {
|
||||||
final convertToLinkButton = find.byWidgetPredicate((widget) {
|
/// show menu
|
||||||
return widget is MenuBlockButton &&
|
final menu = find.byType(CustomLinkPreviewMenu);
|
||||||
widget.tooltip ==
|
expect(menu, findsOneWidget);
|
||||||
LocaleKeys.document_plugins_urlPreview_convertToLink.tr();
|
await tester.tapButton(menu);
|
||||||
});
|
|
||||||
|
final convertToLinkButton = find.text(
|
||||||
|
LocaleKeys.document_plugins_linkPreview_linkPreviewMenu_toUrl.tr(),
|
||||||
|
);
|
||||||
expect(convertToLinkButton, findsOneWidget);
|
expect(convertToLinkButton, findsOneWidget);
|
||||||
await tester.tap(convertToLinkButton);
|
await tester.tapButton(convertToLinkButton);
|
||||||
await tester.pumpAndSettle();
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
final editorState = tester.editor.getCurrentEditorState();
|
final editorState = tester.editor.getCurrentEditorState();
|
||||||
final textNode = editorState.getNodeAtPath([0])!;
|
final textNode = editorState.getNodeAtPath([0])!;
|
||||||
expect(textNode.type, ParagraphBlockKeys.type);
|
expect(textNode.type, ParagraphBlockKeys.type);
|
||||||
|
@ -376,22 +373,18 @@ void main() {
|
||||||
await tester.pasteContent(plainText: url, (editorState) async {
|
await tester.pasteContent(plainText: url, (editorState) async {
|
||||||
final pasteAsMenu = find.byType(PasteAsMenu);
|
final pasteAsMenu = find.byType(PasteAsMenu);
|
||||||
expect(pasteAsMenu, findsOneWidget);
|
expect(pasteAsMenu, findsOneWidget);
|
||||||
final bookmarkButton = find.descendant(
|
final bookmarkButton = find.text(
|
||||||
of: pasteAsMenu,
|
LocaleKeys.document_plugins_linkPreview_typeSelection_bookmark.tr(),
|
||||||
matching: find.text(
|
|
||||||
LocaleKeys.document_plugins_linkPreview_typeSelection_bookmark
|
|
||||||
.tr(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
await tester.tapButton(bookmarkButton);
|
await tester.tapButton(bookmarkButton);
|
||||||
// the second one is the paragraph node
|
// 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])!;
|
final node = editorState.getNodeAtPath([0])!;
|
||||||
expect(node.type, LinkPreviewBlockKeys.type);
|
expect(node.type, LinkPreviewBlockKeys.type);
|
||||||
expect(node.attributes[LinkPreviewBlockKeys.url], url);
|
expect(node.attributes[LinkPreviewBlockKeys.url], url);
|
||||||
});
|
});
|
||||||
|
|
||||||
await tester.editor.tapLineOfEditorAt(0);
|
|
||||||
await tester.simulateKeyEvent(
|
await tester.simulateKeyEvent(
|
||||||
LogicalKeyboardKey.keyZ,
|
LogicalKeyboardKey.keyZ,
|
||||||
isControlPressed:
|
isControlPressed:
|
||||||
|
@ -542,7 +535,7 @@ void main() {
|
||||||
|
|
||||||
extension on WidgetTester {
|
extension on WidgetTester {
|
||||||
Future<void> pasteContent(
|
Future<void> pasteContent(
|
||||||
void Function(EditorState editorState) test, {
|
FutureOr<void> Function(EditorState editorState) test, {
|
||||||
Future<void> Function(EditorState editorState)? beforeTest,
|
Future<void> Function(EditorState editorState)? beforeTest,
|
||||||
String? plainText,
|
String? plainText,
|
||||||
String? html,
|
String? html,
|
||||||
|
@ -579,6 +572,6 @@ extension on WidgetTester {
|
||||||
);
|
);
|
||||||
await pumpAndSettle(const Duration(milliseconds: 1000));
|
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 {
|
Future<bool> _isImageUrl(String text) async {
|
||||||
|
if (isNotImageUrl(text)) return false;
|
||||||
final response = await http.head(Uri.parse(text));
|
final response = await http.head(Uri.parse(text));
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
|
|
|
@ -13,3 +13,11 @@ const List<String> defaultImageExtensions = [
|
||||||
'webp',
|
'webp',
|
||||||
'bmp',
|
'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,
|
Brightness brightness,
|
||||||
) {
|
) {
|
||||||
return switch (brightness) {
|
return switch (brightness) {
|
||||||
Brightness.light => AppFlowyFillColorScheme(
|
Brightness.dark => AppFlowyFillColorScheme(
|
||||||
primary: colorScheme.neutral.neutral100,
|
primary: colorScheme.neutral.neutral100,
|
||||||
primaryHover: colorScheme.neutral.neutral200,
|
primaryHover: colorScheme.neutral.neutral200,
|
||||||
secondary: colorScheme.neutral.neutral300,
|
secondary: colorScheme.neutral.neutral300,
|
||||||
|
@ -196,7 +196,7 @@ class AppFlowyThemeBuilder {
|
||||||
purpleThick: colorScheme.purple.purple500,
|
purpleThick: colorScheme.purple.purple500,
|
||||||
purpleThickHover: colorScheme.purple.purple600,
|
purpleThickHover: colorScheme.purple.purple600,
|
||||||
),
|
),
|
||||||
Brightness.dark => AppFlowyFillColorScheme(
|
Brightness.light => AppFlowyFillColorScheme(
|
||||||
primary: colorScheme.neutral.neutral1000,
|
primary: colorScheme.neutral.neutral1000,
|
||||||
primaryHover: colorScheme.neutral.neutral900,
|
primaryHover: colorScheme.neutral.neutral900,
|
||||||
secondary: colorScheme.neutral.neutral600,
|
secondary: colorScheme.neutral.neutral600,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue