Added tests for selectedScopeButtonIndex

This commit is contained in:
Stephen H. Gerstacker 2016-03-12 22:23:27 -05:00
parent 23a3743a23
commit 4ebf810993

View File

@ -44,4 +44,31 @@ class UISearchBarTests : RxTest {
_ = Observable.just("value").bindTo(searchBar.rx_text)
XCTAssertEqual(searchBar.text, "value")
}
func testSelectedScopeButtonIndex_changeEventWOrks() {
let searchBar = UISearchBar(frame: CGRectMake(0, 0, 1, 1))
searchBar.scopeButtonTitles = [ "One", "Two", "Three" ]
var latestSelectedScopeIndex: Int = -1
_ = searchBar.rx_selectedScopeButtonIndex.subscribeNext { index in
latestSelectedScopeIndex = index
}
XCTAssertEqual(latestSelectedScopeIndex, 0)
searchBar.selectedScopeButtonIndex = 1
searchBar.delegate!.searchBar!(searchBar, selectedScopeButtonIndexDidChange: 1)
XCTAssertEqual(latestSelectedScopeIndex, 1)
}
func testSelectedScopeButtonIndex_binding() {
let searchBar = UISearchBar(frame: CGRectMake(0, 0, 1, 1))
searchBar.scopeButtonTitles = [ "One", "Two", "Three" ]
XCTAssertNotEqual(searchBar.selectedScopeButtonIndex, 1)
_ = Observable.just(1).bindTo(searchBar.rx_selectedScopeButtonIndex)
XCTAssertEqual(searchBar.selectedScopeButtonIndex, 1)
}
}