diff --git a/dist/index.js b/dist/index.js index 72cb736..b62312e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29894,12 +29894,24 @@ const generateChangeList = (current, previous, result=[]) => { const aMatch = previous.find((entry) => { return entry.text.replaceAll(MARKDOWN_STRIKETHROUGH, "") === checkboxLine.text.replaceAll(MARKDOWN_STRIKETHROUGH, ""); // check from strike }) - if (aMatch !== null) { + if (aMatch !== undefined) { if (aMatch.text !== checkboxLine.text || aMatch.checked !== checkboxLine.checked) { result.push(checkboxLine); } + } else { + result.push({checked: checkboxLine.checked, text: `[added] ${checkboxLine.text}`}); + } + }); + // check for removed + previous.forEach((checkboxLine) => { + const aMatch = current.find((entry) => { + return entry.text.replaceAll(MARKDOWN_STRIKETHROUGH, "") === checkboxLine.text.replaceAll(MARKDOWN_STRIKETHROUGH, ""); // check from strike + }); + if (aMatch === undefined) { + result.push({checked: checkboxLine.checked, text: `[removed] ${checkboxLine.text}`}); } }); + console.log('>>>', JSON.stringify(result)); return result; }; diff --git a/src/functions.js b/src/functions.js index 566ecea..d0ef24d 100644 --- a/src/functions.js +++ b/src/functions.js @@ -31,12 +31,24 @@ const generateChangeList = (current, previous, result=[]) => { const aMatch = previous.find((entry) => { return entry.text.replaceAll(MARKDOWN_STRIKETHROUGH, "") === checkboxLine.text.replaceAll(MARKDOWN_STRIKETHROUGH, ""); // check from strike }) - if (aMatch !== null) { + if (aMatch !== undefined) { if (aMatch.text !== checkboxLine.text || aMatch.checked !== checkboxLine.checked) { result.push(checkboxLine); } + } else { + result.push({checked: checkboxLine.checked, text: `[added] ${checkboxLine.text}`}); } }); + // check for removed + previous.forEach((checkboxLine) => { + const aMatch = current.find((entry) => { + return entry.text.replaceAll(MARKDOWN_STRIKETHROUGH, "") === checkboxLine.text.replaceAll(MARKDOWN_STRIKETHROUGH, ""); // check from strike + }); + if (aMatch === undefined) { + result.push({checked: checkboxLine.checked, text: `[removed] ${checkboxLine.text}`}); + } + }); + console.log('>>>', JSON.stringify(result)); return result; }; diff --git a/src/functions.test.js b/src/functions.test.js index 538b335..8eef824 100644 --- a/src/functions.test.js +++ b/src/functions.test.js @@ -37,10 +37,14 @@ test('finds both of the checkboxes', () => { const current = []; const previous = []; +const added = []; +const removed = []; beforeAll(() => { extractCheckmarks("something at the start\n-[x] hi there\nsomething in the middle\n-[ ] was here \nsomething at the end", current); extractCheckmarks("something at the start\n-[x] hi there\nsomething in the middle\n-[x] was here\nsomething at the end", previous); + extractCheckmarks("something at the start\n-[x] hi there\nsomething in the middle\n-[x] was here\n- [ ] new task\nsomething at the end", added); + extractCheckmarks("something at the start\n-[x] hi there\nsomething in the middle\n-[x] was here\nsomething at the end", removed); }); describe('calculating changes between the bodies', () => { @@ -50,4 +54,10 @@ describe('calculating changes between the bodies', () => { test('finds a change between the edits', ()=>{ expect(generateChangeList(current, previous)).toStrictEqual([{checked: false, text: "was here"}]); }) + test('handles additional task', ()=>{ + expect(generateChangeList(added, previous)).toStrictEqual([{checked: false, text: "[added] new task"}]); + }) + test('handles removed task', ()=>{ + expect(generateChangeList(removed, added)).toStrictEqual([{checked: false, text: "[removed] new task"}]); + }) });