Resurrects UITests.

This commit is contained in:
Krunoslav Zaher 2016-10-04 00:04:58 +02:00
parent e8c5a256fb
commit 3738b96d49
5 changed files with 52 additions and 5 deletions

View File

@ -8,10 +8,10 @@
#if os(iOS)
import UIKit
private typealias OSApplication = UIApplication
typealias OSApplication = UIApplication
#elseif os(OSX)
import Cocoa
private typealias OSApplication = NSApplication
typealias OSApplication = NSApplication
#endif
extension OSApplication {

View File

@ -34,6 +34,7 @@ public class CollectionViewImageCell: UICollectionViewCell {
override public func prepareForReuse() {
super.prepareForReuse()
downloadableImage = nil
disposeBag = nil
}

View File

@ -29,10 +29,14 @@ public class WikipediaSearchCell: UITableViewCell {
self.imagesOutlet.register(UINib(nibName: "WikipediaImageCell", bundle: nil), forCellWithReuseIdentifier: "ImageCell")
}
var viewModel: SearchResultViewModel! {
var viewModel: SearchResultViewModel? {
didSet {
let disposeBag = DisposeBag()
guard let viewModel = viewModel else {
return
}
viewModel.title
.map(Optional.init)
.drive(self.titleOutlet.rx.text)
@ -44,16 +48,25 @@ public class WikipediaSearchCell: UITableViewCell {
viewModel.imageURLs
.drive(self.imagesOutlet.rx.items(cellIdentifier: "ImageCell", cellType: CollectionViewImageCell.self)) { [weak self] (_, url, cell) in
cell.downloadableImage = self?.imageService.imageFromURL(url, reachabilityService: reachabilityService) ?? Observable.empty()
#if DEBUG
cell.installHackBecauseOfAutomationLeaksOnIOS10(firstViewThatDoesntLeak: self!.superview!.superview!)
#endif
}
.addDisposableTo(disposeBag)
self.disposeBag = disposeBag
#if DEBUG
self.installHackBecauseOfAutomationLeaksOnIOS10(firstViewThatDoesntLeak: self.superview!.superview!)
#endif
}
}
public override func prepareForReuse() {
super.prepareForReuse()
self.viewModel = nil
self.disposeBag = nil
}
@ -61,3 +74,36 @@ public class WikipediaSearchCell: UITableViewCell {
}
}
fileprivate protocol ReusableView: class {
var disposeBag: DisposeBag? { get }
func prepareForReuse()
}
extension WikipediaSearchCell : ReusableView {
}
extension CollectionViewImageCell : ReusableView {
}
fileprivate extension ReusableView {
func installHackBecauseOfAutomationLeaksOnIOS10(firstViewThatDoesntLeak: UIView) {
if #available(iOS 10.0, *) {
if OSApplication.isInUITest {
// !!! on iOS 10 automation tests leak cells, 🍻 automation team
// !!! fugly workaround
// ... no, I'm not assuming prepareForReuse is always called before init, this is
// just a workaround because that method already has cleanup logic :(
// Remember that leaking UISwitch?
// https://github.com/ReactiveX/RxSwift/issues/842
// Well it just got some new buddies to hang around with
firstViewThatDoesntLeak.rx.deallocated.subscribe(onNext: { [weak self] _ in
self?.prepareForReuse()
})
.addDisposableTo(self.disposeBag!)
}
}
}
}

View File

@ -14,11 +14,9 @@ import RxSwift
#if os(iOS)
import UIKit
typealias OSViewController = UIViewController
private typealias OSApplication = UIApplication
#elseif os(OSX)
import Cocoa
typealias OSViewController = NSViewController
private typealias OSApplication = NSApplication
#endif
class ViewController: OSViewController {

View File

@ -22,6 +22,8 @@ public class RootViewController : UITableViewController {
_ = DefaultImageService.sharedImageService
_ = DefaultWireframe.sharedInstance
_ = MainScheduler.instance
_ = Dependencies.sharedDependencies.reachabilityService
let geoService = GeolocationService.instance
geoService.authorized.drive(onNext: { _ in