From 3b4ae69f16a1c6cec0e7218ee64c69c0ec2960ed Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 12 Nov 2026 16:10:12 +0000 Subject: [PATCH 01/27] Add button for "Delete completed task" in index.html --- Sprint-3/todo-list/index.html | 73 ++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/Sprint-3/todo-list/index.html b/Sprint-3/todo-list/index.html index 4d12c46543..281fa34509 100644 --- a/Sprint-3/todo-list/index.html +++ b/Sprint-3/todo-list/index.html @@ -1,40 +1,51 @@ - + - - - - ToDo List - - + + + + ToDo List + + - - - -
-

My ToDo List

+ + + +
+

My ToDo List

-
- - -
+
+ + +
-
    -
+
    + - - - -
    - + +
    + From c2e02c1dcc9695b886b4b077e02873e5af6b0078 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 12 Nov 2026 16:19:57 +0000 Subject: [PATCH 02/27] Implement deleteCompleted function to remove completed tasks from the todo list --- Sprint-3/todo-list/todos.mjs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sprint-3/todo-list/todos.mjs b/Sprint-3/todo-list/todos.mjs index f17ab6a250..b3b2353d0f 100644 --- a/Sprint-3/todo-list/todos.mjs +++ b/Sprint-3/todo-list/todos.mjs @@ -26,4 +26,13 @@ export function toggleCompletedOnTask(todos, taskIndex) { if (todos[taskIndex]) { todos[taskIndex].completed = !todos[taskIndex].completed; } -} \ No newline at end of file +} + +// Remove every task whose "completed" property is true +export function deleteCompleted(todos) { + for (let i = todos.length - 1; i >= 0; i--) { + if (todos[i].completed) { + todos.splice(i, 1); + } + } +} From 4e8361ced0bf547ad9d25ed7045884e2496dd781 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 12 Nov 2026 16:27:24 +0000 Subject: [PATCH 03/27] Add tests for deleteCompleted function to verify removal of completed tasks --- Sprint-3/todo-list/todos.test.mjs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Sprint-3/todo-list/todos.test.mjs b/Sprint-3/todo-list/todos.test.mjs index bae7ae4917..0d7163953d 100644 --- a/Sprint-3/todo-list/todos.test.mjs +++ b/Sprint-3/todo-list/todos.test.mjs @@ -13,7 +13,7 @@ function createMockTodos() { { task: "Task 1 description", completed: true }, { task: "Task 2 description", completed: false }, { task: "Task 3 description", completed: true }, - { task: "Task 4 description", completed: false }, + { task: "Task 4 description", completed: false }, ]; } @@ -29,7 +29,6 @@ describe("addTask()", () => { }); test("Should append a new task to the end of a ToDo list", () => { - const todos = createMockTodos(); const lengthBeforeAddition = todos.length; Todos.addTask(todos, theTask.task, theTask.completed); @@ -42,7 +41,6 @@ describe("addTask()", () => { }); describe("deleteTask()", () => { - test("Delete the first task", () => { const todos = createMockTodos(); const todosBeforeDeletion = createMockTodos(); @@ -53,7 +51,7 @@ describe("deleteTask()", () => { expect(todos[0]).toEqual(todosBeforeDeletion[1]); expect(todos[1]).toEqual(todosBeforeDeletion[2]); - expect(todos[2]).toEqual(todosBeforeDeletion[3]); + expect(todos[2]).toEqual(todosBeforeDeletion[3]); }); test("Delete the second task (a middle task)", () => { @@ -66,7 +64,7 @@ describe("deleteTask()", () => { expect(todos[0]).toEqual(todosBeforeDeletion[0]); expect(todos[1]).toEqual(todosBeforeDeletion[2]); - expect(todos[2]).toEqual(todosBeforeDeletion[3]); + expect(todos[2]).toEqual(todosBeforeDeletion[3]); }); test("Delete the last task", () => { @@ -79,7 +77,7 @@ describe("deleteTask()", () => { expect(todos[0]).toEqual(todosBeforeDeletion[0]); expect(todos[1]).toEqual(todosBeforeDeletion[1]); - expect(todos[2]).toEqual(todosBeforeDeletion[2]); + expect(todos[2]).toEqual(todosBeforeDeletion[2]); }); test("Delete a non-existing task", () => { @@ -94,7 +92,6 @@ describe("deleteTask()", () => { }); describe("toggleCompletedOnTask()", () => { - test("Expect the 'completed' property to toggle on an existing task", () => { const todos = createMockTodos(); const taskIndex = 1; @@ -111,13 +108,12 @@ describe("toggleCompletedOnTask()", () => { const todos = createMockTodos(); const todosBeforeToggle = createMockTodos(); Todos.toggleCompletedOnTask(todos, 1); - - expect(todos[0]).toEqual(todosBeforeToggle[0]); + + expect(todos[0]).toEqual(todosBeforeToggle[0]); expect(todos[2]).toEqual(todosBeforeToggle[2]); expect(todos[3]).toEqual(todosBeforeToggle[3]); }); - test("Expect no change when toggling on a non-existing task", () => { const todos = createMockTodos(); const todosBeforeToggle = createMockTodos(); @@ -130,3 +126,12 @@ describe("toggleCompletedOnTask()", () => { }); }); +describe("deleteCompleted()", () => { + test("Removes all completed tasks", () => { + const todos = createMockTodos(); + Todos.deleteCompleted(todos); + + expect(todos).toHaveLength(2); + expect(todos.every((t) => !t.completed)).toBe(true); + }); +}); From 36b055f6d7d70b1a6a78b76e8eda1e9cb9009d20 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 12 Nov 2026 16:29:53 +0000 Subject: [PATCH 04/27] Add test to verify remaining tasks order after deleting completed tasks --- Sprint-3/todo-list/todos.test.mjs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-3/todo-list/todos.test.mjs b/Sprint-3/todo-list/todos.test.mjs index 0d7163953d..b9883e0ac5 100644 --- a/Sprint-3/todo-list/todos.test.mjs +++ b/Sprint-3/todo-list/todos.test.mjs @@ -134,4 +134,13 @@ describe("deleteCompleted()", () => { expect(todos).toHaveLength(2); expect(todos.every((t) => !t.completed)).toBe(true); }); + + test("Keeps the remaining tasks in their original order", () => { + const todos = createMockTodos(); + const before = createMockTodos(); + Todos.deleteCompleted(todos); + + expect(todos[0]).toEqual(before[1]); + expect(todos[1]).toEqual(before[3]); + }); }); From fb013414690be159c1b38e1140cb0fde944fcc42 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 12 Nov 2026 16:37:45 +0000 Subject: [PATCH 05/27] Add test to verify deletion of completed tasks results in an empty array --- Sprint-3/todo-list/todos.test.mjs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-3/todo-list/todos.test.mjs b/Sprint-3/todo-list/todos.test.mjs index b9883e0ac5..51b5e07e17 100644 --- a/Sprint-3/todo-list/todos.test.mjs +++ b/Sprint-3/todo-list/todos.test.mjs @@ -143,4 +143,14 @@ describe("deleteCompleted()", () => { expect(todos[0]).toEqual(before[1]); expect(todos[1]).toEqual(before[3]); }); + + test("Keeps the remaining tasks in their original order", () => { + const todos = [ + { task: "A", completed: true }, + { task: "B", completed: true }, + ]; + Todos.deleteCompleted(todos); + + expect(todos).toEqual([]); + }); }); From fe74b0ad0d689ac1da242729c622441f6e6095e9 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 12 Nov 2026 16:40:28 +0000 Subject: [PATCH 06/27] Add test to verify no changes when no tasks are completed in deleteCompleted function --- 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 51b5e07e17..c48f4ff93b 100644 --- a/Sprint-3/todo-list/todos.test.mjs +++ b/Sprint-3/todo-list/todos.test.mjs @@ -153,4 +153,11 @@ describe("deleteCompleted()", () => { expect(todos).toEqual([]); }); + + test("Changes nothing when no task is completed", () => { + const todos = [{ task: "A", completed: false }]; + Todos.deleteCompleted(todos); + + expect(todos).toEqual([{ task: "A", completed: false }]); + }); }); From ca95b419e84c499a97d5b16200edc7ae2d58c783 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 12 Nov 2026 16:47:13 +0000 Subject: [PATCH 07/27] Implement deleteCompleted functionality and update event listener for completed tasks --- Sprint-3/todo-list/script.mjs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Sprint-3/todo-list/script.mjs b/Sprint-3/todo-list/script.mjs index ba0b2ceaec..f2f189ef59 100644 --- a/Sprint-3/todo-list/script.mjs +++ b/Sprint-3/todo-list/script.mjs @@ -1,4 +1,4 @@ -// Store everything imported from './todos.mjs' module as properties of an object named Todos +// Store everything imported from './todos.mjs' module as properties of an object named Todos import * as Todos from "./todos.mjs"; // To store the todo tasks @@ -9,14 +9,21 @@ window.addEventListener("load", () => { document.getElementById("add-task-btn").addEventListener("click", addNewTodo); // Populate sample data - Todos.addTask(todos, "Wash the dishes", false); + Todos.addTask(todos, "Wash the dishes", false); Todos.addTask(todos, "Do the shopping", true); render(); -}); + document + .getElementById("delete-completed-btn") + .addEventListener("click", () => { + Todos.deleteCompleted(todos); + + render(); + }); +}); -// A callback that reads the task description from an input field and +// A callback that reads the task description from an input field and // append a new task to the todo list. function addNewTodo() { const taskInput = document.getElementById("new-task-input"); @@ -45,12 +52,11 @@ function render() { }); } - // Note: // - First child of #todo-item-template is a
  • element. // We will create each ToDo list item as a clone of this node. // - This variable is declared here to be close to the only function that uses it. -const todoListItemTemplate = +const todoListItemTemplate = document.getElementById("todo-item-template").content.firstElementChild; // Create a
  • element for the given todo task @@ -62,15 +68,15 @@ function createListItem(todo, index) { li.classList.add("completed"); } - li.querySelector('.complete-btn').addEventListener("click", () => { + li.querySelector(".complete-btn").addEventListener("click", () => { Todos.toggleCompletedOnTask(todos, index); render(); }); - - li.querySelector('.delete-btn').addEventListener("click", () => { + + li.querySelector(".delete-btn").addEventListener("click", () => { Todos.deleteTask(todos, index); render(); }); return li; -} \ No newline at end of file +} From d300a88a2c22435ffe9afda36d4c05dd5e37e057 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 12 Nov 2026 16:53:41 +0000 Subject: [PATCH 08/27] Add deadline input field and update todo item template to display deadline --- Sprint-3/todo-list/index.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-3/todo-list/index.html b/Sprint-3/todo-list/index.html index 281fa34509..269d1b46ca 100644 --- a/Sprint-3/todo-list/index.html +++ b/Sprint-3/todo-list/index.html @@ -22,6 +22,7 @@

    My ToDo List

    id="new-task-input" placeholder="Enter a new task..." /> + @@ -36,6 +37,7 @@

    My ToDo List

  • Task description +
    @@ -29,13 +33,8 @@

    My ToDo List

      -