Skip to content

Commit 512a5de

Browse files
authored
Merge pull request #17 from rcaos/testing-schedulers
Fix Testing schedulers
2 parents e93f1e0 + 5848d0e commit 512a5de

File tree

204 files changed

+1865
-2287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+1865
-2287
lines changed

Projects/Features/Account/Project.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ let project = Project.framework(
1919
.project(
2020
target: "TVShowsListInterface",
2121
path: .relativeToRoot("Projects/Features/TVShowsList")
22-
)
22+
),
23+
.package(product: "CombineSchedulers")
2324
],
2425
testFolder: "Tests",
2526
testDependencies: [

Projects/Features/Account/Sources/Presentation/Account/View/AccountViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ class AccountViewController: NiblessViewController {
3030

3131
override func viewDidLoad() {
3232
super.viewDidLoad()
33+
viewModel.viewDidLoad()
3334
subscribe()
3435
}
3536

3637
// MARK: - Setup UI
3738
private func subscribe() {
3839
viewModel
3940
.viewState
40-
.receive(on: RunLoop.main)
41+
.receive(on: DispatchQueue.main)
4142
.sink(receiveCompletion: { _ in }, receiveValue: { [weak self] viewState in
4243
self?.setupUI(with: viewState)
4344
})

Projects/Features/Account/Sources/Presentation/Account/ViewModel/AccountViewModel.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import Foundation
1010
import Combine
11+
import CombineSchedulers
1112
import NetworkingInterface
1213
import Shared
1314

@@ -17,6 +18,7 @@ enum AccountViewState: Equatable {
1718
}
1819

1920
protocol AccountViewModelProtocol: AuthPermissionViewModelDelegate {
21+
func viewDidLoad()
2022
var viewState: CurrentValueSubject<AccountViewState, Never> { get }
2123
}
2224

@@ -28,6 +30,7 @@ final class AccountViewModel: AccountViewModelProtocol {
2830

2931
weak var coordinator: AccountCoordinatorProtocol?
3032
private var disposeBag = Set<AnyCancellable>()
33+
private let scheduler: AnySchedulerOf<DispatchQueue>
3134

3235
// MARK: - Public Api
3336
let viewState: CurrentValueSubject<AccountViewState, Never> = .init(.login)
@@ -36,15 +39,21 @@ final class AccountViewModel: AccountViewModelProtocol {
3639
init(createNewSession: CreateSessionUseCase,
3740
fetchAccountDetails: FetchAccountDetailsUseCase,
3841
fetchLoggedUser: FetchLoggedUser,
39-
deleteLoguedUser: DeleteLoguedUserUseCase) {
42+
deleteLoguedUser: DeleteLoguedUserUseCase,
43+
scheduler: AnySchedulerOf<DispatchQueue> = .main
44+
) {
4045
self.createNewSession = createNewSession
4146
self.fetchAccountDetails = fetchAccountDetails
4247
self.fetchLoggedUser = fetchLoggedUser
4348
self.deleteLoguedUser = deleteLoguedUser
49+
self.scheduler = scheduler
50+
}
51+
52+
func viewDidLoad() {
4453
checkIsLogued()
4554
}
4655

47-
fileprivate func checkIsLogued() {
56+
private func checkIsLogued() {
4857
if fetchLoggedUser.execute() != nil {
4958
fetchUserDetails()
5059
} else {
@@ -54,7 +63,7 @@ final class AccountViewModel: AccountViewModelProtocol {
5463

5564
private func fetchUserDetails() {
5665
fetchDetailsAccount()
57-
.receive(on: RunLoop.main)
66+
.receive(on: scheduler)
5867
.sink(receiveCompletion: { [weak self] completion in
5968
switch completion {
6069
case .failure:
@@ -77,7 +86,7 @@ final class AccountViewModel: AccountViewModelProtocol {
7786
}
7887
return strongSelf.fetchDetailsAccount()
7988
}
80-
.receive(on: RunLoop.main)
89+
.receive(on: scheduler)
8190
.sink(receiveCompletion: { [weak self] completion in
8291
switch completion {
8392
case .failure:

Projects/Features/Account/Sources/Presentation/Profile/View/ProfileRootView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ProfileRootView: NiblessView {
7777
}
7878
return snapShot
7979
}
80-
.receive(on: RunLoop.main)
80+
.receive(on: DispatchQueue.main)
8181
.sink(receiveCompletion: { _ in }, receiveValue: { [weak self] snapshot in
8282
self?.dataSource?.apply(snapshot)
8383
})

Projects/Features/Account/Sources/Presentation/Profile/View/ProfileViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ProfileViewController: NiblessViewController {
3434
viewModel
3535
.presentSignOutAlert
3636
.filter { $0 == true }
37-
.receive(on: RunLoop.main)
37+
.receive(on: DispatchQueue.main)
3838
.sink(receiveCompletion: { _ in }, receiveValue: { [weak self] _ in
3939
self?.showSignOutActionSheet()
4040
})

Projects/Features/Account/Sources/Presentation/SignIn/View/SignInViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class SignInViewController: NiblessViewController {
3434
fileprivate func subscribe() {
3535
viewModel
3636
.viewState
37-
.receive(on: RunLoop.main)
37+
.receive(on: DispatchQueue.main)
3838
.sink(receiveCompletion: { _ in }, receiveValue: { [weak self] state in
3939
self?.setupView(with: state)
4040
})

Projects/Features/Account/Sources/Presentation/SignIn/ViewModel/SignInViewModel.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import Foundation
1010
import Combine
11+
import CombineSchedulers
1112
import Shared
1213
import NetworkingInterface
1314

@@ -17,11 +18,14 @@ class SignInViewModel: SignInViewModelProtocol {
1718

1819
let viewState: CurrentValueSubject<SignInViewState, Never> = .init(.initial)
1920
weak var delegate: SignInViewModelDelegate?
21+
22+
private let scheduler: AnySchedulerOf<DispatchQueue>
2023
private var disposeBag = Set<AnyCancellable>()
2124

2225
// MARK: - Initializers
23-
init(createTokenUseCase: CreateTokenUseCase) {
26+
init(createTokenUseCase: CreateTokenUseCase, scheduler: AnySchedulerOf<DispatchQueue> = .main) {
2427
self.createTokenUseCase = createTokenUseCase
28+
self.scheduler = scheduler
2529
subscribe()
2630
}
2731

@@ -42,7 +46,7 @@ class SignInViewModel: SignInViewModelProtocol {
4246
viewState.send(.loading)
4347
return createTokenUseCase.execute()
4448
}
45-
.receive(on: RunLoop.main)
49+
.receive(on: scheduler)
4650
.sink(receiveCompletion: { [weak self] completion in
4751
switch completion {
4852
case let .failure(error):

Projects/Features/Account/Tests/Account/Mocks/ViewModels/AccountViewModelMock.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import Combine
1010

1111
final class AccountViewModelMock: AccountViewModelProtocol {
1212

13+
func viewDidLoad() { }
14+
1315
let viewState: CurrentValueSubject<AccountViewState, Never>
1416

1517
init(state: AccountViewState) {

Projects/Features/Account/Tests/Account/Presentation/AccountViewControllerFactoryMock.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ class AccountViewControllerFactoryMock: AccountViewControllerFactory {
1919
return ProfileViewController(viewModel: viewModel)
2020
}
2121
}
22+
23+
func configureWith(_ viewController: UIViewController, style: UIUserInterfaceStyle) {
24+
viewController.overrideUserInterfaceStyle = style
25+
_ = viewController.view
26+
}

Projects/Features/Account/Tests/Account/Presentation/AccountViewDarkTests.swift

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)