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
1 change: 1 addition & 0 deletions Sprint-3/todo-list/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ <h1>My ToDo List</h1>

<ul id="todo-list" class="todo-list">
</ul>
<button id="delete-completed-btn" class="del-completed-btn">Delete completed tasks</button>

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

return li;
}
}

document.getElementById("delete-completed-btn").addEventListener("click", () => {
Todos.deleteCompleted(todos);
render();
});
11 changes: 11 additions & 0 deletions Sprint-3/todo-list/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ h1 {
color: red;
}

.del-completed-btn {
width: 100%;
height: 40px;
font-size: 16px;
background-color: #ef2121;
color: rgb(255, 255, 255);
border: none;
border-radius: 6px;
cursor: pointer;
}

.todo-item.completed .description {
text-decoration: line-through;
color: gray;
Expand Down
10 changes: 10 additions & 0 deletions Sprint-3/todo-list/todos.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@ export function toggleCompletedOnTask(todos, taskIndex) {
if (todos[taskIndex]) {
todos[taskIndex].completed = !todos[taskIndex].completed;
}
}

// Delete all completed tasks from the list
export function deleteCompleted(todoList) {
// creating filtered object that holds not completed tasks
let filteredList = todoList.filter((element) => element.completed === false);
// removing all properties from todoList(todos)
todoList.length = 0;
// adding filtered tasks to todoList(todos)
todoList.push(...filteredList);
}
13 changes: 13 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,16 @@ describe("toggleCompletedOnTask()", () => {
});
});


describe("deleteCompletedTasks()", () => {

test("Delete 2 Completed task", () => {
const todos = createMockTodos();
const todosBeforeDeletion = createMockTodos();
const lengthBeforeDeletion = todos.length;
Todos.deleteCompleted(todos);

expect(todos).toHaveLength(lengthBeforeDeletion - 2);
});
Comment on lines +136 to +143
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a good start.
You could also check if the remaining two elements are actually the non-completed tasks.

Well, the more comprehensive our unit tests are, the higher the quality of our software.

No change required in this exercise.


});
Loading