Repository navigation
London | 26-ITP-Sep | Shirin Panahian| Sprint 3 | Build a todo-list app #1572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a3f4fe0
479e34c
fddbd23
9a7527c
bba37fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,51 @@ | ||
| <!DOCTYPE html> | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
| <title>ToDo List</title> | ||
| <link rel="stylesheet" href="style.css" /> | ||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>ToDo List</title> | ||
| <link rel="stylesheet" href="style.css" /> | ||
| <link | ||
| href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" | ||
| rel="stylesheet" | ||
| /> | ||
|
|
||
| <script type="module" src="script.mjs"></script> | ||
| </head> | ||
| <body> | ||
| <div class="todo-container"> | ||
| <h1>My ToDo List</h1> | ||
| <script type="module" src="script.mjs"></script> | ||
| </head> | ||
| <body> | ||
| <div class="todo-container"> | ||
| <h1>My ToDo List</h1> | ||
|
|
||
| <div class="todo-input"> | ||
| <input type="text" id="new-task-input" placeholder="Enter a new task..." /> | ||
| <button id="add-task-btn">Add</button> | ||
| </div> | ||
| <div class="todo-input"> | ||
| <input | ||
| type="text" | ||
| id="new-task-input" | ||
| placeholder="Enter a new task..." | ||
| /> | ||
| <button id="add-task-btn">Add</button> | ||
| <button id="Delete-completed-tasks">Delete completed tasks</button> | ||
| </div> | ||
|
|
||
| <ul id="todo-list" class="todo-list"> | ||
| </ul> | ||
| <ul id="todo-list" class="todo-list"></ul> | ||
|
|
||
| <!-- | ||
| <!-- | ||
| This is a template for the To-do list item. | ||
| It can simplify the creation of list item node in JS script. | ||
| --> | ||
| <template id="todo-item-template"> | ||
| <li class="todo-item"> <!-- include class "completed" if the task completed state is true --> | ||
| <span class="description">Task description</span> | ||
| <div class="actions"> | ||
| <button class="complete-btn"><span class="fa-solid fa-check" aria-hidden="true"></span></button> | ||
| <button class="delete-btn"><span class="fa-solid fa-trash" aria-hidden="true"></span></button> | ||
| </div> | ||
| </li> | ||
| </template> | ||
|
|
||
| </div> | ||
| </body> | ||
| <template id="todo-item-template"> | ||
| <li class="todo-item"> | ||
| <!-- include class "completed" if the task completed state is true --> | ||
| <span class="description">Task description</span> | ||
| <div class="actions"> | ||
| <button class="complete-btn"> | ||
| <span class="fa-solid fa-check" aria-hidden="true"></span> | ||
| </button> | ||
| <button class="delete-btn"> | ||
| <span class="fa-solid fa-trash" aria-hidden="true"></span> | ||
| </button> | ||
| </div> | ||
| </li> | ||
| </template> | ||
| </div> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
|
@@ -41,8 +40,22 @@ describe("addTask()", () => { | |
| }); | ||
| }); | ||
|
|
||
| describe("deleteTask()", () => { | ||
| describe("deleteCompleted()", () => { | ||
| test("removes all completed ToDos from the given list.", () => { | ||
| const todos = createMockTodos(); | ||
| const lengthBeforeDeletion = todos.length; | ||
| let lengthOfCompletedTask = 0; | ||
| for (let item of todos) { | ||
| if (item.completed === true) { | ||
| lengthOfCompletedTask += 1; | ||
| } | ||
| } | ||
| Todos.deleteCompleted(todos); | ||
| expect(todos).toEqual(todos.filter((todos) => !todos.completed)); | ||
| }); | ||
|
Comment on lines
+44
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case is correct. How about when all tasks completed or when all tasks incomplete? Please add those two tests as well. Thank you.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the suggestion! I've added two additional test cases to cover both edge cases: when all tasks are completed (the list should become empty) and when all tasks are incomplete (the list should remain unchanged). |
||
| }); | ||
|
|
||
| describe("deleteTask()", () => { | ||
| test("Delete the first task", () => { | ||
| const todos = createMockTodos(); | ||
| const todosBeforeDeletion = createMockTodos(); | ||
|
|
@@ -53,7 +66,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 +79,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 +92,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 +107,6 @@ describe("deleteTask()", () => { | |
| }); | ||
|
|
||
| describe("toggleCompletedOnTask()", () => { | ||
|
|
||
| test("Expect the 'completed' property to toggle on an existing task", () => { | ||
| const todos = createMockTodos(); | ||
| const taskIndex = 1; | ||
|
|
@@ -111,13 +123,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(); | ||
|
|
@@ -128,5 +139,29 @@ describe("toggleCompletedOnTask()", () => { | |
| Todos.toggleCompletedOnTask(todos, -1); | ||
| expect(todos).toEqual(todosBeforeToggle); | ||
| }); | ||
| }); | ||
|
|
||
| test("removes all ToDos when all tasks are completed.", () => { | ||
| const todos = [ | ||
| { task: "Task 1", completed: true }, | ||
| { task: "Task 2", completed: true }, | ||
| { task: "Task 3", completed: true }, | ||
| ]; | ||
|
|
||
| Todos.deleteCompleted(todos); | ||
|
|
||
| expect(todos).toEqual([]); | ||
| }); | ||
| test("keeps all ToDos when no tasks are completed.", () => { | ||
| const todos = [ | ||
| { task: "Task 1", completed: false }, | ||
| { task: "Task 2", completed: false }, | ||
| { task: "Task 3", completed: false }, | ||
| ]; | ||
|
|
||
| const todosBeforeDeletion = [...todos]; | ||
|
|
||
| Todos.deleteCompleted(todos); | ||
|
|
||
| expect(todos).toEqual(todosBeforeDeletion); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for your future reference, instead of using
.quertSelector("#, it would be clearer to use.getElementById(". Thank you.