Skip to content

Commit

Permalink
Remove redundant view state and test for it.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Sep 23, 2024
1 parent 2d4d8a9 commit abe1ecb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ struct ServerConfirmationScreenViewState: BindableState {
var homeserverAddress: String
/// The flow being attempted on the selected homeserver.
let authenticationFlow: AuthenticationFlow
/// Whether or not the homeserver supports registration.
var homeserverSupportsRegistration = false
/// The presentation anchor used for OIDC authentication.
var window: UIWindow?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ class ServerConfirmationScreenViewModel: ServerConfirmationScreenViewModelType,

let homeserver = authenticationService.homeserver.value
super.init(initialViewState: ServerConfirmationScreenViewState(homeserverAddress: homeserver.address,
authenticationFlow: authenticationFlow,
homeserverSupportsRegistration: homeserver.supportsRegistration))
authenticationFlow: authenticationFlow))

authenticationService.homeserver
.receive(on: DispatchQueue.main)
.sink { [weak self] homeserver in
guard let self else { return }
state.homeserverAddress = homeserver.address
state.homeserverSupportsRegistration = homeserver.supportsRegistration
}
.store(in: &cancellables)
}
Expand Down
11 changes: 2 additions & 9 deletions UnitTests/Sources/ServerConfigurationScreenViewStateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,11 @@ class ServerConfirmationScreenViewStateTests: XCTestCase {

func testRegisterMessageString() {
let matrixDotOrgRegister = ServerConfirmationScreenViewState(homeserverAddress: LoginHomeserver.mockMatrixDotOrg.address,
authenticationFlow: .register,
homeserverSupportsRegistration: true)
authenticationFlow: .register)
XCTAssertEqual(matrixDotOrgRegister.message, L10n.screenServerConfirmationMessageRegister, "The registration message should always be the same.")

let oidcRegister = ServerConfirmationScreenViewState(homeserverAddress: LoginHomeserver.mockOIDC.address,
authenticationFlow: .register,
homeserverSupportsRegistration: true)
authenticationFlow: .register)
XCTAssertEqual(oidcRegister.message, L10n.screenServerConfirmationMessageRegister, "The registration message should always be the same.")

let otherRegister = ServerConfirmationScreenViewState(homeserverAddress: LoginHomeserver.mockBasicServer.address,
authenticationFlow: .register,
homeserverSupportsRegistration: false)
XCTAssertEqual(otherRegister.message, L10n.errorAccountCreationNotPossible, "The registration message should always be the same.")
}
}

0 comments on commit abe1ecb

Please sign in to comment.