From 66f2608dcb62042048b85a229e6b52cb72b39a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=A3=8A?= <200892907@qq.com> Date: Sun, 14 Jan 2024 10:25:37 +0800 Subject: [PATCH] feat:add test --- .../insert_newline_in_type_command_test.dart | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 test/editor/block_component/base_component/insert_newline_in_type_command_test.dart diff --git a/test/editor/block_component/base_component/insert_newline_in_type_command_test.dart b/test/editor/block_component/base_component/insert_newline_in_type_command_test.dart new file mode 100644 index 000000000..a1cff6b52 --- /dev/null +++ b/test/editor/block_component/base_component/insert_newline_in_type_command_test.dart @@ -0,0 +1,77 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('InsertNewlineInTypeCommand tests', () { + test('bulleted list', () async { + final bulletedNode = bulletedListNode( + text: 'bulleted list 1', + children: [ + bulletedListNode(text: '1'), + bulletedListNode(text: ''), + ], + ); + final document = Document.blank()..insert([0], [bulletedNode]); + + final editorState = EditorState(document: document); + + editorState.selection = Selection.collapsed(Position(path: [0, 1])); + + insertNewLineAfterBulletedList.execute(editorState); + Node? node1 = editorState.getNodeAtPath([1]); + expect(node1?.type, BulletedListBlockKeys.type); + + insertNewLineAfterBulletedList.execute(editorState); + Node? node2 = editorState.getNodeAtPath([1]); + + expect(node2?.type, ParagraphBlockKeys.type); + }); + + test('todo list', () async { + final todoListNodes = todoListNode( + checked: false, + children: [ + todoListNode(checked: false), + todoListNode(checked: false), + ], + ); + final document = Document.blank()..insert([0], [todoListNodes]); + + final editorState = EditorState(document: document); + + editorState.selection = Selection.collapsed(Position(path: [0, 1])); + + insertNewLineAfterTodoList.execute(editorState); + Node? node1 = editorState.getNodeAtPath([1]); + expect(node1?.type, TodoListBlockKeys.type); + + insertNewLineAfterTodoList.execute(editorState); + Node? node2 = editorState.getNodeAtPath([1]); + + expect(node2?.type, ParagraphBlockKeys.type); + }); + + test('numbered list', () async { + final numberedListNodes = numberedListNode( + children: [ + numberedListNode(), + numberedListNode(), + ], + ); + final document = Document.blank()..insert([0], [numberedListNodes]); + + final editorState = EditorState(document: document); + + editorState.selection = Selection.collapsed(Position(path: [0, 1])); + + insertNewLineAfterNumberedList.execute(editorState); + Node? node1 = editorState.getNodeAtPath([1]); + expect(node1?.type, NumberedListBlockKeys.type); + + insertNewLineAfterNumberedList.execute(editorState); + Node? node2 = editorState.getNodeAtPath([1]); + + expect(node2?.type, ParagraphBlockKeys.type); + }); + }); +}