From 6ea3ea189e473337e86c454abd6c4d016ca1b38b Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Tue, 4 Oct 2022 11:37:40 -0500 Subject: [PATCH 01/14] chore: remove unused imports --- .../example/lib/plugin/code_block_node_widget.dart | 2 +- .../src/render/rich_text/built_in_text_widget.dart | 1 - .../backspace_handler.dart | 1 - .../copy_paste_handler.dart | 1 - .../enter_without_shift_in_text_node_handler.dart | 1 - .../markdown_syntax_to_styled_text.dart | 3 +-- .../test/extensions/path_extensions_test.dart | 1 - .../test/render/rich_text/checkbox_text_test.dart | 2 -- .../render/rich_text/toolbar_rich_text_test.dart | 1 - .../selection_menu/selection_menu_widget_test.dart | 12 ++++++------ .../backspace_handler_test.dart | 1 - .../format_style_handler_test.dart | 1 - .../slash_handler_test.dart | 1 - .../white_space_handler_test.dart | 1 - .../test/service/toolbar_service_test.dart | 1 - 15 files changed, 8 insertions(+), 22 deletions(-) diff --git a/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/code_block_node_widget.dart b/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/code_block_node_widget.dart index 3949073756..8f80990fc4 100644 --- a/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/code_block_node_widget.dart +++ b/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/code_block_node_widget.dart @@ -45,7 +45,7 @@ ShortcutEventHandler _ignorekHandler = (editorState, event) { }; SelectionMenuItem codeBlockItem = SelectionMenuItem( - name: 'Code Block', + name: () => 'Code Block', icon: const Icon(Icons.abc), keywords: ['code block'], handler: (editorState, _, __) { diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/built_in_text_widget.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/built_in_text_widget.dart index f2c8693f87..a0a65d9583 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/built_in_text_widget.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/built_in_text_widget.dart @@ -1,5 +1,4 @@ import 'package:appflowy_editor/appflowy_editor.dart'; -import 'package:appflowy_editor/src/render/rich_text/default_selectable.dart'; import 'package:flutter/material.dart'; abstract class BuiltInTextWidget extends StatefulWidget { diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/backspace_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/backspace_handler.dart index 3f7a54810f..c9956635ba 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/backspace_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/backspace_handler.dart @@ -3,7 +3,6 @@ import 'package:appflowy_editor/src/service/internal_key_event_handlers/number_l import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:appflowy_editor/appflowy_editor.dart'; -import 'package:appflowy_editor/src/extensions/path_extensions.dart'; // Handle delete text. ShortcutEventHandler deleteTextHandler = (editorState, event) { diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart index e48ec3426d..916ffe317e 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart @@ -1,7 +1,6 @@ import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/infra/html_converter.dart'; import 'package:appflowy_editor/src/document/node_iterator.dart'; -import 'package:appflowy_editor/src/document/built_in_attribute_keys.dart'; import 'package:appflowy_editor/src/service/internal_key_event_handlers/number_list_helper.dart'; import 'package:flutter/material.dart'; import 'package:rich_clipboard/rich_clipboard.dart'; diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart index c31b8c3699..2a2d1deedb 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart @@ -3,7 +3,6 @@ import 'dart:collection'; import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/material.dart'; -import 'package:appflowy_editor/src/extensions/path_extensions.dart'; import './number_list_helper.dart'; /// Handle some cases where enter is pressed and shift is not pressed. diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/markdown_syntax_to_styled_text.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/markdown_syntax_to_styled_text.dart index 4b74145ec0..c46b2322c7 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/markdown_syntax_to_styled_text.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/markdown_syntax_to_styled_text.dart @@ -1,4 +1,3 @@ -import "dart:math"; import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/extensions/text_node_extensions.dart'; import 'package:appflowy_editor/src/service/default_text_operations/format_rich_text_style.dart'; @@ -49,7 +48,7 @@ ShortcutEventHandler backquoteToCodeHandler = (editorState, event) { .substring(selection.start.offset, selection.end.offset); // toggle code style when selected some text - if (selectionText.length > 0) { + if (selectionText.isNotEmpty) { formatEmbedCode(editorState); return KeyEventResult.handled; } diff --git a/frontend/app_flowy/packages/appflowy_editor/test/extensions/path_extensions_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/extensions/path_extensions_test.dart index c39c0d0e56..5d84690641 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/extensions/path_extensions_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/extensions/path_extensions_test.dart @@ -1,6 +1,5 @@ import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:appflowy_editor/src/extensions/path_extensions.dart'; void main() async { setUpAll(() { diff --git a/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/checkbox_text_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/checkbox_text_test.dart index 96cdbbce65..29dfbba136 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/checkbox_text_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/checkbox_text_test.dart @@ -1,6 +1,4 @@ import 'package:appflowy_editor/appflowy_editor.dart'; -import 'package:appflowy_editor/src/document/built_in_attribute_keys.dart'; -import 'package:appflowy_editor/src/render/rich_text/default_selectable.dart'; import 'package:appflowy_editor/src/extensions/text_node_extensions.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../infra/test_editor.dart'; diff --git a/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/toolbar_rich_text_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/toolbar_rich_text_test.dart index 9e8a5c15c9..c9d9ef9e70 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/toolbar_rich_text_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/toolbar_rich_text_test.dart @@ -1,5 +1,4 @@ import 'package:appflowy_editor/appflowy_editor.dart'; -import 'package:appflowy_editor/src/document/built_in_attribute_keys.dart'; import 'package:appflowy_editor/src/extensions/text_node_extensions.dart'; import 'package:appflowy_editor/src/render/toolbar/toolbar_item_widget.dart'; import 'package:appflowy_editor/src/render/toolbar/toolbar_widget.dart'; diff --git a/frontend/app_flowy/packages/appflowy_editor/test/render/selection_menu/selection_menu_widget_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/render/selection_menu/selection_menu_widget_test.dart index 1495105746..2076daefc1 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/render/selection_menu/selection_menu_widget_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/render/selection_menu/selection_menu_widget_test.dart @@ -1,7 +1,6 @@ import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/render/selection_menu/selection_menu_item_widget.dart'; import 'package:appflowy_editor/src/render/selection_menu/selection_menu_service.dart'; -import 'package:appflowy_editor/src/render/selection_menu/selection_menu_widget.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../infra/test_editor.dart'; @@ -13,8 +12,8 @@ void main() async { group('selection_menu_widget.dart', () { for (var i = 0; i < defaultSelectionMenuItems.length; i += 1) { - testWidgets('Selects number.$i item in selection menu with enter', ( - tester) async { + testWidgets('Selects number.$i item in selection menu with enter', + (tester) async { final editor = await _prepare(tester); for (var j = 0; j < i; j++) { await editor.pressLogicKey(LogicalKeyboardKey.arrowDown); @@ -30,8 +29,8 @@ void main() async { } }); - testWidgets('Selects number.$i item in selection menu with click', ( - tester) async { + testWidgets('Selects number.$i item in selection menu with click', + (tester) async { final editor = await _prepare(tester); await tester.tap(find.byType(SelectionMenuItemWidget).at(i)); @@ -148,7 +147,8 @@ Future _testDefaultSelectionMenuItems( int index, EditorWidgetTester editor) async { expect(editor.documentLength, 4); expect(editor.documentSelection, Selection.single(path: [2], startOffset: 0)); - expect((editor.nodeAtPath([1]) as TextNode).toRawString(), 'Welcome to Appflowy 😁'); + expect((editor.nodeAtPath([1]) as TextNode).toRawString(), + 'Welcome to Appflowy 😁'); final node = editor.nodeAtPath([2]); final item = defaultSelectionMenuItems[index]; final itemName = item.name(); diff --git a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/backspace_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/backspace_handler_test.dart index 37ad7bade3..1e423c39e0 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/backspace_handler_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/backspace_handler_test.dart @@ -2,7 +2,6 @@ import 'dart:collection'; import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/render/image/image_node_widget.dart'; -import 'package:appflowy_editor/src/render/rich_text/flowy_rich_text.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:network_image_mock/network_image_mock.dart'; diff --git a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/format_style_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/format_style_handler_test.dart index 7240c186f3..0cb4c71600 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/format_style_handler_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/format_style_handler_test.dart @@ -8,7 +8,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../infra/test_editor.dart'; -import 'package:appflowy_editor/src/document/built_in_attribute_keys.dart'; void main() async { setUpAll(() { diff --git a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/slash_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/slash_handler_test.dart index 4d5492e620..b3166a46fb 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/slash_handler_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/slash_handler_test.dart @@ -1,7 +1,6 @@ import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/render/selection_menu/selection_menu_item_widget.dart'; import 'package:appflowy_editor/src/render/selection_menu/selection_menu_service.dart'; -import 'package:appflowy_editor/src/render/selection_menu/selection_menu_widget.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../infra/test_editor.dart'; diff --git a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/white_space_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/white_space_handler_test.dart index fd7707a5f5..c0948a93c5 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/white_space_handler_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/white_space_handler_test.dart @@ -3,7 +3,6 @@ import 'package:appflowy_editor/src/service/internal_key_event_handlers/whitespa import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../infra/test_editor.dart'; -import 'package:appflowy_editor/src/document/built_in_attribute_keys.dart'; void main() async { setUpAll(() { diff --git a/frontend/app_flowy/packages/appflowy_editor/test/service/toolbar_service_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/toolbar_service_test.dart index 5b82a5dea9..1e8f2f1f07 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/service/toolbar_service_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/toolbar_service_test.dart @@ -4,7 +4,6 @@ import 'package:appflowy_editor/src/render/toolbar/toolbar_item_widget.dart'; import 'package:appflowy_editor/src/render/toolbar/toolbar_widget.dart'; import 'package:flutter_test/flutter_test.dart'; import '../infra/test_editor.dart'; -import 'package:appflowy_editor/src/document/built_in_attribute_keys.dart'; void main() async { setUpAll(() { From bf9f6ac13f75a80a061fd93f2d5d4f465cd41b61 Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Tue, 4 Oct 2022 11:37:59 -0500 Subject: [PATCH 02/14] chore: small code improvements --- .../lib/src/extensions/attributes_extension.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/attributes_extension.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/attributes_extension.dart index c80753b217..b8970d8225 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/attributes_extension.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/attributes_extension.dart @@ -17,9 +17,9 @@ extension NodeAttributesExtensions on Attributes { return containsKey(BuiltInAttributeKey.quote); } - int? get number { + num? get number { if (containsKey(BuiltInAttributeKey.number) && - this[BuiltInAttributeKey.number] is int) { + this[BuiltInAttributeKey.number] is num) { return this[BuiltInAttributeKey.number]; } return null; @@ -27,7 +27,7 @@ extension NodeAttributesExtensions on Attributes { bool get code { if (containsKey(BuiltInAttributeKey.code) && - this[BuiltInAttributeKey.code] == true) { + this[BuiltInAttributeKey.code] is bool) { return this[BuiltInAttributeKey.code]; } return false; @@ -63,11 +63,14 @@ extension DeltaAttributesExtensions on Attributes { this[BuiltInAttributeKey.strikethrough] == true); } + static const whiteInt = 0XFFFFFFFF; + Color? get color { if (containsKey(BuiltInAttributeKey.color) && this[BuiltInAttributeKey.color] is String) { return Color( - int.parse(this[BuiltInAttributeKey.color]), + // If the parse fails returns white by default + int.tryParse(this[BuiltInAttributeKey.color]) ?? whiteInt, ); } return null; @@ -77,8 +80,7 @@ extension DeltaAttributesExtensions on Attributes { if (containsKey(BuiltInAttributeKey.backgroundColor) && this[BuiltInAttributeKey.backgroundColor] is String) { return Color( - int.parse(this[BuiltInAttributeKey.backgroundColor]), - ); + int.tryParse(this[BuiltInAttributeKey.backgroundColor]) ?? whiteInt); } return null; } From dd15a49d765b0725cd15330777f21604429c201b Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Tue, 4 Oct 2022 11:38:34 -0500 Subject: [PATCH 03/14] test: add unit tests for attributes extensions --- .../extensions/attributes_extension_test.dart | 201 ++++++++++++++++++ frontend/app_flowy/pubspec.lock | 2 +- 2 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 frontend/app_flowy/packages/appflowy_editor/test/extensions/attributes_extension_test.dart diff --git a/frontend/app_flowy/packages/appflowy_editor/test/extensions/attributes_extension_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/extensions/attributes_extension_test.dart new file mode 100644 index 0000000000..427e53f32a --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/test/extensions/attributes_extension_test.dart @@ -0,0 +1,201 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('NodeAttributesExtensions::', () { + test('heading', () { + final Attributes attribute = { + 'subtype': 'heading', + 'heading': 'AppFlowy', + }; + expect(attribute.heading, 'AppFlowy'); + }); + + test('heading - text is not String return null', () { + final Attributes attribute = { + 'subtype': 'heading', + 'heading': 123, + }; + expect(attribute.heading, null); + }); + + test('heading - subtype is not "heading" return null', () { + final Attributes attribute = { + 'subtype': 'code', + 'heading': 'Hello World!', + }; + expect(attribute.heading, null); + }); + + test('quote', () { + final Attributes attribute = { + 'quote': 'quote text', + }; + expect(attribute.quote, true); + }); + + test('number - int', () { + final Attributes attribute = { + 'number': 99, + }; + expect(attribute.number, 99); + }); + + test('number - double', () { + final Attributes attribute = { + 'number': 12.34, + }; + expect(attribute.number, 12.34); + }); + + test('number - return null', () { + final Attributes attribute = { + 'code': 12.34, + }; + expect(attribute.number, null); + }); + + test('code', () { + final Attributes attribute = { + 'code': true, + }; + expect(attribute.code, true); + }); + + test('code - return false', () { + final Attributes attribute = { + 'quote': true, + }; + expect(attribute.code, false); + }); + + test('check', () { + final Attributes attribute = { + 'checkbox': true, + }; + expect(attribute.check, true); + }); + + test('check - return false', () { + final Attributes attribute = { + 'quote': true, + }; + expect(attribute.check, false); + }); + }); + + group('DeltaAttributesExtensions::', () { + test('bold', () { + final Attributes attribute = { + 'bold': true, + }; + expect(attribute.bold, true); + }); + + test('bold - return false', () { + final Attributes attribute = { + 'bold': 123, + }; + expect(attribute.bold, false); + }); + + test('italic', () { + final Attributes attribute = { + 'italic': true, + }; + expect(attribute.italic, true); + }); + + test('italic - return false', () { + final Attributes attribute = { + 'italic': 123, + }; + expect(attribute.italic, false); + }); + + test('underline', () { + final Attributes attribute = { + 'underline': true, + }; + expect(attribute.underline, true); + }); + + test('underline - return false', () { + final Attributes attribute = { + 'underline': 123, + }; + expect(attribute.underline, false); + }); + + test('strikethrough', () { + final Attributes attribute = { + 'strikethrough': true, + }; + expect(attribute.strikethrough, true); + }); + + test('strikethrough - return false', () { + final Attributes attribute = { + 'strikethrough': 123, + }; + expect(attribute.strikethrough, false); + }); + + test('color', () { + final Attributes attribute = { + 'color': '0xff212fff', + }; + expect(attribute.color, const Color(0XFF212FFF)); + }); + + test('color - return null', () { + final Attributes attribute = { + 'color': 123, + }; + expect(attribute.color, null); + }); + + test('color - parse failure return white', () { + final Attributes attribute = { + 'color': 'hello123', + }; + expect(attribute.color, const Color(0XFFFFFFFF)); + }); + + test('backgroundColor', () { + final Attributes attribute = { + 'backgroundColor': '0xff678fff', + }; + expect(attribute.backgroundColor, const Color(0XFF678FFF)); + }); + + test('backgroundColor - return null', () { + final Attributes attribute = { + 'backgroundColor': 123, + }; + expect(attribute.backgroundColor, null); + }); + + test('backgroundColor - parse failure return white', () { + final Attributes attribute = { + 'backgroundColor': 'hello123', + }; + expect(attribute.backgroundColor, const Color(0XFFFFFFFF)); + }); + + test('href', () { + final Attributes attribute = { + 'href': '/app/flowy', + }; + expect(attribute.href, '/app/flowy'); + }); + + test('href - return null', () { + final Attributes attribute = { + 'href': 123, + }; + expect(attribute.href, null); + }); + }); +} diff --git a/frontend/app_flowy/pubspec.lock b/frontend/app_flowy/pubspec.lock index a042baadd7..eaa1ad4900 100644 --- a/frontend/app_flowy/pubspec.lock +++ b/frontend/app_flowy/pubspec.lock @@ -28,7 +28,7 @@ packages: path: "packages/appflowy_board" relative: true source: path - version: "0.0.7" + version: "0.0.8" appflowy_editor: dependency: "direct main" description: From 791494961315e302fe39d2bdddf9c3e9492ec0c3 Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Tue, 4 Oct 2022 17:59:20 -0500 Subject: [PATCH 04/14] test: color tests --- .../test/extensions/color_extension_test.dart | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 frontend/app_flowy/packages/appflowy_editor/test/extensions/color_extension_test.dart diff --git a/frontend/app_flowy/packages/appflowy_editor/test/extensions/color_extension_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/extensions/color_extension_test.dart new file mode 100644 index 0000000000..929a5c0378 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/test/extensions/color_extension_test.dart @@ -0,0 +1,40 @@ +import 'package:appflowy_editor/src/extensions/color_extension.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('ColorExtension::', () { + const white = Color(0XFFFFFFFF); + const black = Color(0XFF000000); + const blue = Color(0XFF000FFF); + const blueRgba = 'rgba(0, 15, 255, 255)'; + test('ToRgbaString', () { + expect(blue.toRgbaString(), 'rgba(0, 15, 255, 255)'); + expect(white.toRgbaString(), 'rgba(255, 255, 255, 255)'); + expect(black.toRgbaString(), 'rgba(0, 0, 0, 255)'); + }); + + test('tryFromRgbaString', () { + final color = ColorExtension.tryFromRgbaString(blueRgba); + expect(color, const Color.fromARGB(255, 0, 15, 255)); + }); + + test('tryFromRgbaString - wrong rgba format return null', () { + const wrongRgba = 'abc(1,2,3,4)'; + final color = ColorExtension.tryFromRgbaString(wrongRgba); + expect(color, null); + }); + + test('tryFromRgbaString - wrong length return null', () { + const wrongRgba = 'rgba(0, 15, 255)'; + final color = ColorExtension.tryFromRgbaString(wrongRgba); + expect(color, null); + }); + + test('tryFromRgbaString - wrong values return null', () { + const wrongRgba = 'rgba(-12, 999, 1234, 619)'; + final color = ColorExtension.tryFromRgbaString(wrongRgba); + expect(color, null); + }); + }); +} From 50ebaa3ab8fef7a696230fa6849761e34fc9169f Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Tue, 4 Oct 2022 17:59:30 -0500 Subject: [PATCH 05/14] test: object tests --- .../extensions/object_extension_test.dart | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 frontend/app_flowy/packages/appflowy_editor/test/extensions/object_extension_test.dart diff --git a/frontend/app_flowy/packages/appflowy_editor/test/extensions/object_extension_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/extensions/object_extension_test.dart new file mode 100644 index 0000000000..151df9cc31 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/test/extensions/object_extension_test.dart @@ -0,0 +1,20 @@ +import 'dart:io'; + +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:appflowy_editor/src/extensions/object_extensions.dart'; + +void main() { + group('FlowyObjectExtensions::', () { + test('unwrapOrNull', () { + final result = const TextSpan().unwrapOrNull(); + assert(result is TextSpan); + }); + + test('unwrapOrNull - return null', () { + final result = const TextSpan().unwrapOrNull(); + expect(result, null); + }); + }); +} From c0aa90b0b3058a023cecf22aa5638f3fc9b88c53 Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Tue, 4 Oct 2022 22:19:38 -0500 Subject: [PATCH 06/14] test: text style tests --- .../extensions/text_style_extension_test.dart | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 frontend/app_flowy/packages/appflowy_editor/test/extensions/text_style_extension_test.dart diff --git a/frontend/app_flowy/packages/appflowy_editor/test/extensions/text_style_extension_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/extensions/text_style_extension_test.dart new file mode 100644 index 0000000000..572178d0f3 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/test/extensions/text_style_extension_test.dart @@ -0,0 +1,43 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:appflowy_editor/src/extensions/text_style_extension.dart'; + +void main() { + group('TextStyleExtensions::', () { + const style = TextStyle( + color: Colors.blue, + backgroundColor: Colors.white, + fontSize: 14, + height: 100, + wordSpacing: 2, + fontWeight: FontWeight.w700, + ); + + const otherStyle = TextStyle( + color: Colors.red, + backgroundColor: Colors.black, + fontSize: 12, + height: 10, + wordSpacing: 1, + ); + test('combine', () { + final result = style.combine(otherStyle); + expect(result.color, Colors.red); + expect(result.backgroundColor, Colors.black); + expect(result.fontSize, 12); + expect(result.height, 10); + expect(result.wordSpacing, 1); + }); + + test('combine - return this', () { + final result = style.combine(null); + expect(result, style); + }); + + test('combine - return null with inherit', () { + final styleCopy = otherStyle.copyWith(inherit: false); + final result = style.combine(styleCopy); + expect(result, styleCopy); + }); + }); +} From 4acce447f24f808a8c4502a10fb078e3193e27bd Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Tue, 4 Oct 2022 22:39:55 -0500 Subject: [PATCH 07/14] test: add node extension test --- .../test/extensions/node_extension_test.dart | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 frontend/app_flowy/packages/appflowy_editor/test/extensions/node_extension_test.dart diff --git a/frontend/app_flowy/packages/appflowy_editor/test/extensions/node_extension_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/extensions/node_extension_test.dart new file mode 100644 index 0000000000..7b0d106582 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/test/extensions/node_extension_test.dart @@ -0,0 +1,31 @@ +import 'dart:ui'; + +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:appflowy_editor/src/extensions/node_extensions.dart'; + +class MockNode extends Mock implements Node {} + +void main() { + group('NodeExtensions::', () { + final mockNode = MockNode(); + + final selection = Selection( + start: Position(path: [0, 1]), + end: Position(path: [1, 0]), + ); + + test('rect - renderBox is null', () { + when(mockNode.renderBox).thenReturn(null); + final result = mockNode.rect; + expect(result, Rect.zero); + }); + + // test('inSelection', () { + // when(mockNode.path).thenAnswer((_) => [3, 3]); + // final result = mockNode.inSelection(selection); + // expect(result, true); + // }); + }); +} From b4aceec346a4bb544cf1a6e792bcd79df4481311 Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Tue, 4 Oct 2022 22:40:07 -0500 Subject: [PATCH 08/14] test: add mockito --- frontend/app_flowy/packages/appflowy_editor/pubspec.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/app_flowy/packages/appflowy_editor/pubspec.yaml b/frontend/app_flowy/packages/appflowy_editor/pubspec.yaml index 76ec0b758d..b41f9243c0 100644 --- a/frontend/app_flowy/packages/appflowy_editor/pubspec.yaml +++ b/frontend/app_flowy/packages/appflowy_editor/pubspec.yaml @@ -32,6 +32,7 @@ dev_dependencies: sdk: flutter flutter_lints: ^2.0.1 network_image_mock: ^2.1.1 + mockito: ^5.3.2 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec From fe524736ec51c8b29ea28180288968b3978643f4 Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Tue, 4 Oct 2022 22:40:15 -0500 Subject: [PATCH 09/14] test: add url launcher test --- .../url_launcher_extension_test.dart | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 frontend/app_flowy/packages/appflowy_editor/test/extensions/url_launcher_extension_test.dart diff --git a/frontend/app_flowy/packages/appflowy_editor/test/extensions/url_launcher_extension_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/extensions/url_launcher_extension_test.dart new file mode 100644 index 0000000000..7c8761e5a9 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/test/extensions/url_launcher_extension_test.dart @@ -0,0 +1,22 @@ +import 'package:appflowy_editor/src/extensions/url_launcher_extension.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + // test('safeLaunchUrl with scheme', () async { + // const href = 'https://github.com/AppFlowy-IO'; + // final result = await safeLaunchUrl(href); + // expect(result, true); + // }); + + // test('safeLaunchUrl without scheme', () async { + // const href = 'github.com/AppFlowy-IO'; + // final result = await safeLaunchUrl(href); + // expect(result, true); + // }); + + test('safeLaunchUrl without scheme', () async { + const href = null; + final result = await safeLaunchUrl(href); + expect(result, false); + }); +} From eaf396630cb71649af81fdba4b8c30443c8adda8 Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Wed, 5 Oct 2022 23:06:48 -0500 Subject: [PATCH 10/14] chore: url launcher test --- .../test/extensions/url_launcher_extension_test.dart | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/frontend/app_flowy/packages/appflowy_editor/test/extensions/url_launcher_extension_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/extensions/url_launcher_extension_test.dart index 7c8761e5a9..81b5b51e37 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/extensions/url_launcher_extension_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/extensions/url_launcher_extension_test.dart @@ -2,18 +2,6 @@ import 'package:appflowy_editor/src/extensions/url_launcher_extension.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { - // test('safeLaunchUrl with scheme', () async { - // const href = 'https://github.com/AppFlowy-IO'; - // final result = await safeLaunchUrl(href); - // expect(result, true); - // }); - - // test('safeLaunchUrl without scheme', () async { - // const href = 'github.com/AppFlowy-IO'; - // final result = await safeLaunchUrl(href); - // expect(result, true); - // }); - test('safeLaunchUrl without scheme', () async { const href = null; final result = await safeLaunchUrl(href); From bfe61ea09d6a573c3ce1e7bcb2562269a389e2a2 Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Wed, 5 Oct 2022 23:46:34 -0500 Subject: [PATCH 11/14] test: node tests --- .../test/extensions/node_extension_test.dart | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/frontend/app_flowy/packages/appflowy_editor/test/extensions/node_extension_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/extensions/node_extension_test.dart index 7b0d106582..0e31aa5a96 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/extensions/node_extension_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/extensions/node_extension_test.dart @@ -1,3 +1,4 @@ +import 'dart:collection'; import 'dart:ui'; import 'package:appflowy_editor/appflowy_editor.dart'; @@ -8,12 +9,12 @@ import 'package:appflowy_editor/src/extensions/node_extensions.dart'; class MockNode extends Mock implements Node {} void main() { - group('NodeExtensions::', () { - final mockNode = MockNode(); + final mockNode = MockNode(); + group('NodeExtensions::', () { final selection = Selection( - start: Position(path: [0, 1]), - end: Position(path: [1, 0]), + start: Position(path: [0]), + end: Position(path: [1]), ); test('rect - renderBox is null', () { @@ -22,10 +23,35 @@ void main() { expect(result, Rect.zero); }); - // test('inSelection', () { - // when(mockNode.path).thenAnswer((_) => [3, 3]); - // final result = mockNode.inSelection(selection); - // expect(result, true); - // }); + test('inSelection', () { + // I use an empty implementation instead of mock, because the mocked + // version throws error trying to access the path. + + final subLinkedList = LinkedList() + ..addAll([ + Node(type: 'type', children: LinkedList(), attributes: {}), + Node(type: 'type', children: LinkedList(), attributes: {}), + Node(type: 'type', children: LinkedList(), attributes: {}), + Node(type: 'type', children: LinkedList(), attributes: {}), + Node(type: 'type', children: LinkedList(), attributes: {}), + ]); + + final linkedList = LinkedList() + ..addAll([ + Node( + type: 'type', + children: subLinkedList, + attributes: {}, + ), + ]); + + final node = Node( + type: 'type', + children: linkedList, + attributes: {}, + ); + final result = node.inSelection(selection); + expect(result, false); + }); }); } From 90ac7970bd67f0cd9d5e6622da5533ec8b2dff18 Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Wed, 5 Oct 2022 23:49:41 -0500 Subject: [PATCH 12/14] chore: remove dynamic methods --- .../src/extensions/text_node_extensions.dart | 30 +++++++++-------- .../lib/src/render/toolbar/toolbar_item.dart | 32 ++++++++++--------- .../format_rich_text_style.dart | 2 +- .../extensions/text_node_extensions_test.dart | 10 ++++++ .../rich_text/toolbar_rich_text_test.dart | 4 +-- .../format_style_handler_test.dart | 10 +++--- 6 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 frontend/app_flowy/packages/appflowy_editor/test/extensions/text_node_extensions_test.dart diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/text_node_extensions.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/text_node_extensions.dart index d4d7857286..4d8c44b9fa 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/text_node_extensions.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/text_node_extensions.dart @@ -6,7 +6,7 @@ import 'package:appflowy_editor/src/document/text_delta.dart'; import 'package:appflowy_editor/src/document/built_in_attribute_keys.dart'; extension TextNodeExtension on TextNode { - dynamic getAttributeInSelection(Selection selection, String styleKey) { + T? getAttributeInSelection(Selection selection, String styleKey) { final ops = delta.whereType(); final startOffset = selection.isBackward ? selection.start.offset : selection.end.offset; @@ -29,40 +29,42 @@ extension TextNodeExtension on TextNode { } bool allSatisfyLinkInSelection(Selection selection) => - allSatisfyInSelection(selection, BuiltInAttributeKey.href, (value) { + allSatisfyInSelection(selection, BuiltInAttributeKey.href, (value) { return value != null; }); bool allSatisfyBoldInSelection(Selection selection) => - allSatisfyInSelection(selection, BuiltInAttributeKey.bold, (value) { + allSatisfyInSelection(selection, BuiltInAttributeKey.bold, (value) { return value == true; }); bool allSatisfyItalicInSelection(Selection selection) => - allSatisfyInSelection(selection, BuiltInAttributeKey.italic, (value) { + allSatisfyInSelection(selection, BuiltInAttributeKey.italic, + (value) { return value == true; }); bool allSatisfyUnderlineInSelection(Selection selection) => - allSatisfyInSelection(selection, BuiltInAttributeKey.underline, (value) { + allSatisfyInSelection(selection, BuiltInAttributeKey.underline, + (value) { return value == true; }); bool allSatisfyStrikethroughInSelection(Selection selection) => allSatisfyInSelection(selection, BuiltInAttributeKey.strikethrough, - (value) { + (value) { return value == true; }); bool allSatisfyCodeInSelection(Selection selection) => - allSatisfyInSelection(selection, BuiltInAttributeKey.code, (value) { + allSatisfyInSelection(selection, BuiltInAttributeKey.code, (value) { return value == true; }); bool allSatisfyInSelection( Selection selection, String styleKey, - bool Function(dynamic value) test, + bool Function(T value) test, ) { if (BuiltInAttributeKey.globalStyleKeys.contains(styleKey)) { if (attributes.containsKey(styleKey)) { @@ -127,40 +129,40 @@ extension TextNodesExtension on List { bool allSatisfyBoldInSelection(Selection selection) => allSatisfyInSelection( selection, BuiltInAttributeKey.bold, - (value) => value == true, + (value) => value == true, ); bool allSatisfyItalicInSelection(Selection selection) => allSatisfyInSelection( selection, BuiltInAttributeKey.italic, - (value) => value == true, + (value) => value == true, ); bool allSatisfyUnderlineInSelection(Selection selection) => allSatisfyInSelection( selection, BuiltInAttributeKey.underline, - (value) => value == true, + (value) => value == true, ); bool allSatisfyStrikethroughInSelection(Selection selection) => allSatisfyInSelection( selection, BuiltInAttributeKey.strikethrough, - (value) => value == true, + (value) => value == true, ); bool allSatisfyInSelection( Selection selection, String styleKey, - bool Function(dynamic value) test, + bool Function(T value) test, ) { if (isEmpty) { return false; } if (length == 1) { - return first.allSatisfyInSelection(selection, styleKey, (value) { + return first.allSatisfyInSelection(selection, styleKey, (value) { return test(value); }); } else { diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/render/toolbar/toolbar_item.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/toolbar/toolbar_item.dart index 6407f81cb3..1b531f306b 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/render/toolbar/toolbar_item.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/toolbar/toolbar_item.dart @@ -73,7 +73,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.heading, - (value) => value == BuiltInAttributeKey.h1, + (value) => value == BuiltInAttributeKey.h1, ), handler: (editorState, context) => formatHeading(editorState, BuiltInAttributeKey.h1), @@ -90,7 +90,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.heading, - (value) => value == BuiltInAttributeKey.h2, + (value) => value == BuiltInAttributeKey.h2, ), handler: (editorState, context) => formatHeading(editorState, BuiltInAttributeKey.h2), @@ -107,7 +107,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.heading, - (value) => value == BuiltInAttributeKey.h3, + (value) => value == BuiltInAttributeKey.h3, ), handler: (editorState, context) => formatHeading(editorState, BuiltInAttributeKey.h3), @@ -124,7 +124,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.bold, - (value) => value == true, + (value) => value == true, ), handler: (editorState, context) => formatBold(editorState), ), @@ -140,7 +140,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.italic, - (value) => value == true, + (value) => value == true, ), handler: (editorState, context) => formatItalic(editorState), ), @@ -156,7 +156,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.underline, - (value) => value == true, + (value) => value == true, ), handler: (editorState, context) => formatUnderline(editorState), ), @@ -172,7 +172,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.strikethrough, - (value) => value == true, + (value) => value == true, ), handler: (editorState, context) => formatStrikethrough(editorState), ), @@ -188,7 +188,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.code, - (value) => value == true, + (value) => value == true, ), handler: (editorState, context) => formatEmbedCode(editorState), ), @@ -204,7 +204,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.subtype, - (value) => value == BuiltInAttributeKey.quote, + (value) => value == BuiltInAttributeKey.quote, ), handler: (editorState, context) => formatQuote(editorState), ), @@ -220,7 +220,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.subtype, - (value) => value == BuiltInAttributeKey.bulletedList, + (value) => value == BuiltInAttributeKey.bulletedList, ), handler: (editorState, context) => formatBulletedList(editorState), ), @@ -236,7 +236,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.href, - (value) => value != null, + (value) => value != null, ), handler: (editorState, context) => showLinkMenu(context, editorState), ), @@ -252,7 +252,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.backgroundColor, - (value) => value != null, + (value) => value != null, ), handler: (editorState, context) => formatHighlight( editorState, @@ -284,7 +284,7 @@ ToolbarItemValidator _showInBuiltInTextSelection = (editorState) { bool _allSatisfy( EditorState editorState, String styleKey, - bool Function(dynamic value) test, + bool Function(T value) test, ) { final selection = editorState.service.selectionService.currentSelection.value; return selection != null && @@ -333,8 +333,10 @@ void showLinkMenu( final textNode = node.first as TextNode; String? linkText; if (textNode.allSatisfyLinkInSelection(selection)) { - linkText = - textNode.getAttributeInSelection(selection, BuiltInAttributeKey.href); + linkText = textNode.getAttributeInSelection( + selection, + BuiltInAttributeKey.href, + ); } _linkMenuOverlay = OverlayEntry(builder: (context) { return Positioned( diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart index 053d9e542a..0377b9e37c 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart @@ -188,7 +188,7 @@ bool _allSatisfyInSelection( return false; } - return textNodes.allSatisfyInSelection(selection, styleKey, (value) { + return textNodes.allSatisfyInSelection(selection, styleKey, (value) { return value == matchValue; }); } diff --git a/frontend/app_flowy/packages/appflowy_editor/test/extensions/text_node_extensions_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/extensions/text_node_extensions_test.dart new file mode 100644 index 0000000000..bec92362f4 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/test/extensions/text_node_extensions_test.dart @@ -0,0 +1,10 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('TextNodeExtension::', () { + test('description', () { + final selecion = Selection.single(path: [0, 1, 2], startOffset: 0); + }); + }); +} diff --git a/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/toolbar_rich_text_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/toolbar_rich_text_test.dart index c9d9ef9e70..49990b4662 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/toolbar_rich_text_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/toolbar_rich_text_test.dart @@ -229,7 +229,7 @@ void main() async { node.allSatisfyInSelection( code, BuiltInAttributeKey.code, - (value) { + (value) { return value == true; }, ), @@ -319,7 +319,7 @@ void main() async { node.allSatisfyInSelection( selection, BuiltInAttributeKey.backgroundColor, - (value) { + (value) { return value == blue; }, ), diff --git a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/format_style_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/format_style_handler_test.dart index 0cb4c71600..684e7d21f1 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/format_style_handler_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/format_style_handler_test.dart @@ -111,7 +111,7 @@ Future _testUpdateTextStyleByCommandX( textNode.allSatisfyInSelection( selection, matchStyle, - (value) { + (value) { return value == matchValue; }, ), @@ -138,7 +138,7 @@ Future _testUpdateTextStyleByCommandX( textNode.allSatisfyInSelection( selection, matchStyle, - (value) { + (value) { return value == matchValue; }, ), @@ -192,7 +192,7 @@ Future _testUpdateTextStyleByCommandX( endOffset: text.length, ), matchStyle, - (value) { + (value) { return value == matchValue; }, ), @@ -266,7 +266,7 @@ Future _testLinkMenuInSingleTextSelection(WidgetTester tester) async { node.allSatisfyInSelection( selection, BuiltInAttributeKey.href, - (value) => value == link, + (value) => value == link, ), true); @@ -303,7 +303,7 @@ Future _testLinkMenuInSingleTextSelection(WidgetTester tester) async { node.allSatisfyInSelection( selection, BuiltInAttributeKey.href, - (value) => value == link, + (value) => value == link, ), false); } From 73a97fdbeabfe69951374beaff38b747da65e885 Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Wed, 5 Oct 2022 23:55:01 -0500 Subject: [PATCH 13/14] fix: conflict merge --- .../app_flowy/packages/appflowy_editor/example/lib/main.dart | 2 +- .../example/lib/plugin/tex_block_node_widget.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/app_flowy/packages/appflowy_editor/example/lib/main.dart b/frontend/app_flowy/packages/appflowy_editor/example/lib/main.dart index fecec3d3e0..4283752a03 100644 --- a/frontend/app_flowy/packages/appflowy_editor/example/lib/main.dart +++ b/frontend/app_flowy/packages/appflowy_editor/example/lib/main.dart @@ -128,7 +128,7 @@ class _MyHomePageState extends State { underscoreToItalic, ], selectionMenuItems: [ - codeBlockMenuItem, + codeBlockItem, teXBlockMenuItem, ], ), diff --git a/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/tex_block_node_widget.dart b/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/tex_block_node_widget.dart index 80ad3642ca..e76c3e160b 100644 --- a/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/tex_block_node_widget.dart +++ b/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/tex_block_node_widget.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_math_fork/flutter_math.dart'; SelectionMenuItem teXBlockMenuItem = SelectionMenuItem( - name: 'Tex', + name: () => 'Tex', icon: const Icon(Icons.text_fields_rounded), keywords: ['tex, latex, katex'], handler: (editorState, _, __) { From 2b8e4d3e611edf9bdc8933225dde4f9aac606c8c Mon Sep 17 00:00:00 2001 From: Enzo Lizama Date: Fri, 7 Oct 2022 21:24:28 -0500 Subject: [PATCH 14/14] test: delete file --- .../test/extensions/text_node_extensions_test.dart | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 frontend/app_flowy/packages/appflowy_editor/test/extensions/text_node_extensions_test.dart diff --git a/frontend/app_flowy/packages/appflowy_editor/test/extensions/text_node_extensions_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/extensions/text_node_extensions_test.dart deleted file mode 100644 index bec92362f4..0000000000 --- a/frontend/app_flowy/packages/appflowy_editor/test/extensions/text_node_extensions_test.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'package:appflowy_editor/appflowy_editor.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group('TextNodeExtension::', () { - test('description', () { - final selecion = Selection.single(path: [0, 1, 2], startOffset: 0); - }); - }); -}