2020-08-03 15:20:51 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Combine
|
|
|
|
import CombineExpectations
|
2020-08-31 18:57:02 +00:00
|
|
|
import ServiceLayer
|
2020-09-01 07:33:49 +00:00
|
|
|
import ServiceLayerMocks
|
|
|
|
@testable import ViewModels
|
2020-09-05 02:31:43 +00:00
|
|
|
import XCTest
|
2020-08-03 15:20:51 +00:00
|
|
|
|
|
|
|
class RootViewModelTests: XCTestCase {
|
2020-08-07 01:41:59 +00:00
|
|
|
var cancellables = Set<AnyCancellable>()
|
|
|
|
|
2020-08-03 15:20:51 +00:00
|
|
|
func testAddIdentity() throws {
|
2020-09-01 07:33:49 +00:00
|
|
|
let sut = try RootViewModel(
|
|
|
|
environment: .mock(),
|
|
|
|
registerForRemoteNotifications: { Empty().setFailureType(to: Error.self).eraseToAnyPublisher() })
|
2020-09-10 04:51:31 +00:00
|
|
|
let recorder = sut.$navigationViewModel.record()
|
2020-08-03 15:20:51 +00:00
|
|
|
|
2020-08-04 20:26:09 +00:00
|
|
|
XCTAssertNil(try wait(for: recorder.next(), timeout: 1))
|
2020-08-03 15:20:51 +00:00
|
|
|
|
|
|
|
let addIdentityViewModel = sut.addIdentityViewModel()
|
|
|
|
|
2020-08-14 01:59:17 +00:00
|
|
|
addIdentityViewModel.addedIdentityID
|
2020-09-09 12:05:43 +00:00
|
|
|
.sink(receiveValue: sut.identitySelected(id:))
|
2020-08-07 01:41:59 +00:00
|
|
|
.store(in: &cancellables)
|
|
|
|
|
2020-08-03 15:20:51 +00:00
|
|
|
addIdentityViewModel.urlFieldText = "https://mastodon.social"
|
2020-08-09 11:27:38 +00:00
|
|
|
addIdentityViewModel.logInTapped()
|
2020-08-03 15:20:51 +00:00
|
|
|
|
2020-09-10 04:51:31 +00:00
|
|
|
let navigationViewModel = try wait(for: recorder.next(), timeout: 1)!
|
2020-08-03 15:20:51 +00:00
|
|
|
|
2020-09-10 04:51:31 +00:00
|
|
|
XCTAssertNotNil(navigationViewModel)
|
2020-08-03 15:20:51 +00:00
|
|
|
}
|
|
|
|
}
|