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.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
test: add unit test for backquote to code
He Linming9604bc06bb64
diff --git a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/markdown_syntax_to_styled_text_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/markdown_syntax_to_styled_text_test.dartnew file mode 100644index 0000000000..d11a955643--- /dev/null+++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/markdown_syntax_to_styled_text_test.dart@@ -0,0 +1,154 @@+import 'package:appflowy_editor/appflowy_editor.dart';+import 'package:appflowy_editor/src/extensions/text_node_extensions.dart';+import 'package:flutter/services.dart';+import 'package:flutter_test/flutter_test.dart';+import '../../infra/test_editor.dart';++void main() async {+ setUpAll(() {+ TestWidgetsFlutterBinding.ensureInitialized();+ });++ group('markdown_syntax_to_styled_text.dart', () {+ group('convert single backquote to code', () {+ Future<void> insertBackquote(+ EditorWidgetTester editor, {+ int repeat = 1,+ }) async {+ for (var i = 0; i < repeat; i++) {+ await editor.pressLogicKey(+ LogicalKeyboardKey.backquote,+ );+ }+ }++ testWidgets('`AppFlowy` to code AppFlowy', (tester) async {+ const text = '`AppFlowy';+ final editor = tester.editor..insertTextNode('');+ await editor.startTesting();+ await editor.updateSelection(+ Selection.single(path: [0], startOffset: 0),+ );+ final textNode = editor.nodeAtPath([0]) as TextNode;+ for (var i = 0; i < text.length; i++) {+ await editor.insertText(textNode, text[i], i);+ }+ await insertBackquote(editor);+ final allCode = textNode.allSatisfyCodeInSelection(+ Selection.single(+ path: [0],+ startOffset: 0,+ endOffset: textNode.toRawString().length,+ ),+ );+ expect(allCode, true);+ expect(textNode.toRawString(), 'AppFlowy');+ });++ testWidgets('App`Flowy` to code AppFlowy', (tester) async {+ const text = 'App`Flowy';+ final editor = tester.editor..insertTextNode('');+ await editor.startTesting();+ await editor.updateSelection(+ Selection.single(path: [0], startOffset: 0),+ );+ final textNode = editor.nodeAtPath([0]) as TextNode;+ for (var i = 0; i < text.length; i++) {+ await editor.insertText(textNode, text[i], i);+ }+ await insertBackquote(editor);+ final allCode = textNode.allSatisfyCodeInSelection(+ Selection.single(+ path: [0],+ startOffset: 3,+ endOffset: textNode.toRawString().length,+ ),+ );+ expect(allCode, true);+ expect(textNode.toRawString(), 'AppFlowy');+ });++ testWidgets('`` nothing changes', (tester) async {+ const text = '`';+ final editor = tester.editor..insertTextNode('');+ await editor.startTesting();+ await editor.updateSelection(+ Selection.single(path: [0], startOffset: 0),+ );+ final textNode = editor.nodeAtPath([0]) as TextNode;+ for (var i = 0; i < text.length; i++) {+ await editor.insertText(textNode, text[i], i);+ }+ await insertBackquote(editor);+ final allCode = textNode.allSatisfyCodeInSelection(+ Selection.single(+ path: [0],+ startOffset: 0,+ endOffset: textNode.toRawString().length,+ ),+ );+ expect(allCode, false);+ expect(textNode.toRawString(), text);+ });+ });++ group('convert double backquote to code', () {+ Future<void> insertBackquote(+ EditorWidgetTester editor, {+ int repeat = 1,+ }) async {+ for (var i = 0; i < repeat; i++) {+ await editor.pressLogicKey(+ LogicalKeyboardKey.backquote,+ );+ }+ }++ testWidgets('```AppFlowy`` to code `AppFlowy', (tester) async {+ const text = '```AppFlowy`';+ final editor = tester.editor..insertTextNode('');+ await editor.startTesting();+ await editor.updateSelection(+ Selection.single(path: [0], startOffset: 0),+ );+ final textNode = editor.nodeAtPath([0]) as TextNode;+ for (var i = 0; i < text.length; i++) {+ await editor.insertText(textNode, text[i], i);+ }+ await insertBackquote(editor);+ final allCode = textNode.allSatisfyCodeInSelection(+ Selection.single(+ path: [0],+ startOffset: 1,+ endOffset: textNode.toRawString().length,+ ),+ );+ expect(allCode, true);+ expect(textNode.toRawString(), '`AppFlowy');+ });++ testWidgets('```` nothing changes', (tester) async {+ const text = '```';+ final editor = tester.editor..insertTextNode('');+ await editor.startTesting();+ await editor.updateSelection(+ Selection.single(path: [0], startOffset: 0),+ );+ final textNode = editor.nodeAtPath([0]) as TextNode;+ for (var i = 0; i < text.length; i++) {+ await editor.insertText(textNode, text[i], i);+ }+ await insertBackquote(editor);+ final allCode = textNode.allSatisfyCodeInSelection(+ Selection.single(+ path: [0],+ startOffset: 0,+ endOffset: textNode.toRawString().length,+ ),+ );+ expect(allCode, false);+ expect(textNode.toRawString(), text);+ });+ });+ });+}