Skip to content

Commit

Permalink
feat:add test
Browse files Browse the repository at this point in the history
  • Loading branch information
q200892907 committed Jan 14, 2024
1 parent f522189 commit 66f2608
Showing 1 changed file with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
});
});
}

0 comments on commit 66f2608

Please sign in to comment.