bugfixes, add tests
This commit is contained in:
parent
1cf2bb1890
commit
fdd74a650c
Binary file not shown.
|
|
@ -71,7 +71,7 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate
|
|||
if let action = notification.object as? Action, indexPath = tableView.indexPathForCell(action.cell) {
|
||||
|
||||
let builder = builderAtIndexPath(indexPath)
|
||||
builder.0.invokeAction(.custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1, userInfo: action.userInfo)
|
||||
builder.0.invokeAction(.custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1, userInfo: notification.userInfo)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -95,10 +95,10 @@ public class TableRowBuilder<I, C where C: UITableViewCell> : RowBuilder {
|
|||
|
||||
// MARK: Triggers
|
||||
|
||||
public func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]? = nil) -> AnyObject? {
|
||||
public func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? {
|
||||
|
||||
if let action = actions[actionType.key] {
|
||||
return action.invoke(ActionData(cell: cell as? C, indexPath: indexPath, item: items[itemIndex], itemIndex: itemIndex))
|
||||
return action.invoke(ActionData(cell: cell as? C, indexPath: indexPath, item: items[itemIndex], itemIndex: itemIndex, userInfo: userInfo))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -144,14 +144,14 @@ public class TableConfigurableRowBuilder<I, C: ConfigurableCell where C.Item ==
|
|||
super.init(items: items, id: C.reusableIdentifier())
|
||||
}
|
||||
|
||||
public override func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]? = nil) -> AnyObject? {
|
||||
public override func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? {
|
||||
|
||||
switch actionType {
|
||||
case .configure:
|
||||
(cell as? C)?.configureWithItem(items[itemIndex])
|
||||
default: break
|
||||
}
|
||||
return super.invokeAction(actionType, cell: cell, indexPath: indexPath, itemIndex: itemIndex)
|
||||
return super.invokeAction(actionType, cell: cell, indexPath: indexPath, itemIndex: itemIndex, userInfo: userInfo)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,13 +57,15 @@ public class ActionData<I, C> {
|
|||
public let item: I
|
||||
public let itemIndex: Int
|
||||
public let indexPath: NSIndexPath
|
||||
|
||||
init(cell: C?, indexPath: NSIndexPath, item: I, itemIndex: Int) {
|
||||
|
||||
public let userInfo: [NSObject: AnyObject]?
|
||||
|
||||
init(cell: C?, indexPath: NSIndexPath, item: I, itemIndex: Int, userInfo: [NSObject: AnyObject]?) {
|
||||
|
||||
self.cell = cell
|
||||
self.indexPath = indexPath
|
||||
self.item = item
|
||||
self.itemIndex = itemIndex
|
||||
self.userInfo = userInfo
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -91,7 +93,7 @@ public class Action {
|
|||
|
||||
public func invoke() {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(TabletNotifications.CellAction, object: self)
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(TabletNotifications.CellAction, object: self, userInfo: userInfo)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Bucket
|
||||
type = "1"
|
||||
version = "2.0">
|
||||
</Bucket>
|
||||
|
|
@ -39,6 +39,9 @@ struct TestData {
|
|||
struct TestTableViewCellOptions {
|
||||
|
||||
static let ReusableIdentifier: String = "ReusableIdentifier"
|
||||
static let CellAction: String = "CellAction"
|
||||
static let CellActionUserInfoKey: String = "CellActionUserInfoKey"
|
||||
static let CellActionUserInfoValue: String = "CellActionUserInfoValue"
|
||||
static let EstimatedHeight: Float = 255
|
||||
}
|
||||
|
||||
|
|
@ -57,6 +60,10 @@ class TestTableViewCell: UITableViewCell, ConfigurableCell {
|
|||
func configureWithItem(item: Item) {
|
||||
textLabel?.text = item.title
|
||||
}
|
||||
|
||||
func raiseAction() {
|
||||
Action(key: TestTableViewCellOptions.CellAction, sender: self, userInfo: [TestTableViewCellOptions.CellActionUserInfoKey: TestTableViewCellOptions.CellActionUserInfoValue]).invoke()
|
||||
}
|
||||
}
|
||||
|
||||
class TabletTests: XCTestCase {
|
||||
|
|
@ -134,6 +141,7 @@ class TabletTests: XCTestCase {
|
|||
|
||||
testController.view.hidden = false
|
||||
testController.tableDirector += section
|
||||
testController.tableView.reloadData()
|
||||
|
||||
XCTAssertTrue(testController.tableView.dataSource?.numberOfSectionsInTableView?(testController.tableView) == 1, "Table view should have a section")
|
||||
XCTAssertTrue(testController.tableView.dataSource?.tableView(testController.tableView, numberOfRowsInSection: 0) == 1, "Table view should have certain number of rows in a section")
|
||||
|
|
@ -154,12 +162,39 @@ class TabletTests: XCTestCase {
|
|||
|
||||
testController.view.hidden = false
|
||||
testController.tableDirector += section
|
||||
testController.tableView.reloadData()
|
||||
|
||||
XCTAssertTrue(testController.tableView.dataSource?.numberOfSectionsInTableView?(testController.tableView) == 1, "Table view should have a section")
|
||||
XCTAssertTrue(testController.tableView.dataSource?.tableView(testController.tableView, numberOfRowsInSection: 0) == 1, "Table view should have certain number of rows in a section")
|
||||
|
||||
XCTAssertTrue(testController.tableView.delegate?.tableView?(testController.tableView, viewForHeaderInSection: 0) == sectionHeaderView)
|
||||
XCTAssertTrue(testController.tableView.delegate?.tableView?(testController.tableView, viewForFooterInSection: 0) == sectionFooterView)
|
||||
}
|
||||
|
||||
func testRowBuilderCustomActionInvokedAndSentUserInfo() {
|
||||
|
||||
let expectation = expectationWithDescription("cell action")
|
||||
|
||||
let row = TableConfigurableRowBuilder<TestData, TestTableViewCell>(items: [TestData(title: "title")])
|
||||
.action(TestTableViewCellOptions.CellAction) { data -> Void in
|
||||
|
||||
XCTAssertNotNil(data.cell, "Action data should have a cell")
|
||||
XCTAssertNotNil(data.userInfo, "Action data should have a user info dictionary")
|
||||
XCTAssertTrue(data.userInfo?[TestTableViewCellOptions.CellActionUserInfoKey] as? String == TestTableViewCellOptions.CellActionUserInfoValue, "UserInfo should have correct value for key")
|
||||
|
||||
expectation.fulfill()
|
||||
}
|
||||
|
||||
testController.view.hidden = false
|
||||
testController.tableDirector += row
|
||||
testController.tableView.reloadData()
|
||||
|
||||
let cell = testController.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0)) as? TestTableViewCell
|
||||
|
||||
XCTAssertNotNil(cell, "Cell should exists and should be TestTableViewCell")
|
||||
|
||||
cell?.raiseAction()
|
||||
|
||||
waitForExpectationsWithTimeout(1.0, handler: nil)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue