Toggle All Todos Between Completed and Not Completed
Story: As a user, I want to be able to toggle all todos between completed and not completed statuses.
MainSection actions
It should create an action to toggle all todos between completed and not completed
Write a test.
diff --git a/tests/todomvc/actions.spec.js b/tests/todomvc/actions.spec.js
index 367d6ad..2ae2dec 100644
--- a/tests/todomvc/actions.spec.js
+++ b/tests/todomvc/actions.spec.js
@@ -37,5 +37,13 @@ describe('TodoMVC actions', () => {
};
expect(todomvc.actions.toggleCompleteOneTodo('my_id')).to.deep.equal(expectedAction)
+ });
+
+ it('Should create an action to toggle all todos between completed and not completed', () => {
+ const expectedAction = {
+ type: todomvc.types.TOGGLE_COMPLETE_ALL, all_completed: true
+ };
+
+ expect(todomvc.actions.toggleCompleteAllTodos()).to.deep.equal(expectedAction)
})
});
(END)Run the test and watch it fail.
Write the code to make the test pass.
Run the test and watch it pass.
Commit changes.
TodoMVC reducer
It should handle TOGGLE_COMPLETE_ALL todo
Write the test.
Run the test and watch it fail.
Write the code to make the test pass.
Run the test and watch it pass.
Commit changes.
Header component
It should render correctly
It should have a toggle all complete status checkbox
Write the test.
Run the test and watch it fail.
Write the code to make the test pass.
Run the test and watch it pass.
Commit changes.
It should behave correctly
It should call toggleCompleteAllTodos() when the complete all status checkbox is changed
Write the test.
Run the test and watch it fail.
Write the code to make the test pass, but also let's immediately work on the required prop warning regression.
Run the test and watch it pass.
Commit changes.
Run It!
Now let's see what this looks like.
Open http://localhost:4000 in your web browser.
When the page loads you will be able to see a new, toggle "completed" status, checkbox appear. Try creating a couple of todos and set their completed statuses randomly. Now make them all completed or not completed by using the new checkbox.

Last updated
Was this helpful?