Skip to content

London | 26-ITP-Sep | Maharit Belai | Sprint 3 | Todo-list - #1574

Open
MaharitB wants to merge 11 commits into
CodeYourFuture:mainfrom
MaharitB:todo-list
Open

MaharitB wants to merge 11 commits into
CodeYourFuture:mainfrom
MaharitB:todo-list

Conversation

@MaharitB

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Task code

CYF-1097

Changelist

I have met all provided requirements.

Questions

@MaharitB MaharitB added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 22, 2026
Comment thread Sprint-3/todo-list/todos.test.mjs Outdated
});
});

test("should return the tasks that are not completed", () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How does this test verify the tasks returned by deleteCompleted, given that it ignores the function's return value?

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have deleted the return array and renamed the test with appropriate name to the test.

@cyf-ai-code-reviewer cyf-ai-code-reviewer Bot added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 22, 2026
@cyf-ai-code-reviewer

Copy link
Copy Markdown

The CYF AI review has left comments. It will only review a PR one time. When you have addressed these comments, please request review again and a volunteer will take a look.

@MaharitB MaharitB added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 22, 2026
@MaharitB MaharitB added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 22, 2026
@mayowaolokun mayowaolokun added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 23, 2026

@mayowaolokun mayowaolokun left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for this. The delete completed feature works end to end across the HTML, script, todos module and tests, and it's good to see tests added alongside it.
Please revisit how deleteCompleted removes items so it is easier for others to maintain, check the commented out line in the toggle test since that assertion isn't currently testing anything, and add tests for when no tasks, or all tasks, are completed. It would also help to tidy the variable names in the new test and your formatting setup so the diff only shows your real changes. Nice work overall.

placeholder="Enter a new task..."
/>
<button id="add-task-btn">Add</button>
<button id="delete-complete-btn">Delete completed Task</button>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice work adding the delete completed button.

}
} No newline at end of file
}
export function deleteCompleted(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.

Nice work with the delete completed behaviour. Have a look at how the function removes items while it is looping over the same list.
Could you explain why i-- is needed in line (34) here? Would a teammate reading this quickly understand it, and is there a simpler way to express 'remove only the completed tasks' that doesn't depend on that adjustment?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

i-- ,its work here is to make sure we check all the indices after deletion. Since the deleted index's element will be leaving empty space the next element will move to the empty index which will leave it unchecked. I have tried to use filter before but it creates a new array. I will give it a try.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have made the change as advised. But please let me if you have something different in mind. Thank you for your support!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thank you; your explanation of i-- was spot on, and the new version is much easier to read. I like that you kept the same array rather than returning a new one, since the rest of the code relies on that.

Comment on lines +16 to +21
document
.getElementById("delete-complete-btn")
.addEventListener("click", () => {
Todos.deleteCompleted(todos);
render();
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good to see the delete completed button connected here and the list re-rendered afterwards. This matches how you handled the other buttons. Once the tests are in, it would be worth checking the behaviour when there are no completed tasks, and when every task is completed.

Comment thread Sprint-3/todo-list/todos.test.mjs Outdated
expect(todos).toEqual(todosBeforeToggle);

Todos.toggleCompletedOnTask(todos, -1);
// Todos.toggleCompletedOnTask(todos, -1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I noticed this call to toggleCompletedOnTask with -1 has been commented out, but the expect below it is still active. As it stands, that assertion would pass whether or not the function was called. Was this intentional? If the case no longer applies, it would be cleaner to remove the line and the check. If it is failing, it may be worth understanding why rather than disabling it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have sorted it out. I only did it to understand how things are working. Thank you!

Comment thread Sprint-3/todo-list/todos.test.mjs Outdated
Comment on lines +129 to +130
const todosBeforeDeleteComplet = createMockTodos();
const lengthBeforDeleteComplete = todos.length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A couple of variable names look like they have typos, such as todosBeforeDeleteComplet and lengthBeforDeleteComplete. Could you tidy these so they are easy to read and search for?

Comment thread Sprint-3/todo-list/todos.test.mjs Outdated
const todosBeforeDeleteComplet = createMockTodos();
const lengthBeforDeleteComplete = todos.length;
Todos.deleteCompleted(todos);
expect(todos).toHaveLength(lengthBeforDeleteComplete - 2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The - 2 relies on knowing how many completed tasks are in the mock data. Would a reader understand where that number comes from? Is there a way to make the link to the data clearer?

expect(todos).toHaveLength(lengthBeforDeleteComplete - 2);
expect(todos[0]).toEqual(todosBeforeDeleteComplet[1]);
expect(todos[1]).toEqual(todosBeforeDeleteComplet[3]);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This covers the main case well. Earlier I raised how the function behaves when there are no completed tasks, so have a think about which other situations are worth a test. For example, what should happen if nothing is completed, or if everything is?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thank you, both cases are now covered.

});
});

test("should remove completed tasks from the array", () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good to see a test added for deleteCompleted. I like that you check both the length and which tasks remain.

@mayowaolokun mayowaolokun added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Nov 24, 2026
@MaharitB MaharitB added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 25, 2026
@mayowaolokun mayowaolokun added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 26, 2026

@mayowaolokun mayowaolokun left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the updates. The deleteCompleted rewrite is much easier to read, and it's good to see the extra test cases added. Please look at the length check in the first deleteCompleted test, since it currently compares the list with its own length and so can't fail. It would also help to remove the unused variables, fix the remaining name typo, and group these tests in a describe block like the others. Nice progress.

test("should remove completed tasks from the array", () => {
const todos = createMockTodos();
const todosBeforeDeleteComplete = createMockTodos();
const lengthBeforDeleteComplete = todos.length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

lengthBeforDeleteComplete still has a small typo, and it no longer seems to be used. Could you tidy or remove it?

Todos.deleteCompleted(todos);

const lengthAfterDeleteComplete = todos.length;
expect(todos).toHaveLength(lengthAfterDeleteComplete);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for adding these tests. On this line, the expected length is measured after deleteCompleted has run, so the check compares the list with itself and would pass even if the wrong number of tasks were removed. How could the expected length be worked out independently of the function's result?

todos = todos.filter((task) => task.completed);
const todosBeforeDeleteComplete = [];
todosBeforeDeleteComplete.push(...todos);
const LengthBeforeDeleteComplete = todos.length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

todosBeforeDeleteComplete and LengthBeforeDeleteComplete aren't used in this test, and the second has a capital L, unlike the other names. Could you remove them or use them?

expect(todos).toHaveLength(lengthBeforDeleteComplete - 2);
expect(todos[0]).toEqual(todosBeforeDeleteComplet[1]);
expect(todos[1]).toEqual(todosBeforeDeleteComplet[3]);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thank you, both cases are now covered.

@mayowaolokun mayowaolokun added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants