fix: unit test and integration test

This commit is contained in:
Lucas.Xu 2025-04-09 09:32:10 +08:00
parent dba8235440
commit 5b6af79dbd
4 changed files with 12 additions and 4 deletions

View file

@ -72,8 +72,11 @@ extension AiWriterNodeExtension on EditorState {
}
}
// use \n\n as line break to improve the ai response
// using \n will cause the ai response treat the text as a single line
final markdown = await customDocumentToMarkdown(
Document.blank()..insert([0], slicedNodes),
lineBreak: '\n\n',
);
// trim the last \n if it exists

View file

@ -424,6 +424,7 @@ class MarkdownTextRobot {
firstMarkdownDelta != null) {
final startIndex = selection.startIndex;
final length = delta.length - startIndex;
transaction
..deleteText(firstNode, startIndex, length)
..insertTextDelta(firstNode, startIndex, firstMarkdownDelta);
@ -439,7 +440,9 @@ class MarkdownTextRobot {
lastMarkdownNode != null &&
lastMarkdownDelta != null) {
final endIndex = selection.endIndex;
transaction.deleteText(lastNode, 0, endIndex);
// if the last node is same as the first node, it means we have replaced the
// selected text in the first node.
if (lastMarkdownNode.id != firstMarkdownNode?.id) {
@ -457,8 +460,9 @@ class MarkdownTextRobot {
}
// step 4
if (nodes.length > 2) {
final middleNodes = nodes.skip(1).take(nodes.length - 2).toList();
final length = nodes.length - 2;
if (length > 0) {
final middleNodes = nodes.skip(1).take(length).toList();
transaction.deleteNodes(middleNodes);
}

View file

@ -27,6 +27,7 @@ Future<String> customDocumentToMarkdown(
Document document, {
String path = '',
AsyncValueSetter<Archive>? onArchive,
String lineBreak = '',
}) async {
final List<Future<ArchiveFile>> fileFutures = [];
@ -41,7 +42,7 @@ Future<String> customDocumentToMarkdown(
try {
markdown = documentToMarkdown(
document,
lineBreak: '\n\n',
lineBreak: lineBreak,
customParsers: [
const MathEquationNodeParser(),
const CalloutNodeParser(),

View file

@ -375,7 +375,7 @@ void main() {
await blocResponseFuture();
bloc.runResponseAction(SuggestionAction.accept);
await blocResponseFuture();
expect(editorState.document.root.children.length, 1);
expect(editorState.document.root.children.length, 2);
expect(
editorState.getNodeAtPath([0])!.delta!.toPlainText(),
'Hello World',