mirror of
https://github.com/ReactiveX/RxSwift.git
synced 2024-10-06 06:57:43 +03:00
Resurrects UITests.
This commit is contained in:
parent
e8c5a256fb
commit
3738b96d49
@ -8,10 +8,10 @@
|
|||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
import UIKit
|
import UIKit
|
||||||
private typealias OSApplication = UIApplication
|
typealias OSApplication = UIApplication
|
||||||
#elseif os(OSX)
|
#elseif os(OSX)
|
||||||
import Cocoa
|
import Cocoa
|
||||||
private typealias OSApplication = NSApplication
|
typealias OSApplication = NSApplication
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extension OSApplication {
|
extension OSApplication {
|
||||||
|
@ -34,6 +34,7 @@ public class CollectionViewImageCell: UICollectionViewCell {
|
|||||||
override public func prepareForReuse() {
|
override public func prepareForReuse() {
|
||||||
super.prepareForReuse()
|
super.prepareForReuse()
|
||||||
|
|
||||||
|
downloadableImage = nil
|
||||||
disposeBag = nil
|
disposeBag = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,10 +29,14 @@ public class WikipediaSearchCell: UITableViewCell {
|
|||||||
self.imagesOutlet.register(UINib(nibName: "WikipediaImageCell", bundle: nil), forCellWithReuseIdentifier: "ImageCell")
|
self.imagesOutlet.register(UINib(nibName: "WikipediaImageCell", bundle: nil), forCellWithReuseIdentifier: "ImageCell")
|
||||||
}
|
}
|
||||||
|
|
||||||
var viewModel: SearchResultViewModel! {
|
var viewModel: SearchResultViewModel? {
|
||||||
didSet {
|
didSet {
|
||||||
let disposeBag = DisposeBag()
|
let disposeBag = DisposeBag()
|
||||||
|
|
||||||
|
guard let viewModel = viewModel else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
viewModel.title
|
viewModel.title
|
||||||
.map(Optional.init)
|
.map(Optional.init)
|
||||||
.drive(self.titleOutlet.rx.text)
|
.drive(self.titleOutlet.rx.text)
|
||||||
@ -44,16 +48,25 @@ public class WikipediaSearchCell: UITableViewCell {
|
|||||||
viewModel.imageURLs
|
viewModel.imageURLs
|
||||||
.drive(self.imagesOutlet.rx.items(cellIdentifier: "ImageCell", cellType: CollectionViewImageCell.self)) { [weak self] (_, url, cell) in
|
.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()
|
cell.downloadableImage = self?.imageService.imageFromURL(url, reachabilityService: reachabilityService) ?? Observable.empty()
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
cell.installHackBecauseOfAutomationLeaksOnIOS10(firstViewThatDoesntLeak: self!.superview!.superview!)
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
.addDisposableTo(disposeBag)
|
.addDisposableTo(disposeBag)
|
||||||
|
|
||||||
self.disposeBag = disposeBag
|
self.disposeBag = disposeBag
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
self.installHackBecauseOfAutomationLeaksOnIOS10(firstViewThatDoesntLeak: self.superview!.superview!)
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func prepareForReuse() {
|
public override func prepareForReuse() {
|
||||||
super.prepareForReuse()
|
super.prepareForReuse()
|
||||||
|
|
||||||
|
self.viewModel = nil
|
||||||
self.disposeBag = 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!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -14,11 +14,9 @@ import RxSwift
|
|||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
import UIKit
|
import UIKit
|
||||||
typealias OSViewController = UIViewController
|
typealias OSViewController = UIViewController
|
||||||
private typealias OSApplication = UIApplication
|
|
||||||
#elseif os(OSX)
|
#elseif os(OSX)
|
||||||
import Cocoa
|
import Cocoa
|
||||||
typealias OSViewController = NSViewController
|
typealias OSViewController = NSViewController
|
||||||
private typealias OSApplication = NSApplication
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class ViewController: OSViewController {
|
class ViewController: OSViewController {
|
||||||
|
@ -22,6 +22,8 @@ public class RootViewController : UITableViewController {
|
|||||||
_ = DefaultImageService.sharedImageService
|
_ = DefaultImageService.sharedImageService
|
||||||
_ = DefaultWireframe.sharedInstance
|
_ = DefaultWireframe.sharedInstance
|
||||||
_ = MainScheduler.instance
|
_ = MainScheduler.instance
|
||||||
|
_ = Dependencies.sharedDependencies.reachabilityService
|
||||||
|
|
||||||
let geoService = GeolocationService.instance
|
let geoService = GeolocationService.instance
|
||||||
geoService.authorized.drive(onNext: { _ in
|
geoService.authorized.drive(onNext: { _ in
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user