add test, bump readme

This commit is contained in:
Max Sokolov 2016-03-19 19:58:39 +03:00
parent eefb885c44
commit 9309ac7766
3 changed files with 48 additions and 4 deletions

View File

@ -12,11 +12,13 @@ Tablet is a super lightweight yet powerful generic library that handles a comple
## Features
- [x] Powerfull type-safe system based on generics
- [x] Type-safe cells based on generics
- [x] The easiest way to map your models or view models to cells
- [x] Chainable cell actions
- [x] Support cells created from code, xib, or storyboard
- [x] Automatic xib/classes registration
- [x] No need to subclass
- [x] Correctly handles autolayout cells with multiline labels
- [x] Extensibility
- [x] Tests
@ -66,7 +68,7 @@ let rowBuilder = TableRowBuilder<User, UITableViewCell>(items: [user1, user2, us
data.cell?.detailTextLabel?.text = data.item.isActive ? "Active" : "Inactive"
}
let sectionBuilder = TableSectionBuilder(headerTitle: "Users", rowBuilders: [rowBuilder])
let sectionBuilder = TableSectionBuilder(headerTitle: "Users", rows: [rowBuilder])
director = TableDirector(tableView: tableView)
director.appendSections(sectionBuilder)
@ -108,7 +110,7 @@ let rowBuilder = TableConfigurableRowBuilder<User, MyTableViewCell>()
rowBuilder.appendItems(users)
director = TableDirector(tableView: tableView)
tableDirector.appendSection(TableSectionBuilder(rowBuilders: [rowBuilder]))
tableDirector.appendSection(TableSectionBuilder(rows: [rowBuilder]))
```
### Cell actions

View File

@ -21,7 +21,7 @@
import XCTest
import Tablet
class TestController : UITableViewController {
class TestController: UITableViewController {
var tableDirector: TableDirector!
@ -31,6 +31,34 @@ class TestController : UITableViewController {
}
}
struct TestData {
let title: String
}
struct TestTableViewCellOptions {
static let ReusableIdentifier: String = "ReusableIdentifier"
static let EstimatedHeight: Float = 255
}
class TestTableViewCell: UITableViewCell, ConfigurableCell {
typealias Item = TestData
static func reusableIdentifier() -> String {
return TestTableViewCellOptions.ReusableIdentifier
}
static func estimatedHeight() -> Float {
return TestTableViewCellOptions.EstimatedHeight
}
func configureWithItem(item: Item) {
textLabel?.text = item.title
}
}
class TabletTests: XCTestCase {
var testController: TestController!
@ -80,4 +108,18 @@ class TabletTests: XCTestCase {
XCTAssertTrue(cell?.textLabel?.text == element)
}
}
func testConfigurableRowBuilder() {
let testData = TestData(title: "title")
testController.view.hidden = false
testController.tableDirector += TableConfigurableRowBuilder<TestData, TestTableViewCell>(item: testData)
testController.tableView.reloadData()
let cell = testController.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0)) as? TestTableViewCell
XCTAssertNotNil(cell, "Cell should exists and should be TestTableViewCell")
XCTAssertTrue(cell?.textLabel?.text == testData.title, "Cell's textLabel.text should equal to testData's title")
}
}