Skip to content

Commit 9994060

Browse files
committed
Fixes & tests cell deletion in TableViewDataSource
1 parent 1ba4ee5 commit 9994060

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Sourcing/TableViewDataSource.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ final public class TableViewDataSource<Object>: NSObject, UITableViewDataSource,
143143
public func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
144144
if let dataModificator = dataModificator, editingStyle == .delete {
145145
dataModificator.deleteItem(at: indexPath, triggerdByTableView: true)
146+
tableView.deleteRows(at: [indexPath], with: .automatic)
146147
}
147148
}
148149

SourcingTests/TableViewDataSource_SingleCellTest.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ class TableViewDataSourceSingleCellTest: XCTestCase {
387387
let dataSource = TableViewDataSource(tableView: tableViewMock, dataProvider: dataProvider, cell: cell)
388388

389389
//When
390-
let canDelete = dataSource.tableView(UITableView(), canEditRowAt: IndexPath(row: 0, section: 0))
390+
let canDelete = dataSource.tableView(tableViewMock, canEditRowAt: IndexPath(row: 0, section: 0))
391391

392392
//Then
393393
XCTAssertFalse(canDelete)
@@ -399,10 +399,11 @@ class TableViewDataSourceSingleCellTest: XCTestCase {
399399
let deletedIndexPath = IndexPath(row: 0, section: 0)
400400

401401
//When
402-
dataSource.tableView(UITableView(), commit: .delete, forRowAt: deletedIndexPath)
402+
dataSource.tableView(tableViewMock, commit: .delete, forRowAt: deletedIndexPath)
403403

404404
//Then
405405
XCTAssertEqual(dataModificator.deletedIndexPath, deletedIndexPath)
406+
XCTAssertEqual(tableViewMock.modifiedIndexPaths.deleted?.first, deletedIndexPath)
406407
XCTAssert(dataModificator.triggeredByUserInteraction ?? false)
407408
}
408409

0 commit comments

Comments
 (0)