Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirkofman committed Apr 26, 2017
1 parent 35ec953 commit 65fa61e
Showing 1 changed file with 60 additions and 7 deletions.
67 changes: 60 additions & 7 deletions TableTieTests/TableTieTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,33 @@ class TableTieTests: XCTestCase {
XCTAssertEqual(adapter.numberOfSections(in: tableView), 0)
}

func testAdapterInitRows() {
let arr = ["a", "b", "c"]
adapter = Adapter(arr)
tableView = UITableView(frame: CGRect.zero)
tableView.dataSource = adapter
tableView.delegate = adapter

XCTAssertEqual(adapter.numberOfSections(in: tableView), 1)
XCTAssertEqual(adapter.tableView(tableView, numberOfRowsInSection: 0), arr.count)
}

func testAdapterInitSections() {
let sections = [Section("A", ["a", "b"])]
adapter = Adapter(sections)
tableView = UITableView(frame: CGRect.zero)
tableView.dataSource = adapter
tableView.delegate = adapter

XCTAssertEqual(adapter.numberOfSections(in: tableView), 1)
XCTAssertEqual(adapter.tableView(tableView, numberOfRowsInSection: 0), sections[0].rows.count)
}

func testAdapterSetRows() {
let arr = ["a", "b", "c"]
adapter.set(arr)

XCTAssertEqual(adapter.numberOfSections(in: UITableView()), 1)
XCTAssertEqual(adapter.numberOfSections(in: tableView), 1)
XCTAssertEqual(adapter.tableView(tableView, numberOfRowsInSection: 0), arr.count)

}
Expand All @@ -59,14 +81,45 @@ class TableTieTests: XCTestCase {
XCTAssertEqual(cell.textLabel?.text, arr[testRowIndex])

adapter.set([] as! [AnyRow])
XCTAssertEqual(adapter.numberOfSections(in: UITableView()), 1)
XCTAssertEqual(adapter.numberOfSections(in: tableView), 1)
}

// let arr2 = ["d", "e"]
// adapter.set(arr2)
// XCTAssertEqual(adapter.numberOfSections(in: UITableView()), 1)
// XCTAssertEqual(adapter.tableView(tableView, numberOfRowsInSection: 0), arr2.count)
// }
func testAdapterSetSections() {
let sections = [Section("A", ["a", "b"]), Section("B", ["d", "e", "f"])]

adapter.set(sections)
XCTAssertEqual(adapter.numberOfSections(in: tableView), sections.count)

for (i, section) in sections.enumerated() {
XCTAssertEqual(adapter.tableView(tableView, numberOfRowsInSection: i), sections[i].rows.count)

XCTAssertEqual(adapter.tableView(tableView, titleForHeaderInSection: i), sections[i].header)
XCTAssertNil(adapter.tableView(tableView, titleForFooterInSection: i))

let testRowIndex = section.rows.count / 2
let cell = adapter.tableView(tableView, cellForRowAt: IndexPath(row: testRowIndex, section: i))
XCTAssertEqual(cell.textLabel?.text, section.rows[testRowIndex] as? String)
}
}

func testSelectableRow() {
var callMeCalled = false
func callMe() {
callMeCalled = true
}

adapter.set([SelectableRow("a", callMe())])

XCTAssertFalse(callMeCalled)

adapter.tableView(tableView, didSelectRowAt: IndexPath(row: 0, section: 0))

XCTAssertTrue(callMeCalled)
}

func testDefaultRowHeight() {
adapter.set(["a"])

XCTAssertEqual(adapter.tableView(tableView, heightForRowAt: IndexPath(row: 0, section: 0)), UITableViewAutomaticDimension)
}
}

0 comments on commit 65fa61e

Please sign in to comment.