From ae6e1857fd23817914cb244a2a77860e806a9e79 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sat, 14 Mar 2026 18:39:29 +0000 Subject: [PATCH 1/7] Add delete completed tasks button to the ToDo list --- Sprint-3/todo-list/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/todo-list/index.html b/Sprint-3/todo-list/index.html index 4d12c4654..78e0c8724 100644 --- a/Sprint-3/todo-list/index.html +++ b/Sprint-3/todo-list/index.html @@ -34,7 +34,7 @@

My ToDo List

- + From f5bd8fae0049db05c9acc6eaeb943e1a01976fe8 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sat, 14 Mar 2026 19:28:22 +0000 Subject: [PATCH 2/7] Add deleteCompleted function to remove completed tasks from the todo list --- Sprint-3/todo-list/todos.mjs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-3/todo-list/todos.mjs b/Sprint-3/todo-list/todos.mjs index f17ab6a25..f95c07161 100644 --- a/Sprint-3/todo-list/todos.mjs +++ b/Sprint-3/todo-list/todos.mjs @@ -26,4 +26,11 @@ export function toggleCompletedOnTask(todos, taskIndex) { if (todos[taskIndex]) { todos[taskIndex].completed = !todos[taskIndex].completed; } +} +export function deleteCompleted(todoList){ + for(let i=todoList.length-1;i>=0;i-- ){ + if(todoList[i].completed){ + todoList.splice(i,1) + } + } } \ No newline at end of file From 671afdc0fdfd23d18ce1e76d9938549683ac2c54 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sat, 14 Mar 2026 20:11:52 +0000 Subject: [PATCH 3/7] Add test for deleteCompleted function to verify removal of completed tasks --- Sprint-3/todo-list/todos.test.mjs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-3/todo-list/todos.test.mjs b/Sprint-3/todo-list/todos.test.mjs index bae7ae491..002965838 100644 --- a/Sprint-3/todo-list/todos.test.mjs +++ b/Sprint-3/todo-list/todos.test.mjs @@ -130,3 +130,10 @@ describe("toggleCompletedOnTask()", () => { }); }); +describe("deleteCompleted()",()=>{ + test("remove all completed tasks",()=>{ + const todoList=createMockTodos() + Todos.deleteCompleted(todoList) + expect(todoList).toHaveLength(2) + }) +}); \ No newline at end of file From 6d2862fc59236ed8e8dee9d95108066b4c5bcce2 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sat, 14 Mar 2026 20:35:32 +0000 Subject: [PATCH 4/7] Add event listener for delete completed tasks button to remove completed todos --- Sprint-3/todo-list/script.mjs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-3/todo-list/script.mjs b/Sprint-3/todo-list/script.mjs index ba0b2ceae..2b86f5386 100644 --- a/Sprint-3/todo-list/script.mjs +++ b/Sprint-3/todo-list/script.mjs @@ -13,6 +13,11 @@ window.addEventListener("load", () => { Todos.addTask(todos, "Do the shopping", true); render(); + const deleteButton = document.getElementById("delete-completed-tasks"); + deleteButton.addEventListener("click", () => { + Todos.deleteCompleted(todos); + render(); + }); }); @@ -73,4 +78,5 @@ function createListItem(todo, index) { }); return li; -} \ No newline at end of file +} + From d08e9ec7652510e7b8f5b52aa99ae1b279361df4 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 2 Apr 2026 10:58:03 +0100 Subject: [PATCH 5/7] formated code to make it more readable --- Sprint-3/todo-list/todos.mjs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprint-3/todo-list/todos.mjs b/Sprint-3/todo-list/todos.mjs index f95c07161..bfdaf75f7 100644 --- a/Sprint-3/todo-list/todos.mjs +++ b/Sprint-3/todo-list/todos.mjs @@ -27,10 +27,10 @@ export function toggleCompletedOnTask(todos, taskIndex) { todos[taskIndex].completed = !todos[taskIndex].completed; } } -export function deleteCompleted(todoList){ - for(let i=todoList.length-1;i>=0;i-- ){ - if(todoList[i].completed){ - todoList.splice(i,1) +export function deleteCompleted(todoList) { + for (let i = todoList.length - 1; i >= 0; i--) { + if (todoList[i].completed) { + todoList.splice(i, 1); } } -} \ No newline at end of file +} From a045f8038b145d29fc1298d7693841e30f2fab0a Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 2 Apr 2026 16:14:02 +0100 Subject: [PATCH 6/7] check that remaining tasks are the ones expected --- Sprint-3/todo-list/todos.test.mjs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-3/todo-list/todos.test.mjs b/Sprint-3/todo-list/todos.test.mjs index 002965838..06c76deee 100644 --- a/Sprint-3/todo-list/todos.test.mjs +++ b/Sprint-3/todo-list/todos.test.mjs @@ -135,5 +135,9 @@ describe("deleteCompleted()",()=>{ const todoList=createMockTodos() Todos.deleteCompleted(todoList) expect(todoList).toHaveLength(2) + expect(todoList).toEqual([ + { task: "Task 2 description", completed: false }, + { task: "Task 4 description", completed: false }, + ]); }) }); \ No newline at end of file From 349f50ff6583fab26b19ee165cad1ae1cae93b86 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 2 Apr 2026 16:34:48 +0100 Subject: [PATCH 7/7] check deleteCompleted function does nothing when no completed tasks --- Sprint-3/todo-list/todos.test.mjs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sprint-3/todo-list/todos.test.mjs b/Sprint-3/todo-list/todos.test.mjs index 06c76deee..30f65ded8 100644 --- a/Sprint-3/todo-list/todos.test.mjs +++ b/Sprint-3/todo-list/todos.test.mjs @@ -140,4 +140,17 @@ describe("deleteCompleted()",()=>{ { task: "Task 4 description", completed: false }, ]); }) -}); \ No newline at end of file +}); + test("does nothing when there are no completed tasks", () => { + const todoList = [ + { task: "Task 1 description", completed: false }, + { task: "Task 2 description", completed: false }, + ]; + + Todos.deleteCompleted(todoList); + + expect(todoList).toEqual([ + { task: "Task 1 description", completed: false }, + { task: "Task 2 description", completed: false }, + ]); + });