From 8cabb07483cfa4103b602f304485c472dfc2e40a Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Sat, 15 Feb 2020 02:30:00 +0100 Subject: [PATCH] checklist: verify insertItem works --- lib/core/checklist.dart | 2 +- test/checklist_test.dart | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/core/checklist.dart b/lib/core/checklist.dart index bffed055..9eac5804 100644 --- a/lib/core/checklist.dart +++ b/lib/core/checklist.dart @@ -113,7 +113,7 @@ class Checklist { var prevItem = items[index]; var nodeIndex = nodes.indexOf(prevItem.element); - nodes.insert(nodeIndex + 1, item.element); + nodes.insert(nodeIndex, item.element); items.insert(index, item); } } diff --git a/test/checklist_test.dart b/test/checklist_test.dart index c65315d8..a865277b 100644 --- a/test/checklist_test.dart +++ b/test/checklist_test.dart @@ -149,5 +149,25 @@ Booga Wooga note = checklist.note; expect(note.body, "Hi.\n[ ] item\n"); }); + + test('insertItem works', () async { + var content = "Hi.\n[ ] One\nTwo\n[ ] Three"; + + var notePath = p.join(tempDir.path, "note4.md"); + File(notePath).writeAsString(content); + + var parentFolder = NotesFolder(null, tempDir.path); + var note = Note(parentFolder, notePath); + await note.load(); + + var checklist = Checklist(note); + var items = checklist.items; + expect(items.length, equals(2)); + + checklist.insertItem(1, checklist.buildItem(false, "item")); + + note = checklist.note; + expect(note.body, "Hi.\n[ ] One\nTwo\n[ ] item\n[ ] Three\n"); + }); }); }