metatext/Tests/View Models/RootViewModelTests.swift

32 lines
940 B
Swift
Raw Normal View History

2020-08-03 15:20:51 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
import XCTest
import Combine
import CombineExpectations
@testable import Metatext
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 {
let sut = RootViewModel(environment: .fresh())
2020-08-07 01:41:59 +00:00
let recorder = sut.$identityID.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-07 01:41:59 +00:00
addIdentityViewModel.addedIdentityID
.sink(receiveValue: sut.newIdentitySelected(id:))
.store(in: &cancellables)
2020-08-03 15:20:51 +00:00
addIdentityViewModel.urlFieldText = "https://mastodon.social"
addIdentityViewModel.goTapped()
2020-08-07 01:41:59 +00:00
let identityID = try wait(for: recorder.next(), timeout: 1)!
2020-08-03 15:20:51 +00:00
2020-08-07 01:41:59 +00:00
XCTAssertNotNil(identityID)
XCTAssertNotNil(sut.mainNavigationViewModel(identityID: identityID))
2020-08-03 15:20:51 +00:00
}
}