From 1e82730d0380b793d7bb5fd3e69561ec03747f4d Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Mon, 15 Dec 2025 21:47:52 +0100 Subject: [PATCH 1/5] add new additional test --- Sprint-3/todo-list/todos.test.mjs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Sprint-3/todo-list/todos.test.mjs b/Sprint-3/todo-list/todos.test.mjs index d6bf96414..a7e6cd9b9 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 = [...todos]; @@ -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 = [...todos]; 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 = [...todos]; @@ -130,3 +126,14 @@ describe("toggleCompletedOnTask()", () => { }); }); +describe("deleteCompleted()", () => { + test("Deletes all completed tasks", () => { + const todos = createMockTodos(); + Todos.deleteCompleted(todos); + + // Only incomplete tasks should remain + expect(todos).toHaveLength(2); // + expect(todos[0].completed).toBe(false); + expect(todos[1].completed).toBe(false); + }); +}); From 10644cc547b09aa4d6bc1e3432d6226881ac4334 Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Mon, 15 Dec 2025 21:49:05 +0100 Subject: [PATCH 2/5] add deletecompleted function --- Sprint-3/todo-list/todos.mjs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Sprint-3/todo-list/todos.mjs b/Sprint-3/todo-list/todos.mjs index f17ab6a25..99131a3c4 100644 --- a/Sprint-3/todo-list/todos.mjs +++ b/Sprint-3/todo-list/todos.mjs @@ -10,8 +10,8 @@ */ // Append a new task to todos[] -export function addTask(todos, task, completed = false) { - todos.push({ task, completed }); +export function addTask(todos, task, completed = false, deadline = "") { + todos.push({ task, completed, deadline }); } // Delete todos[taskIndex] if it exists @@ -26,4 +26,10 @@ export function toggleCompletedOnTask(todos, taskIndex) { if (todos[taskIndex]) { todos[taskIndex].completed = !todos[taskIndex].completed; } -} \ No newline at end of file +} +// this function delete all completed todos +export function deleteCompleted(todos) { + const incompleteTodos = todos.filter((todo) => !todo.completed); + todos.length = 0; + todos.push(...incompleteTodos); +} From 5a9af6c9f92a7d8ba2ca1856514bba423b6d4a83 Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Mon, 15 Dec 2025 21:50:32 +0100 Subject: [PATCH 3/5] modify some details --- Sprint-3/todo-list/script.mjs | 39 ++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/Sprint-3/todo-list/script.mjs b/Sprint-3/todo-list/script.mjs index ba0b2ceae..59885f354 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,24 +9,37 @@ 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", deleteCompletedTodos); }); +// to call the function from +function deleteCompletedTodos() { + 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"); + const deadlineInput = document.getElementById("new-task-deadline"); const task = taskInput.value.trim(); + const deadline = deadlineInput.value; + if (task) { - Todos.addTask(todos, task, false); + Todos.addTask(todos, task, false, deadline); render(); } taskInput.value = ""; + deadlineInput.value = ""; } // Note: @@ -45,12 +58,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 @@ -58,19 +70,26 @@ function createListItem(todo, index) { const li = todoListItemTemplate.cloneNode(true); // true => Do a deep copy of the node li.querySelector(".description").textContent = todo.task; + + if (todo.deadline) { + const deadlineSpan = document.createElement("span"); + deadlineSpan.classList.add("deadline"); + deadlineSpan.textContent = `Deadline: ${todo.deadline}`; + li.querySelector(".description").appendChild(deadlineSpan); + } if (todo.completed) { 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 6ca129b63063004121fd4bff6286be2ab5b56d57 Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Mon, 15 Dec 2025 21:51:02 +0100 Subject: [PATCH 4/5] modify deadline css --- Sprint-3/todo-list/style.css | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-3/todo-list/style.css b/Sprint-3/todo-list/style.css index 535e91227..2514ddaf2 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,8 @@ h1 { text-decoration: line-through; color: gray; } +.deadline { + font-size: 12px; + color: #888; + margin-left: 10px; +} From 187431a792b2e895ea348173db307cf40959eb9d Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Mon, 15 Dec 2025 21:51:34 +0100 Subject: [PATCH 5/5] add button --- Sprint-3/todo-list/index.html | 72 ++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/Sprint-3/todo-list/index.html b/Sprint-3/todo-list/index.html index 4d12c4654..d762cb248 100644 --- a/Sprint-3/todo-list/index.html +++ b/Sprint-3/todo-list/index.html @@ -1,40 +1,52 @@ - - - - ToDo List - - + + + + ToDo List + + - - - -
    -

    My ToDo List

    + + + +
    +

    My ToDo List

    -
    - - -
    +
    + + + +
    -
      -
    +
      - - - -
      - + + +
      +