From 1bc7301c7e090664f7a739f48c8c8ee6ba73b796 Mon Sep 17 00:00:00 2001 From: Max Sokolov Date: Sat, 18 Jun 2016 04:17:58 +0300 Subject: [PATCH] add operators --- README.md | 2 +- Sources/Operators.swift | 9 +++++++++ Tests/TableKitTests.swift | 28 ++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1e4259f..6700590 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ It hides a complexity of `UITableViewDataSource` and `UITableViewDelegate` metho ## Features -- [x] Type-safe cells based on generics +- [x] Type-safe generic cells - [x] The easiest way to map your models or view models to cells - [x] Correctly handles autolayout cells with multiline labels - [x] Chainable cell actions (select/deselect etc.) diff --git a/Sources/Operators.swift b/Sources/Operators.swift index 14a4326..3f0f555 100644 --- a/Sources/Operators.swift +++ b/Sources/Operators.swift @@ -27,6 +27,15 @@ public func +=(left: TableDirector, right: [TableSection]) { left.append(sections: right) } +// -- +public func +=(left: TableDirector, right: Row) { + left.append(sections: [TableSection(rows: [right])]) +} + +public func +=(left: TableDirector, right: [Row]) { + left.append(sections: [TableSection(rows: right)]) +} + // -- public func +=(left: TableSection, right: Row) { left.append(row: right) diff --git a/Tests/TableKitTests.swift b/Tests/TableKitTests.swift index 868e288..2a26050 100644 --- a/Tests/TableKitTests.swift +++ b/Tests/TableKitTests.swift @@ -45,7 +45,7 @@ struct TestTableViewCellOptions { static let EstimatedHeight: Float = 255 } -/*class TestTableViewCell: UITableViewCell, ConfigurableCell { +class TestTableViewCell: UITableViewCell, ConfigurableCell { typealias T = TestData @@ -57,12 +57,12 @@ struct TestTableViewCellOptions { return TestTableViewCellOptions.EstimatedHeight } - func configure(item: T) { + func configure(item: T, isPrototype: Bool) { textLabel?.text = item.title } func raiseAction() { - Action(key: TestTableViewCellOptions.CellAction, sender: self, userInfo: [TestTableViewCellOptions.CellActionUserInfoKey: TestTableViewCellOptions.CellActionUserInfoValue]).invoke() + //Action(key: TestTableViewCellOptions.CellAction, sender: self, userInfo: [TestTableViewCellOptions.CellActionUserInfoKey: TestTableViewCellOptions.CellActionUserInfoValue]).invoke() } } @@ -74,6 +74,7 @@ class TabletTests: XCTestCase { super.setUp() testController = TestController() + let _ = testController.view } override func tearDown() { @@ -89,7 +90,22 @@ class TabletTests: XCTestCase { XCTAssertNotNil(testController.tableDirector.tableView, "TableDirector should have table view") } - func testSimpleRowBuilderCreatesRowsAndSection() { + func testRow() { + + let data = TestData(title: "title") + + let row = TableRow(item: data) + + testController.tableDirector += row + + 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") + + let cell = testController.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0)) as? TestTableViewCell + XCTAssertNotNil(cell) + } + + /*func testSimpleRowBuilderCreatesRowsAndSection() { let source = ["1", "2", "3"] @@ -196,5 +212,5 @@ class TabletTests: XCTestCase { cell?.raiseAction() waitForExpectationsWithTimeout(1.0, handler: nil) - } -}*/ \ No newline at end of file + }*/ +} \ No newline at end of file