Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sprint-3/todo-list/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ <h1>My ToDo List</h1>
<ul id="todo-list" class="todo-list">
</ul>

<div class="mass-deletion-container">
<button id="mass-deletion-btn">Delete completed tasks</button>
</div>

<!--
This is a template for the To-do list item.
It can simplify the creation of list item node in JS script.
Expand Down
9 changes: 8 additions & 1 deletion Sprint-3/todo-list/script.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,11 @@ function createListItem(todo, index) {
});

return li;
}
}

const massDeletionBtn = document.getElementById("mass-deletion-btn");

massDeletionBtn.addEventListener("click", () => {
Todos.deleteCompleted(todos);
render();
})
11 changes: 10 additions & 1 deletion Sprint-3/todo-list/todos.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ export function toggleCompletedOnTask(todos, taskIndex) {
if (todos[taskIndex]) {
todos[taskIndex].completed = !todos[taskIndex].completed;
}
}
}

export function deleteCompleted(todos){
for (let i=0; i<todos.length; i++){
if (todos[i].completed){
deleteTask(todos, i);
i--;
}
}
};
18 changes: 18 additions & 0 deletions Sprint-3/todo-list/todos.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,21 @@ describe("toggleCompletedOnTask()", () => {
});
});

describe("deleteCompleted()", () => {
test("Delete all completed tasks", () => {
const todos = createMockTodos();
const todosBeforeDeletion = createMockTodos();
let lengthAfterDeletion = 0;
for(todo of todos){

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when this test reaches for (todo of todos) in an ES module, where todo has not been declared?

To "like" or "dislike" this comment, please follow this link

if(todo.completed === false){
lengthAfterDeletion++;
}
}
Todos.deleteCompleted(todos);

expect(todos).toHaveLength(lengthAfterDeletion);

expect(todos[0]).toEqual(todosBeforeDeletion[1]);
expect(todos[1]).toEqual(todosBeforeDeletion[3]);
});
});
Loading