From 02e1665102a4c801eb65c18d23ccc5dbcc34b32b Mon Sep 17 00:00:00 2001 From: Brian Yorachi Date: Mon, 16 Nov 2026 15:52:09 +0000 Subject: [PATCH 1/6] test: cover todo deadline and bulk deletion --- Sprint-3/todo-list/todos.test.mjs | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Sprint-3/todo-list/todos.test.mjs b/Sprint-3/todo-list/todos.test.mjs index bae7ae491..8adf53a73 100644 --- a/Sprint-3/todo-list/todos.test.mjs +++ b/Sprint-3/todo-list/todos.test.mjs @@ -39,6 +39,53 @@ describe("addTask()", () => { // New task should be appended to the todos expect(todos[todos.length - 1]).toEqual(theTask); }); + + test("stores a deadline when provided", () => { + const todos = []; + + Todos.addTask(todos, "Submit coursework", false, "2026-12-01"); + + expect(todos).toEqual([ + { + task: "Submit coursework", + completed: false, + deadline: "2026-12-01", + }, + ]); + }); + + test("omits a deadline when none is provided", () => { + const todos = []; + + Todos.addTask(todos, "Submit coursework"); + + expect(todos).toEqual([{ task: "Submit coursework", completed: false }]); + }); +}); + +describe("deleteCompleted()", () => { + test("removes all completed tasks and preserves incomplete task order", () => { + const todos = createMockTodos(); + + Todos.deleteCompleted(todos); + + expect(todos).toEqual([ + { task: "Task 2 description", completed: false }, + { task: "Task 4 description", completed: false }, + ]); + }); + + test("leaves the list unchanged when no tasks are completed", () => { + const todos = [ + { task: "Task 1 description", completed: false }, + { task: "Task 2 description", completed: false }, + ]; + const todosBeforeDeletion = [...todos]; + + Todos.deleteCompleted(todos); + + expect(todos).toEqual(todosBeforeDeletion); + }); }); describe("deleteTask()", () => { From e893b54a9a3b9204227e8aaede3e54d092cd88d3 Mon Sep 17 00:00:00 2001 From: Brian Yorachi Date: Mon, 16 Nov 2026 15:52:18 +0000 Subject: [PATCH 2/6] feat: add todo deadlines and completed cleanup --- Sprint-3/todo-list/todos.mjs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Sprint-3/todo-list/todos.mjs b/Sprint-3/todo-list/todos.mjs index f17ab6a25..369c73b7c 100644 --- a/Sprint-3/todo-list/todos.mjs +++ b/Sprint-3/todo-list/todos.mjs @@ -3,15 +3,28 @@ the following manner: [ - { task: "Description of task 1", completed: false}, + { task: "Description of task 1", completed: false, deadline: "2026-12-01"}, { task: "Description of task 2", completed: true} ] */ // 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 = "") { + const todo = { task, completed }; + if (deadline) { + todo.deadline = deadline; + } + todos.push(todo); +} + +// Delete all completed tasks from todos[] +export function deleteCompleted(todos) { + for (let index = todos.length - 1; index >= 0; index--) { + if (todos[index].completed) { + todos.splice(index, 1); + } + } } // Delete todos[taskIndex] if it exists From 3d05c37224c9180410db853f32617f11abe941d4 Mon Sep 17 00:00:00 2001 From: Brian Yorachi Date: Mon, 16 Nov 2026 15:52:26 +0000 Subject: [PATCH 3/6] test: cover todo list interactions and deadlines --- Sprint-3/todo-list/script.test.mjs | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Sprint-3/todo-list/script.test.mjs diff --git a/Sprint-3/todo-list/script.test.mjs b/Sprint-3/todo-list/script.test.mjs new file mode 100644 index 000000000..f06af6b0e --- /dev/null +++ b/Sprint-3/todo-list/script.test.mjs @@ -0,0 +1,63 @@ +/** + * @jest-environment jsdom + */ + +import { readFileSync } from "node:fs"; + +test("renders and manages todos with optional deadlines", async () => { + const html = readFileSync(new URL("./index.html", import.meta.url), "utf8"); + const appDocument = new DOMParser().parseFromString(html, "text/html"); + document.body.innerHTML = appDocument.body.innerHTML; + + await import("./script.mjs"); + window.dispatchEvent(new Event("load")); + + const list = document.getElementById("todo-list"); + const deadlineInput = document.getElementById("new-task-deadline"); + const deleteCompletedButton = document.getElementById( + "delete-completed-btn" + ); + const taskInput = document.getElementById("new-task-input"); + const findTodo = (task) => + [...list.querySelectorAll(".todo-item")].find( + (item) => item.querySelector(".description").textContent === task + ); + const addTodo = (task, deadline = "") => { + taskInput.value = task; + deadlineInput.value = deadline; + document.getElementById("add-task-btn").click(); + }; + + expect(deadlineInput).not.toBeNull(); + expect(deadlineInput.type).toBe("date"); + expect(deleteCompletedButton).not.toBeNull(); + + expect(findTodo("Wash the dishes")).not.toBeUndefined(); + expect(findTodo("Do the shopping").classList.contains("completed")).toBe(true); + expect( + findTodo("Wash the dishes").querySelector(".deadline").textContent + ).toBe(""); + + addTodo(" ", "2026-12-01"); + expect(list.querySelectorAll(".todo-item")).toHaveLength(2); + + addTodo("Submit coursework", "2026-12-01"); + expect( + findTodo("Submit coursework").querySelector(".deadline").textContent + ).toBe("2026-12-01"); + + findTodo("Wash the dishes").querySelector(".complete-btn").click(); + expect(findTodo("Wash the dishes").classList.contains("completed")).toBe(true); + + findTodo("Submit coursework").querySelector(".delete-btn").click(); + expect(findTodo("Submit coursework")).toBeUndefined(); + + addTodo("Prepare demo", "2026-12-02"); + deleteCompletedButton.click(); + + expect(list.querySelectorAll(".todo-item")).toHaveLength(1); + expect( + findTodo("Prepare demo").querySelector(".deadline").textContent + ).toBe("2026-12-02"); + expect(findTodo("Prepare demo").classList.contains("completed")).toBe(false); +}); From 52fdc6a99fd1fd2d33d9f43a7ff0c3dfbac18349 Mon Sep 17 00:00:00 2001 From: Brian Yorachi Date: Mon, 16 Nov 2026 15:52:36 +0000 Subject: [PATCH 4/6] feat: add todo deadline and cleanup controls --- Sprint-3/todo-list/index.html | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-3/todo-list/index.html b/Sprint-3/todo-list/index.html index 4d12c4654..b8c060215 100644 --- a/Sprint-3/todo-list/index.html +++ b/Sprint-3/todo-list/index.html @@ -18,6 +18,15 @@

My ToDo List

+
+ + +
+ +
+ +
+
@@ -28,6 +37,7 @@

My ToDo List