2020-07-30 01:50:30 +02:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
import Combine
|
|
|
|
import CombineExpectations
|
|
|
|
@testable import Metatext
|
|
|
|
|
|
|
|
class AddIdentityViewModelTests: XCTestCase {
|
|
|
|
func testAddIdentity() throws {
|
2020-08-09 13:27:38 +02:00
|
|
|
let identityDatabase = IdentityDatabase.fresh()
|
|
|
|
let sut = AddIdentityViewModel(identitiesService: .fresh(identityDatabase: identityDatabase))
|
2020-08-14 03:59:17 +02:00
|
|
|
let addedIDRecorder = sut.addedIdentityID.record()
|
2020-07-30 01:50:30 +02:00
|
|
|
|
|
|
|
sut.urlFieldText = "https://mastodon.social"
|
2020-08-09 13:27:38 +02:00
|
|
|
sut.logInTapped()
|
2020-07-30 01:50:30 +02:00
|
|
|
|
2020-08-14 03:59:17 +02:00
|
|
|
_ = try wait(for: addedIDRecorder.next(), timeout: 1)
|
2020-07-30 01:50:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func testAddIdentityWithoutScheme() throws {
|
2020-08-09 13:27:38 +02:00
|
|
|
let identityDatabase = IdentityDatabase.fresh()
|
|
|
|
let sut = AddIdentityViewModel(identitiesService: .fresh(identityDatabase: identityDatabase))
|
2020-08-14 03:59:17 +02:00
|
|
|
let addedIDRecorder = sut.addedIdentityID.record()
|
2020-07-30 01:50:30 +02:00
|
|
|
|
|
|
|
sut.urlFieldText = "mastodon.social"
|
2020-08-09 13:27:38 +02:00
|
|
|
sut.logInTapped()
|
2020-07-30 01:50:30 +02:00
|
|
|
|
2020-08-14 03:59:17 +02:00
|
|
|
_ = try wait(for: addedIDRecorder.next(), timeout: 1)
|
2020-07-30 01:50:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func testInvalidURL() throws {
|
2020-08-09 13:27:38 +02:00
|
|
|
let sut = AddIdentityViewModel(identitiesService: .fresh())
|
2020-08-03 00:23:01 +02:00
|
|
|
let recorder = sut.$alertItem.record()
|
|
|
|
|
|
|
|
XCTAssertNil(try wait(for: recorder.next(), timeout: 1))
|
2020-07-30 01:50:30 +02:00
|
|
|
|
|
|
|
sut.urlFieldText = "🐘.social"
|
2020-08-09 13:27:38 +02:00
|
|
|
sut.logInTapped()
|
2020-07-30 01:50:30 +02:00
|
|
|
|
|
|
|
let alertItem = try wait(for: recorder.next(), timeout: 1)
|
|
|
|
|
|
|
|
XCTAssertEqual((alertItem?.error as? URLError)?.code, URLError.badURL)
|
|
|
|
}
|
2020-08-03 00:23:01 +02:00
|
|
|
|
|
|
|
func testDoesNotAlertCanceledLogin() throws {
|
2020-08-09 13:27:38 +02:00
|
|
|
let environment = AppEnvironment(
|
2020-08-12 09:24:39 +02:00
|
|
|
session: Session(configuration: .stubbing),
|
|
|
|
webAuthSessionType: CanceledLoginMockWebAuthSession.self,
|
|
|
|
keychainServiceType: MockKeychainService.self)
|
2020-08-09 13:27:38 +02:00
|
|
|
let identitiesService = IdentitiesService(
|
|
|
|
identityDatabase: .fresh(),
|
|
|
|
environment: environment)
|
|
|
|
let sut = AddIdentityViewModel(identitiesService: identitiesService)
|
2020-08-03 00:23:01 +02:00
|
|
|
let recorder = sut.$alertItem.record()
|
|
|
|
|
|
|
|
XCTAssertNil(try wait(for: recorder.next(), timeout: 1))
|
|
|
|
|
|
|
|
sut.urlFieldText = "https://mastodon.social"
|
2020-08-09 13:27:38 +02:00
|
|
|
sut.logInTapped()
|
2020-08-03 00:23:01 +02:00
|
|
|
|
|
|
|
try wait(for: recorder.next().inverted, timeout: 1)
|
|
|
|
}
|
2020-07-30 01:50:30 +02:00
|
|
|
}
|