Skip to content

Instantly share code, notes, and snippets.

@pietrocaselani
Created June 3, 2018 18:43
Show Gist options
  • Save pietrocaselani/9975d611e4290e8b42990950a4ce5343 to your computer and use it in GitHub Desktop.
Save pietrocaselani/9975d611e4290e8b42990950a4ce5343 to your computer and use it in GitHub Desktop.
Testes unitários no iOS sem medo de ser feliz
import RxSwift
public enum MovieViewState: Hashable {
case loading
case error(error: Error)
case showingMovies(titles: [String])
case empty
public var hashValue: Int {
switch self {
case .loading:
return "MovieViewState.loading".hashValue
case .error(let error):
return "MovieViewState.error".hashValue ^ error.localizedDescription.hashValue
case .showingMovies(let titles):
var hash = "MovieViewState.showingMovies".hashValue
titles.forEach { hash ^= $0.hashValue }
return hash
case .empty:
return "MovieViewState.empty".hashValue
}
}
public static func == (lhs: MovieViewState, rhs: MovieViewState) -> Bool {
return lhs.hashValue == rhs.hashValue
}
}
public protocol MoviesRepository {
func fetchMovies() -> Observable<[String]>
}
public protocol MoviesViewModel {
func viewDidLoad()
func observeViewState() -> Observable<MovieViewState>
}
public protocol MoviesView: class {
var viewModel: MoviesViewModel? { get set }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment