From b05cddbe5104fe21e27e96f7056cd9ab576d9ef4 Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Mon, 23 Nov 2026 18:20:12 +0000 Subject: [PATCH 1/8] Refactor HTML structure for improved readability and consistency --- 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..55b717a412 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 9cfa49f37203c4ec8fa9201d0059a1866579bcb6 Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Mon, 23 Nov 2026 18:20:21 +0000 Subject: [PATCH 2/8] Fix formatting inconsistencies and improve code readability in script.mjs --- Sprint-3/todo-list/script.mjs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Sprint-3/todo-list/script.mjs b/Sprint-3/todo-list/script.mjs index ba0b2ceaec..ff981587a9 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,13 @@ 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(); }); - -// 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 +44,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 +60,21 @@ 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 +} + +const deleteAllCompleted = document.getElementById("delete-all-completed"); +deleteAllCompleted.addEventListener("click", () => { + Todos.deleteCompleted(todos); + render(); +}); From 7953791dc674fa3501700c74e5712ed6ab948327 Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Mon, 23 Nov 2026 18:20:29 +0000 Subject: [PATCH 3/8] Fix button background color case and add styles for delete all completed button --- Sprint-3/todo-list/style.css | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-3/todo-list/style.css b/Sprint-3/todo-list/style.css index 535e912277..639d18146a 100644 --- a/Sprint-3/todo-list/style.css +++ b/Sprint-3/todo-list/style.css @@ -41,7 +41,7 @@ h1 { .todo-input button { padding: 10px 20px; font-size: 16px; - background-color: #4CAF50; + background-color: #4caf50; color: white; border: none; border-radius: 6px; @@ -105,3 +105,13 @@ h1 { text-decoration: line-through; color: gray; } + +#delete-all-completed { + background-color: red; + padding: 10px 20px; + font-size: 16px; + color: white; + border: none; + border-radius: 6px; + cursor: pointer; +} From 2d0b15db702473eb9ddd34ea3aa89d9031ef25b3 Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Mon, 23 Nov 2026 18:20:38 +0000 Subject: [PATCH 4/8] Refactor todos.mjs to improve code readability and add comments for clarity --- Sprint-3/todo-list/todos.mjs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sprint-3/todo-list/todos.mjs b/Sprint-3/todo-list/todos.mjs index f17ab6a250..35b3f304f1 100644 --- a/Sprint-3/todo-list/todos.mjs +++ b/Sprint-3/todo-list/todos.mjs @@ -11,19 +11,25 @@ // Append a new task to todos[] export function addTask(todos, task, completed = false) { - todos.push({ task, completed }); + todos.push({ task, completed }); //add one element to the array todos } // Delete todos[taskIndex] if it exists export function deleteTask(todos, taskIndex) { if (todos[taskIndex]) { - todos.splice(taskIndex, 1); + todos.splice(taskIndex, 1); //delete the selected element } } // Toggle the "completed" property of todos[taskIndex] if the task exists. export function toggleCompletedOnTask(todos, taskIndex) { if (todos[taskIndex]) { - todos[taskIndex].completed = !todos[taskIndex].completed; + todos[taskIndex].completed = !todos[taskIndex].completed; // changes false to true } -} \ No newline at end of file +} + +export function deleteCompleted(todoList) { + const remainingTasks = todoList.filter((todo) => !todo.completed); + + todoList.splice(0, todoList.length, ...remainingTasks); +} From 7fb0f4e38e308244a288fd49c6a7c7c3e96358f9 Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Mon, 23 Nov 2026 18:20:47 +0000 Subject: [PATCH 5/8] Refactor todos.test.mjs to improve formatting and add test for deleting all completed tasks --- Sprint-3/todo-list/todos.test.mjs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Sprint-3/todo-list/todos.test.mjs b/Sprint-3/todo-list/todos.test.mjs index bae7ae4917..b9b63b2d86 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", () => { @@ -91,10 +89,17 @@ describe("deleteTask()", () => { Todos.deleteTask(todos, -1); expect(todos).toEqual(todosBeforeDeletion); }); + + test("Delete all completed tasks", () => { + const todos = createMockTodos(); + const todosBeforeDeletionCompleted = createMockTodos(); + Todos.deleteCompleted(todos); + expect(todos[0]).toEqual(todosBeforeDeletionCompleted[1]); + expect(todos[1]).toEqual(todosBeforeDeletionCompleted[3]); + }); }); describe("toggleCompletedOnTask()", () => { - test("Expect the 'completed' property to toggle on an existing task", () => { const todos = createMockTodos(); const taskIndex = 1; @@ -111,13 +116,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(); @@ -129,4 +133,3 @@ describe("toggleCompletedOnTask()", () => { expect(todos).toEqual(todosBeforeToggle); }); }); - From d9be1133edafc6d03b77e5addec99d63213419f9 Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Mon, 23 Nov 2026 18:34:27 +0000 Subject: [PATCH 6/8] Add test for deleting completed tasks in todos.test.mjs --- Sprint-3/todo-list/todos.test.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/todo-list/todos.test.mjs b/Sprint-3/todo-list/todos.test.mjs index b9b63b2d86..bdfb40cfaf 100644 --- a/Sprint-3/todo-list/todos.test.mjs +++ b/Sprint-3/todo-list/todos.test.mjs @@ -94,6 +94,7 @@ describe("deleteTask()", () => { const todos = createMockTodos(); const todosBeforeDeletionCompleted = createMockTodos(); Todos.deleteCompleted(todos); + expect(todos).toHaveLength(2); expect(todos[0]).toEqual(todosBeforeDeletionCompleted[1]); expect(todos[1]).toEqual(todosBeforeDeletionCompleted[3]); }); From 35905884714ecff7c4e02680d34bf6cee63af13d Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Mon, 23 Nov 2026 18:34:39 +0000 Subject: [PATCH 7/8] Clarify comment in toggleCompletedOnTask function to enhance code readability --- Sprint-3/todo-list/todos.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/todo-list/todos.mjs b/Sprint-3/todo-list/todos.mjs index 35b3f304f1..f29277bf48 100644 --- a/Sprint-3/todo-list/todos.mjs +++ b/Sprint-3/todo-list/todos.mjs @@ -24,7 +24,7 @@ export function deleteTask(todos, taskIndex) { // Toggle the "completed" property of todos[taskIndex] if the task exists. export function toggleCompletedOnTask(todos, taskIndex) { if (todos[taskIndex]) { - todos[taskIndex].completed = !todos[taskIndex].completed; // changes false to true + todos[taskIndex].completed = !todos[taskIndex].completed; // Toggle completed status between true and false } } From 1ad5e63ad5852af47938eefab18e2085d379038f Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Sun, 29 Nov 2026 15:06:38 +0000 Subject: [PATCH 8/8] Add tests for deleteCompleted function to verify task deletion behavior --- Sprint-3/todo-list/todos.test.mjs | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Sprint-3/todo-list/todos.test.mjs b/Sprint-3/todo-list/todos.test.mjs index bdfb40cfaf..eb5c7b1f4e 100644 --- a/Sprint-3/todo-list/todos.test.mjs +++ b/Sprint-3/todo-list/todos.test.mjs @@ -100,6 +100,45 @@ describe("deleteTask()", () => { }); }); +describe("deleteCompleted", () => { + test("Should remove completed tasks and keep only incomplete tasks", () => { + const todos = createMockTodos(); + const todosBeforeDeletionCompleted = createMockTodos(); + + Todos.deleteCompleted(todos); + + expect(todos).toHaveLength(2); + expect(todos[0]).toEqual(todosBeforeDeletionCompleted[1]); + expect(todos[1]).toEqual(todosBeforeDeletionCompleted[3]); + }); + + test("Should return an empty array when all tasks are completed", () => { + const todos = [ + { task: "Task 1 description", completed: true }, + { task: "Task 2 description", completed: true }, + ]; + + Todos.deleteCompleted(todos); + + expect(todos).toHaveLength(0); + }); + + test("Should keep all tasks unchanged when none are completed", () => { + const todos = [ + { task: "Task 1 description", completed: false }, + { task: "Task 2 description", completed: false }, + ]; + + Todos.deleteCompleted(todos); + + expect(todos).toHaveLength(2); + expect(todos).toEqual([ + { task: "Task 1 description", completed: false }, + { task: "Task 2 description", completed: false }, + ]); + }); +}); + describe("toggleCompletedOnTask()", () => { test("Expect the 'completed' property to toggle on an existing task", () => { const todos = createMockTodos();