Repository navigation
Conversation
| }); | ||
| }); | ||
|
|
||
| test("should return the tasks that are not completed", () => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I have deleted the return array and renamed the test with appropriate name to the test.
|
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. |
…value by commenting out my test fails
mayowaolokun
left a comment
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
Nice work adding the delete completed button.
| } | ||
| } No newline at end of file | ||
| } | ||
| export function deleteCompleted(todos) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I have made the change as advised. But please let me if you have something different in mind. Thank you for your support!
There was a problem hiding this comment.
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.
| document | ||
| .getElementById("delete-complete-btn") | ||
| .addEventListener("click", () => { | ||
| Todos.deleteCompleted(todos); | ||
| render(); | ||
| }); |
There was a problem hiding this comment.
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.
| expect(todos).toEqual(todosBeforeToggle); | ||
|
|
||
| Todos.toggleCompletedOnTask(todos, -1); | ||
| // Todos.toggleCompletedOnTask(todos, -1); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I have sorted it out. I only did it to understand how things are working. Thank you!
| const todosBeforeDeleteComplet = createMockTodos(); | ||
| const lengthBeforDeleteComplete = todos.length; |
There was a problem hiding this comment.
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?
| const todosBeforeDeleteComplet = createMockTodos(); | ||
| const lengthBeforDeleteComplete = todos.length; | ||
| Todos.deleteCompleted(todos); | ||
| expect(todos).toHaveLength(lengthBeforDeleteComplete - 2); |
There was a problem hiding this comment.
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]); | ||
| }); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Thank you, both cases are now covered.
| }); | ||
| }); | ||
|
|
||
| test("should remove completed tasks from the array", () => { |
There was a problem hiding this comment.
Good to see a test added for deleteCompleted. I like that you check both the length and which tasks remain.
mayowaolokun
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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]); | ||
| }); |
There was a problem hiding this comment.
Thank you, both cases are now covered.
Learners, PR Template
Self checklist
Task code
CYF-1097
Changelist
I have met all provided requirements.
Questions