Files
bundesmessenger-ios/RiotSwiftUI/Modules/Authentication/VerifyMsisdn/Test/UI/AuthenticationVerifyMsisdnUITests.swift
T
Doug d5b5101420 Update remaining strings for FTUE.
Include homeserver in view models/state as needed.
Pre-fill the user's display name as set by the server.
2022-07-14 16:56:35 +01:00

147 lines
6.9 KiB
Swift

//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import XCTest
import RiotSwiftUI
class AuthenticationVerifyMsisdnUITests: MockScreenTest {
override class var screenType: MockScreenState.Type {
return MockAuthenticationVerifyMsisdnScreenState.self
}
override class func createTest() -> MockScreenTest {
return AuthenticationVerifyMsisdnUITests(selector: #selector(verifyAuthenticationVerifyMsisdnScreen))
}
func verifyAuthenticationVerifyMsisdnScreen() throws {
guard let screenState = screenState as? MockAuthenticationVerifyMsisdnScreenState else { fatalError("no screen") }
switch screenState {
case .emptyPhoneNumber:
verifyEmptyPhoneNumber()
case .enteredPhoneNumber:
verifyEnteredPhoneNumber()
case .hasSentSMS:
verifyHasSentSMS()
case .enteredOTP:
verifyEnteredOTP()
}
}
func verifyEmptyPhoneNumber() {
let titleLabel = app.staticTexts["titleLabel"]
XCTAssertTrue(titleLabel.exists, "The title should be shown.")
let messageLabel = app.staticTexts["messageLabel"]
XCTAssertTrue(messageLabel.exists, "The message should be shown.")
let phoneNumberTextField = app.textFields["phoneNumberTextField"]
XCTAssertTrue(phoneNumberTextField.exists, "The text field should be shown before an SMS is sent.")
XCTAssertEqual(phoneNumberTextField.value as? String, VectorL10n.authenticationVerifyMsisdnTextFieldPlaceholder,
"The text field should be showing the placeholder before text is input.")
let nextButton = app.buttons["nextButton"]
XCTAssertTrue(nextButton.exists, "The next button should be shown.")
XCTAssertFalse(nextButton.isEnabled, "The next button should be disabled before text is input.")
let resendButton = app.buttons["resendButton"]
XCTAssertFalse(resendButton.exists, "Resend button should be hidden until an SMS is sent.")
let cancelButton = app.navigationBars.firstMatch.buttons["cancelButton"]
XCTAssertTrue(cancelButton.exists, "Cancel button should be shown.")
XCTAssertEqual(cancelButton.label, "Cancel")
}
func verifyEnteredPhoneNumber() {
let titleLabel = app.staticTexts["titleLabel"]
XCTAssertTrue(titleLabel.exists, "The title should be shown.")
let messageLabel = app.staticTexts["messageLabel"]
XCTAssertTrue(messageLabel.exists, "The message should be shown.")
let phoneNumberTextField = app.textFields["phoneNumberTextField"]
XCTAssertTrue(phoneNumberTextField.exists, "The text field should be shown before an SMS is sent.")
XCTAssertEqual(phoneNumberTextField.value as? String, "+44 XXXXXXXXX", "The text field should show entered phone number.")
let nextButton = app.buttons["nextButton"]
XCTAssertTrue(nextButton.exists, "The next button should be shown.")
XCTAssertTrue(nextButton.isEnabled, "The next button should be enabled once a phone number has been input.")
let resendButton = app.buttons["resendButton"]
XCTAssertFalse(resendButton.exists, "Resend button should be hidden until an SMS is sent.")
let cancelButton = app.navigationBars.firstMatch.buttons["cancelButton"]
XCTAssertTrue(cancelButton.exists, "Cancel button should be shown.")
XCTAssertEqual(cancelButton.label, "Cancel")
}
func verifyHasSentSMS() {
let titleLabel = app.staticTexts["titleLabel"]
XCTAssertTrue(titleLabel.exists, "The title should be shown.")
let messageLabel = app.staticTexts["messageLabel"]
XCTAssertTrue(messageLabel.exists, "The message should be shown.")
let phoneNumberTextField = app.textFields["phoneNumberTextField"]
XCTAssertFalse(phoneNumberTextField.exists, "The phone number text field should be hidden once an SMS has been sent.")
let otpTextField = app.textFields["otpTextField"]
XCTAssertTrue(otpTextField.exists, "The OTP text field should be shown once an SMS has been sent.")
XCTAssertEqual(otpTextField.value as? String, VectorL10n.authenticationVerifyMsisdnOtpTextFieldPlaceholder,
"The text field should be showing the placeholder before text is input.")
let nextButton = app.buttons["nextButton"]
XCTAssertTrue(nextButton.exists, "The next button should be shown.")
XCTAssertFalse(nextButton.isEnabled, "The next button should be disabled before text is input.")
let resendButton = app.buttons["resendButton"]
XCTAssertTrue(resendButton.exists, "Resend button should be shown after SMS sent.")
XCTAssertTrue(resendButton.isEnabled, "Resend button should be enabled after an SMS sent once.")
let backButton = app.navigationBars.firstMatch.buttons["cancelButton"]
XCTAssertTrue(backButton.exists, "Back button should be shown.")
XCTAssertEqual(backButton.label, "Back")
}
func verifyEnteredOTP() {
let titleLabel = app.staticTexts["titleLabel"]
XCTAssertTrue(titleLabel.exists, "The title should be shown.")
let messageLabel = app.staticTexts["messageLabel"]
XCTAssertTrue(messageLabel.exists, "The message should be shown.")
let phoneNumberTextField = app.textFields["phoneNumberTextField"]
XCTAssertFalse(phoneNumberTextField.exists, "The phone number text field should be hidden once an SMS has been sent.")
let otpTextField = app.textFields["otpTextField"]
XCTAssertTrue(otpTextField.exists, "The OTP text field should be shown once an SMS has been sent.")
XCTAssertEqual(otpTextField.value as? String, "123456", "The text field should show entered OTP.")
let nextButton = app.buttons["nextButton"]
XCTAssertTrue(nextButton.exists, "The next button should be shown.")
XCTAssertTrue(nextButton.isEnabled, "The next button should be enabled once an OTP has been input.")
let resendButton = app.buttons["resendButton"]
XCTAssertTrue(resendButton.exists, "Resend button should be shown after SMS sent.")
XCTAssertTrue(resendButton.isEnabled, "Resend button should be enabled after an SMS sent once.")
let backButton = app.navigationBars.firstMatch.buttons["cancelButton"]
XCTAssertTrue(backButton.exists, "Back button should be shown.")
XCTAssertEqual(backButton.label, "Back")
}
}