added replca method to director
This commit is contained in:
parent
ef536b71b3
commit
721ba1972a
|
|
@ -274,6 +274,15 @@ extension TableDirector {
|
|||
return self
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
open func replaceSection(at index: Int, with section: TableSection) -> Self {
|
||||
|
||||
if index < sections.count {
|
||||
sections[index] = section
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
open func delete(sectionAt index: Int) -> Self {
|
||||
|
||||
|
|
|
|||
|
|
@ -190,4 +190,54 @@ class TabletTests: XCTestCase {
|
|||
|
||||
waitForExpectations(timeout: 1.0, handler: nil)
|
||||
}
|
||||
|
||||
func testReplaceSectionOnExistingIndex() {
|
||||
|
||||
let row1 = TableRow<TestTableViewCell>(item: TestData(title: "title1"))
|
||||
let row2 = TableRow<TestTableViewCell>(item: TestData(title: "title2"))
|
||||
|
||||
let section1 = TableSection(headerView: nil, footerView: nil, rows: nil)
|
||||
section1 += row1
|
||||
|
||||
let section2 = TableSection(headerView: nil, footerView: nil, rows: nil)
|
||||
section2 += row2
|
||||
|
||||
testController.tableDirector += section1
|
||||
testController.tableView.reloadData()
|
||||
|
||||
let cell = testController.tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as? TestTableViewCell
|
||||
XCTAssertTrue(cell?.textLabel?.text == "title1")
|
||||
|
||||
testController.tableDirector.replaceSection(at: 0, with: section2)
|
||||
testController.tableView.reloadData()
|
||||
|
||||
let cell1 = testController.tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as? TestTableViewCell
|
||||
XCTAssertTrue(cell1?.textLabel?.text == "title2")
|
||||
}
|
||||
|
||||
|
||||
func testReplaceSectionOnWrongIndex() {
|
||||
|
||||
let row1 = TableRow<TestTableViewCell>(item: TestData(title: "title1"))
|
||||
let row2 = TableRow<TestTableViewCell>(item: TestData(title: "title2"))
|
||||
|
||||
let section1 = TableSection(headerView: nil, footerView: nil, rows: nil)
|
||||
section1 += row1
|
||||
|
||||
let section2 = TableSection(headerView: nil, footerView: nil, rows: nil)
|
||||
section2 += row2
|
||||
|
||||
testController.tableDirector += section1
|
||||
testController.tableView.reloadData()
|
||||
|
||||
let cell = testController.tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as? TestTableViewCell
|
||||
XCTAssertTrue(cell?.textLabel?.text == "title1")
|
||||
|
||||
testController.tableDirector.replaceSection(at: 33, with: section2)
|
||||
testController.tableView.reloadData()
|
||||
|
||||
let cell1 = testController.tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as? TestTableViewCell
|
||||
XCTAssertTrue(cell1?.textLabel?.text == "title1")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue