From 6de52d313e751dda2f7194d60f9625a4fdc169e5 Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Wed, 18 Mar 2026 10:37:06 +0000 Subject: [PATCH 1/3] updated package.json --- Sprint-3/todo-list/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/todo-list/package.json b/Sprint-3/todo-list/package.json index ce181158a..15eef950e 100644 --- a/Sprint-3/todo-list/package.json +++ b/Sprint-3/todo-list/package.json @@ -6,7 +6,7 @@ "type": "module", "scripts": { "serve": "http-server", - "test": "NODE_OPTIONS=--experimental-vm-modules jest" + "test": "set NODE_OPTIONS=--experimental-vm-modules && jest" }, "repository": { "type": "git", From 29d5a048e09a96900e5647320af03dfc13f6ad57 Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Wed, 18 Mar 2026 10:39:10 +0000 Subject: [PATCH 2/3] delete completed todos --- Sprint-3/todo-list/index.html | 2 ++ Sprint-3/todo-list/script.mjs | 8 +++++++- Sprint-3/todo-list/todos.mjs | 8 ++++++++ Sprint-3/todo-list/todos.test.mjs | 33 +++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Sprint-3/todo-list/index.html b/Sprint-3/todo-list/index.html index 4d12c4654..4b077b6d1 100644 --- a/Sprint-3/todo-list/index.html +++ b/Sprint-3/todo-list/index.html @@ -35,6 +35,8 @@

My ToDo List

+ + diff --git a/Sprint-3/todo-list/script.mjs b/Sprint-3/todo-list/script.mjs index ba0b2ceae..147a09a2b 100644 --- a/Sprint-3/todo-list/script.mjs +++ b/Sprint-3/todo-list/script.mjs @@ -73,4 +73,10 @@ function createListItem(todo, index) { }); return li; -} \ No newline at end of file +} + +// "Delete Completed Tasks" button +document.querySelector(".delete-completed-btn").addEventListener("click", () => { + Todos.deleteCompletedTasks(todos); + render(); +}); \ No newline at end of file diff --git a/Sprint-3/todo-list/todos.mjs b/Sprint-3/todo-list/todos.mjs index f17ab6a25..69d15dfc0 100644 --- a/Sprint-3/todo-list/todos.mjs +++ b/Sprint-3/todo-list/todos.mjs @@ -26,4 +26,12 @@ export function toggleCompletedOnTask(todos, taskIndex) { if (todos[taskIndex]) { todos[taskIndex].completed = !todos[taskIndex].completed; } +} + +export function deleteCompletedTasks(todos) { + for (let i = todos.length - 1; i >= 0; i--) { + if (todos[i].completed) { + todos.splice(i, 1); + } + } } \ No newline at end of file diff --git a/Sprint-3/todo-list/todos.test.mjs b/Sprint-3/todo-list/todos.test.mjs index bae7ae491..3cc9d4579 100644 --- a/Sprint-3/todo-list/todos.test.mjs +++ b/Sprint-3/todo-list/todos.test.mjs @@ -130,3 +130,36 @@ describe("toggleCompletedOnTask()", () => { }); }); +describe("deleteCompletedTasks()", () => { + + test("Expect all completed tasks to be deleted", () => { + const todos = createMockTodos(); + Todos.deleteCompletedTasks(todos); + expect(todos).toHaveLength(2); + expect(todos[0]).toEqual({ task: "Task 2 description", completed: false }); + expect(todos[1]).toEqual({ task: "Task 4 description", completed: false }); + }); + + test("Expect no change if there are no completed tasks", () => { + const todos = [ + { task: "", completed: false }, + { task: "Task 2 description", completed: false }, + ]; + const todosBeforeDeletion = [ + { task: "Task 1 description", completed: false }, + { task: "Task 2 description", completed: false }, + ]; + Todos.deleteCompletedTasks(todos); + expect(todos).toEqual(todosBeforeDeletion); + }); + + test("Expect all tasks to be deleted if all tasks are completed", () => { + const todos = [ + { task: "Task 1 description", completed: true }, + { task: "Task 2 description", completed: true }, + ]; + Todos.deleteCompletedTasks(todos); + expect(todos).toHaveLength(0); + }); +}); + From a6960e3762925a3cd6b016b36f0d5dc82c312bcb Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Wed, 18 Mar 2026 10:40:07 +0000 Subject: [PATCH 3/3] deadline --- Sprint-3/todo-list/index.html | 2 ++ Sprint-3/todo-list/script.mjs | 16 +++++++++++++++- Sprint-3/todo-list/todos.mjs | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Sprint-3/todo-list/index.html b/Sprint-3/todo-list/index.html index 4b077b6d1..1033fb83f 100644 --- a/Sprint-3/todo-list/index.html +++ b/Sprint-3/todo-list/index.html @@ -15,6 +15,7 @@

My ToDo List

+
@@ -28,6 +29,7 @@

My ToDo List