Presenting two sections
As we have already refactored to a diffable data source, supporting two sections in the table view is quite easy. Follow these steps to implement two sections:
- As always, we need to start with a failing test. Add the following test to
ToDoItemsListViewControllerTests
:// ToDoItemsListViewControllerTests.swift func test_numberOfSections_shouldReturnTwo() { var doneItem = ToDoItem(title: "dummy 2") doneItem.done = true toDoItemStoreMock.itemPublisher .send([ToDoItem(title: "dummy 1"), doneItem]) let result = sut.tableView.numberOfSections XCTAssertEqual(result, 2) }
In this test, we set a to-do item and a done item to the table view using toDoItemStoreMock
. The name of the test method should also include what the preconditions of the tests are. We use a shorter name in the book because...