Skip to content

Commit

Permalink
Add UIPickerView data source extensions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergdort committed Jul 14, 2017
1 parent 3127ef4 commit de8de1d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
35 changes: 35 additions & 0 deletions Tests/RxCocoaTests/DelegateProxyTest+UIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ extension DelegateProxyTest {
func test_UIPickerViewExtension() {
performDelegateTest(UIPickerViewSubclass(frame: CGRect.zero))
}

func test_UIPickerViewDataSourceExtension() {
performDelegateTest(UIPickerViewSubclass2(frame: CGRect.zero))
}
}
#endif

Expand Down Expand Up @@ -390,6 +394,37 @@ final class UIPickerViewSubclass
onProxyForObject: self)
}
}

final class ExtendPickerViewDataSourceProxy
: RxPickerViewDataSourceProxy
, TestDelegateProtocol {
weak fileprivate(set) var control: UIPickerViewSubclass2?

required init(parentObject: AnyObject) {
self.control = (parentObject as! UIPickerViewSubclass2)
super.init(parentObject: parentObject)
}
}

final class UIPickerViewSubclass2: UIPickerView, TestDelegateControl {
override func createRxDataSourceProxy() -> RxPickerViewDataSourceProxy {
return ExtendPickerViewDataSourceProxy(parentObject: self)
}

func doThatTest(_ value: Int) {
if dataSource != nil {
(dataSource as! TestDelegateProtocol).testEventHappened?(value)
}
}

var delegateProxy: DelegateProxy {
return self.rx.dataSource
}

func setMineForwardDelegate(_ testDelegate: TestDelegateProtocol) -> Disposable {
return RxPickerViewDataSourceProxy.installForwardDelegate(testDelegate, retainDelegate: false, onProxyForObject: self)
}
}

final class ExtendWebViewDelegateProxy
: RxWebViewDelegateProxy
Expand Down
11 changes: 10 additions & 1 deletion Tests/RxCocoaTests/DelegateProxyTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ extension MockTestDelegateProtocol
: UICollectionViewDataSource
, UIScrollViewDelegate
, UITableViewDataSource
, UITableViewDelegate {
, UITableViewDelegate
, UIPickerViewDataSource {

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
fatalError()
Expand All @@ -525,5 +526,13 @@ extension MockTestDelegateProtocol
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
fatalError()
}

func numberOfComponents(in pickerView: UIPickerView) -> Int {
fatalError()
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
fatalError()
}
}
#endif

0 comments on commit de8de1d

Please sign in to comment.