Skip to content

Commit de8de1d

Browse files
committed
Add UIPickerView data source extensions tests
1 parent 3127ef4 commit de8de1d

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

Tests/RxCocoaTests/DelegateProxyTest+UIKit.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ extension DelegateProxyTest {
7474
func test_UIPickerViewExtension() {
7575
performDelegateTest(UIPickerViewSubclass(frame: CGRect.zero))
7676
}
77+
78+
func test_UIPickerViewDataSourceExtension() {
79+
performDelegateTest(UIPickerViewSubclass2(frame: CGRect.zero))
80+
}
7781
}
7882
#endif
7983

@@ -390,6 +394,37 @@ final class UIPickerViewSubclass
390394
onProxyForObject: self)
391395
}
392396
}
397+
398+
final class ExtendPickerViewDataSourceProxy
399+
: RxPickerViewDataSourceProxy
400+
, TestDelegateProtocol {
401+
weak fileprivate(set) var control: UIPickerViewSubclass2?
402+
403+
required init(parentObject: AnyObject) {
404+
self.control = (parentObject as! UIPickerViewSubclass2)
405+
super.init(parentObject: parentObject)
406+
}
407+
}
408+
409+
final class UIPickerViewSubclass2: UIPickerView, TestDelegateControl {
410+
override func createRxDataSourceProxy() -> RxPickerViewDataSourceProxy {
411+
return ExtendPickerViewDataSourceProxy(parentObject: self)
412+
}
413+
414+
func doThatTest(_ value: Int) {
415+
if dataSource != nil {
416+
(dataSource as! TestDelegateProtocol).testEventHappened?(value)
417+
}
418+
}
419+
420+
var delegateProxy: DelegateProxy {
421+
return self.rx.dataSource
422+
}
423+
424+
func setMineForwardDelegate(_ testDelegate: TestDelegateProtocol) -> Disposable {
425+
return RxPickerViewDataSourceProxy.installForwardDelegate(testDelegate, retainDelegate: false, onProxyForObject: self)
426+
}
427+
}
393428

394429
final class ExtendWebViewDelegateProxy
395430
: RxWebViewDelegateProxy

Tests/RxCocoaTests/DelegateProxyTest.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ extension MockTestDelegateProtocol
508508
: UICollectionViewDataSource
509509
, UIScrollViewDelegate
510510
, UITableViewDataSource
511-
, UITableViewDelegate {
511+
, UITableViewDelegate
512+
, UIPickerViewDataSource {
512513

513514
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
514515
fatalError()
@@ -525,5 +526,13 @@ extension MockTestDelegateProtocol
525526
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
526527
fatalError()
527528
}
529+
530+
func numberOfComponents(in pickerView: UIPickerView) -> Int {
531+
fatalError()
532+
}
533+
534+
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
535+
fatalError()
536+
}
528537
}
529538
#endif

0 commit comments

Comments
 (0)