diff --git a/RiotSwiftUI/Modules/AnalyticsPrompt/Test/UI/AnalyticsPromptUITests.swift b/RiotSwiftUI/Modules/AnalyticsPrompt/Test/UI/AnalyticsPromptUITests.swift index fc12e4e74..2013f0866 100644 --- a/RiotSwiftUI/Modules/AnalyticsPrompt/Test/UI/AnalyticsPromptUITests.swift +++ b/RiotSwiftUI/Modules/AnalyticsPrompt/Test/UI/AnalyticsPromptUITests.swift @@ -17,46 +17,32 @@ import XCTest import RiotSwiftUI -class AnalyticsPromptUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockAnalyticsPromptScreenState.self - } - - override class func createTest() -> MockScreenTest { - return AnalyticsPromptUITests(selector: #selector(verifyAnalyticsPromptScreen)) - } - - func verifyAnalyticsPromptScreen() throws { - guard let screenState = screenState as? MockAnalyticsPromptScreenState else { fatalError("no screen") } - switch screenState { - case .promptType(let promptType): - verifyAnalyticsPromptType(promptType) - } - } - - /// Verify that the prompt is displayed correctly for new users compared to upgrading from Matomo - func verifyAnalyticsPromptType(_ promptType: AnalyticsPromptType) { +class AnalyticsPromptUITests: MockScreenTestCase { + /// Verify that the prompt is displayed correctly for new users. + func testAnalyticsPromptNewUser() { + app.goToScreenWithIdentifier(MockAnalyticsPromptScreenState.promptType(.newUser).title) + let enableButton = app.buttons["enableButton"] let disableButton = app.buttons["disableButton"] XCTAssert(enableButton.exists) XCTAssert(disableButton.exists) - switch promptType { - case .newUser: - XCTAssertEqual(enableButton.label, VectorL10n.enable) - XCTAssertEqual(disableButton.label, VectorL10n.locationSharingInvalidAuthorizationNotNow) - case .upgrade: - XCTAssertEqual(enableButton.label, VectorL10n.analyticsPromptYes) - XCTAssertEqual(disableButton.label, VectorL10n.analyticsPromptStop) - } + XCTAssertEqual(enableButton.label, VectorL10n.enable) + XCTAssertEqual(disableButton.label, VectorL10n.locationSharingInvalidAuthorizationNotNow) } - - func verifyAnalyticsPromptLongName(name: String) { - let displayNameText = app.staticTexts["displayNameText"] - XCTAssert(displayNameText.exists) - XCTAssertEqual(displayNameText.label, name) + + /// Verify that the prompt is displayed correctly for when upgrading from Matomo. + func testAnalyticsPromptUpgrade() { + app.goToScreenWithIdentifier(MockAnalyticsPromptScreenState.promptType(.upgrade).title) + + let enableButton = app.buttons["enableButton"] + let disableButton = app.buttons["disableButton"] + + XCTAssert(enableButton.exists) + XCTAssert(disableButton.exists) + + XCTAssertEqual(enableButton.label, VectorL10n.analyticsPromptYes) + XCTAssertEqual(disableButton.label, VectorL10n.analyticsPromptStop) } - } diff --git a/RiotSwiftUI/Modules/Authentication/ChoosePassword/Test/UI/AuthenticationChoosePasswordUITests.swift b/RiotSwiftUI/Modules/Authentication/ChoosePassword/Test/UI/AuthenticationChoosePasswordUITests.swift index c4e7f564a..d1fffa0fb 100644 --- a/RiotSwiftUI/Modules/Authentication/ChoosePassword/Test/UI/AuthenticationChoosePasswordUITests.swift +++ b/RiotSwiftUI/Modules/Authentication/ChoosePassword/Test/UI/AuthenticationChoosePasswordUITests.swift @@ -17,31 +17,10 @@ import XCTest import RiotSwiftUI -class AuthenticationChoosePasswordUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockAuthenticationChoosePasswordScreenState.self - } - - override class func createTest() -> MockScreenTest { - return AuthenticationChoosePasswordUITests(selector: #selector(verifyAuthenticationChoosePasswordScreen)) - } - - func verifyAuthenticationChoosePasswordScreen() throws { - guard let screenState = screenState as? MockAuthenticationChoosePasswordScreenState else { fatalError("no screen") } - switch screenState { - case .emptyPassword: - verifyEmptyPassword() - case .enteredInvalidPassword: - verifyEnteredInvalidPassword() - case .enteredValidPassword: - verifyEnteredValidPassword() - case .enteredValidPasswordAndSignoutAllDevicesChecked: - verifyEnteredValidPasswordAndSignoutAllDevicesChecked() - } - } - - func verifyEmptyPassword() { +class AuthenticationChoosePasswordUITests: MockScreenTestCase { + func testEmptyPassword() { + app.goToScreenWithIdentifier(MockAuthenticationChoosePasswordScreenState.emptyPassword.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown.") XCTAssertTrue(app.staticTexts["messageLabel"].exists, "The message should be shown.") @@ -58,7 +37,9 @@ class AuthenticationChoosePasswordUITests: MockScreenTest { XCTAssertFalse(signoutAllDevicesToggle.isOn, "Sign out all devices should be unchecked") } - func verifyEnteredInvalidPassword() { + func testEnteredInvalidPassword() { + app.goToScreenWithIdentifier(MockAuthenticationChoosePasswordScreenState.enteredInvalidPassword.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown.") XCTAssertTrue(app.staticTexts["messageLabel"].exists, "The message should be shown.") @@ -75,7 +56,9 @@ class AuthenticationChoosePasswordUITests: MockScreenTest { XCTAssertFalse(signoutAllDevicesToggle.isOn, "Sign out all devices should be unchecked") } - func verifyEnteredValidPassword() { + func testEnteredValidPassword() { + app.goToScreenWithIdentifier(MockAuthenticationChoosePasswordScreenState.enteredValidPassword.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown.") XCTAssertTrue(app.staticTexts["messageLabel"].exists, "The message should be shown.") @@ -92,7 +75,9 @@ class AuthenticationChoosePasswordUITests: MockScreenTest { XCTAssertFalse(signoutAllDevicesToggle.isOn, "Sign out all devices should be unchecked") } - func verifyEnteredValidPasswordAndSignoutAllDevicesChecked() { + func testEnteredValidPasswordAndSignoutAllDevicesChecked() { + app.goToScreenWithIdentifier(MockAuthenticationChoosePasswordScreenState.enteredValidPasswordAndSignoutAllDevicesChecked.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown.") XCTAssertTrue(app.staticTexts["messageLabel"].exists, "The message should be shown.") diff --git a/RiotSwiftUI/Modules/Authentication/ForgotPassword/Test/UI/AuthenticationForgotPasswordUITests.swift b/RiotSwiftUI/Modules/Authentication/ForgotPassword/Test/UI/AuthenticationForgotPasswordUITests.swift index 06b1948f4..06478ce2a 100644 --- a/RiotSwiftUI/Modules/Authentication/ForgotPassword/Test/UI/AuthenticationForgotPasswordUITests.swift +++ b/RiotSwiftUI/Modules/Authentication/ForgotPassword/Test/UI/AuthenticationForgotPasswordUITests.swift @@ -17,29 +17,10 @@ import XCTest import RiotSwiftUI -class AuthenticationForgotPasswordUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockAuthenticationForgotPasswordScreenState.self - } - - override class func createTest() -> MockScreenTest { - return AuthenticationForgotPasswordUITests(selector: #selector(verifyAuthenticationForgotPasswordScreen)) - } - - func verifyAuthenticationForgotPasswordScreen() throws { - guard let screenState = screenState as? MockAuthenticationForgotPasswordScreenState else { fatalError("no screen") } - switch screenState { - case .emptyAddress: - verifyEmptyAddress() - case .enteredAddress: - verifyEnteredAddress() - case .hasSentEmail: - verifyWaitingForEmailLink() - } - } - - func verifyEmptyAddress() { +class AuthenticationForgotPasswordUITests: MockScreenTestCase { + func testEmptyAddress() { + app.goToScreenWithIdentifier(MockAuthenticationForgotPasswordScreenState.emptyAddress.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown before an email is sent.") XCTAssertTrue(app.staticTexts["messageLabel"].exists, "The message should be shown before an email is sent.") @@ -66,7 +47,9 @@ class AuthenticationForgotPasswordUITests: MockScreenTest { XCTAssertEqual(cancelButton.label, "Cancel") } - func verifyEnteredAddress() { + func testEnteredAddress() { + app.goToScreenWithIdentifier(MockAuthenticationForgotPasswordScreenState.enteredAddress.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown before an email is sent.") XCTAssertTrue(app.staticTexts["messageLabel"].exists, "The message should be shown before an email is sent.") @@ -92,7 +75,9 @@ class AuthenticationForgotPasswordUITests: MockScreenTest { XCTAssertEqual(cancelButton.label, "Cancel") } - func verifyWaitingForEmailLink() { + func testWaitingForEmailLink() { + app.goToScreenWithIdentifier(MockAuthenticationForgotPasswordScreenState.hasSentEmail.title) + XCTAssertFalse(app.staticTexts["titleLabel"].exists, "The title should be hidden once an email has been sent.") XCTAssertFalse(app.staticTexts["messageLabel"].exists, "The message should be hidden once an email has been sent.") XCTAssertFalse(app.textFields["addressTextField"].exists, "The text field should be hidden once an email has been sent.") diff --git a/RiotSwiftUI/Modules/Authentication/Login/Test/UI/AuthenticationLoginUITests.swift b/RiotSwiftUI/Modules/Authentication/Login/Test/UI/AuthenticationLoginUITests.swift index 7824a24fa..8dcf6eb63 100644 --- a/RiotSwiftUI/Modules/Authentication/Login/Test/UI/AuthenticationLoginUITests.swift +++ b/RiotSwiftUI/Modules/Authentication/Login/Test/UI/AuthenticationLoginUITests.swift @@ -17,40 +17,45 @@ import XCTest import RiotSwiftUI -class AuthenticationLoginUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockAuthenticationLoginScreenState.self - } - - override class func createTest() -> MockScreenTest { - return AuthenticationLoginUITests(selector: #selector(verifyAuthenticationLoginScreen)) +class AuthenticationLoginUITests: MockScreenTestCase { + func testMatrixDotOrg() { + app.goToScreenWithIdentifier(MockAuthenticationLoginScreenState.matrixDotOrg.title) + + let state = "matrix.org" + validateLoginFormIsVisible(for: state) + validateSSOButtonsAreShown(for: state) } - func verifyAuthenticationLoginScreen() throws { - guard let screenState = screenState as? MockAuthenticationLoginScreenState else { fatalError("no screen") } - switch screenState { - case .matrixDotOrg: - let state = "matrix.org" - validateLoginFormIsVisible(for: state) - validateSSOButtonsAreShown(for: state) - case .passwordOnly: - let state = "a password only server" - validateLoginFormIsVisible(for: state) - validateSSOButtonsAreHidden(for: state) - - validateNextButtonIsDisabled(for: state) - case .passwordWithCredentials: - let state = "a password only server with credentials entered" - validateNextButtonIsEnabled(for: state) - case .ssoOnly: - let state = "an SSO only server" - validateLoginFormIsHidden(for: state) - validateSSOButtonsAreShown(for: state) - case .fallback: - let state = "a fallback server" - validateFallback(for: state) - } + func testPasswordOnly() { + app.goToScreenWithIdentifier(MockAuthenticationLoginScreenState.passwordOnly.title) + + let state = "a password only server" + validateLoginFormIsVisible(for: state) + validateSSOButtonsAreHidden(for: state) + + validateNextButtonIsDisabled(for: state) + } + + func testPasswordWithCredentials() { + app.goToScreenWithIdentifier(MockAuthenticationLoginScreenState.passwordWithCredentials.title) + + let state = "a password only server with credentials entered" + validateNextButtonIsEnabled(for: state) + } + + func testSSOOnly() { + app.goToScreenWithIdentifier(MockAuthenticationLoginScreenState.ssoOnly.title) + + let state = "an SSO only server" + validateLoginFormIsHidden(for: state) + validateSSOButtonsAreShown(for: state) + } + + func testFallback() { + app.goToScreenWithIdentifier(MockAuthenticationLoginScreenState.fallback.title) + + let state = "a fallback server" + validateFallback(for: state) } /// Checks that the username and password text fields are shown along with the next button. diff --git a/RiotSwiftUI/Modules/Authentication/ReCaptcha/Test/UI/AuthenticationReCaptchaUITests.swift b/RiotSwiftUI/Modules/Authentication/ReCaptcha/Test/UI/AuthenticationReCaptchaUITests.swift index bd198bf86..ac8ff628c 100644 --- a/RiotSwiftUI/Modules/Authentication/ReCaptcha/Test/UI/AuthenticationReCaptchaUITests.swift +++ b/RiotSwiftUI/Modules/Authentication/ReCaptcha/Test/UI/AuthenticationReCaptchaUITests.swift @@ -17,6 +17,6 @@ import XCTest import RiotSwiftUI -class AuthenticationReCaptchaUITests: MockScreenTest { +class AuthenticationReCaptchaUITests: MockScreenTestCase { // Nothing to test as the view only has a single state. } diff --git a/RiotSwiftUI/Modules/Authentication/Registration/Test/UI/AuthenticationRegistrationUITests.swift b/RiotSwiftUI/Modules/Authentication/Registration/Test/UI/AuthenticationRegistrationUITests.swift index a94ee11df..223d20c40 100644 --- a/RiotSwiftUI/Modules/Authentication/Registration/Test/UI/AuthenticationRegistrationUITests.swift +++ b/RiotSwiftUI/Modules/Authentication/Registration/Test/UI/AuthenticationRegistrationUITests.swift @@ -17,69 +17,78 @@ import XCTest import RiotSwiftUI -class AuthenticationRegistrationUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockAuthenticationRegistrationScreenState.self +class AuthenticationRegistrationUITests: MockScreenTestCase { + func testMatrixDotOrg() { + app.goToScreenWithIdentifier(MockAuthenticationRegistrationScreenState.matrixDotOrg.title) + + let state = "matrix.org" + validateRegistrationFormIsVisible(for: state) + validateSSOButtonsAreShown(for: state) + validateFallbackButtonIsHidden(for: state) + + validateUnknownUsernameAvailability(for: state) + validateNoPasswordErrorsAreShown(for: state) } - - override class func createTest() -> MockScreenTest { - return AuthenticationRegistrationUITests(selector: #selector(verifyAuthenticationRegistrationScreen)) + + func testPasswordOnly() { + app.goToScreenWithIdentifier(MockAuthenticationRegistrationScreenState.passwordOnly.title) + + let state = "a password only server" + validateRegistrationFormIsVisible(for: state) + validateSSOButtonsAreHidden(for: state) + validateFallbackButtonIsHidden(for: state) + + validateNextButtonIsDisabled(for: state) + + validateUnknownUsernameAvailability(for: state) + validateNoPasswordErrorsAreShown(for: state) } - - func verifyAuthenticationRegistrationScreen() throws { - guard let screenState = screenState as? MockAuthenticationRegistrationScreenState else { fatalError("no screen") } - switch screenState { - case .matrixDotOrg: - let state = "matrix.org" - validateRegistrationFormIsVisible(for: state) - validateSSOButtonsAreShown(for: state) - validateFallbackButtonIsHidden(for: state) - - validateUnknownUsernameAvailability(for: state) - validateNoPasswordErrorsAreShown(for: state) - case .passwordOnly: - let state = "a password only server" - validateRegistrationFormIsVisible(for: state) - validateSSOButtonsAreHidden(for: state) - validateFallbackButtonIsHidden(for: state) - - validateNextButtonIsDisabled(for: state) - - validateUnknownUsernameAvailability(for: state) - validateNoPasswordErrorsAreShown(for: state) - case .passwordWithCredentials: - let state = "a password only server with credentials entered" - validateRegistrationFormIsVisible(for: state) - validateSSOButtonsAreHidden(for: state) - validateFallbackButtonIsHidden(for: state) - - validateNextButtonIsEnabled(for: state) - - validateUsernameAvailable(for: state) - validateNoPasswordErrorsAreShown(for: state) - case .passwordWithUsernameError: - let state = "a password only server with an invalid username" - validateRegistrationFormIsVisible(for: state) - validateSSOButtonsAreHidden(for: state) - validateFallbackButtonIsHidden(for: state) - - validateNextButtonIsDisabled(for: state) - - validateUsernameError(for: state) - case .ssoOnly: - let state = "an SSO only server" - validateRegistrationFormIsHidden(for: state) - validateSSOButtonsAreShown(for: state) - validateFallbackButtonIsHidden(for: state) - case .fallback: - let state = "fallback" - validateRegistrationFormIsHidden(for: state) - validateSSOButtonsAreHidden(for: state) - validateFallbackButtonIsShown(for: state) - } + + func testPasswordWithCredentials() { + app.goToScreenWithIdentifier(MockAuthenticationRegistrationScreenState.passwordWithCredentials.title) + + let state = "a password only server with credentials entered" + validateRegistrationFormIsVisible(for: state) + validateSSOButtonsAreHidden(for: state) + validateFallbackButtonIsHidden(for: state) + + validateNextButtonIsEnabled(for: state) + + validateUsernameAvailable(for: state) + validateNoPasswordErrorsAreShown(for: state) } + func testPasswordWithUsernameError() { + app.goToScreenWithIdentifier(MockAuthenticationRegistrationScreenState.passwordWithUsernameError.title) + + let state = "a password only server with an invalid username" + validateRegistrationFormIsVisible(for: state) + validateSSOButtonsAreHidden(for: state) + validateFallbackButtonIsHidden(for: state) + + validateNextButtonIsDisabled(for: state) + validateUsernameError(for: state) + } + + func testSSOOnly() { + app.goToScreenWithIdentifier(MockAuthenticationRegistrationScreenState.ssoOnly.title) + + let state = "an SSO only server" + validateRegistrationFormIsHidden(for: state) + validateSSOButtonsAreShown(for: state) + validateFallbackButtonIsHidden(for: state) + } + + func testFallback() { + app.goToScreenWithIdentifier(MockAuthenticationRegistrationScreenState.fallback.title) + + let state = "fallback" + validateRegistrationFormIsHidden(for: state) + validateSSOButtonsAreHidden(for: state) + validateFallbackButtonIsShown(for: state) + } + + /// Checks that the username and password text fields are shown along with the next button. func validateRegistrationFormIsVisible(for state: String) { let usernameTextField = app.textFields.element diff --git a/RiotSwiftUI/Modules/Authentication/ServerSelection/Test/UI/AuthenticationServerSelectionUITests.swift b/RiotSwiftUI/Modules/Authentication/ServerSelection/Test/UI/AuthenticationServerSelectionUITests.swift index 53f21e0d7..e72e00ec4 100644 --- a/RiotSwiftUI/Modules/Authentication/ServerSelection/Test/UI/AuthenticationServerSelectionUITests.swift +++ b/RiotSwiftUI/Modules/Authentication/ServerSelection/Test/UI/AuthenticationServerSelectionUITests.swift @@ -17,33 +17,10 @@ import XCTest import RiotSwiftUI -class AuthenticationServerSelectionUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockAuthenticationServerSelectionScreenState.self - } - - override class func createTest() -> MockScreenTest { - return AuthenticationServerSelectionUITests(selector: #selector(verifyAuthenticationServerSelectionScreen)) - } - - func verifyAuthenticationServerSelectionScreen() throws { - guard let screenState = screenState as? MockAuthenticationServerSelectionScreenState else { fatalError("no screen") } - switch screenState { - case .matrix: - verifyRegisterState() - case .login: - verifyLoginState() - case .emptyAddress: - verifyEmptyAddress() - case .invalidAddress: - verifyInvalidAddress() - case .nonModal: - verifyNonModalPresentation() - } - } - - func verifyRegisterState() { +class AuthenticationServerSelectionUITests: MockScreenTestCase { + func testRegisterState() { + app.goToScreenWithIdentifier(MockAuthenticationServerSelectionScreenState.matrix.title) + let title = app.staticTexts["headerTitle"] XCTAssertEqual(title.label, VectorL10n.authenticationServerSelectionRegisterTitle) let message = app.staticTexts["headerMessage"] @@ -65,14 +42,18 @@ class AuthenticationServerSelectionUITests: MockScreenTest { } - func verifyLoginState() { + func testLoginState() { + app.goToScreenWithIdentifier(MockAuthenticationServerSelectionScreenState.login.title) + let title = app.staticTexts["headerTitle"] XCTAssertEqual(title.label, VectorL10n.authenticationServerSelectionLoginTitle) let message = app.staticTexts["headerMessage"] XCTAssertEqual(message.label, VectorL10n.authenticationServerSelectionLoginMessage) } - func verifyEmptyAddress() { + func testEmptyAddress() { + app.goToScreenWithIdentifier(MockAuthenticationServerSelectionScreenState.emptyAddress.title) + let serverTextField = app.textFields.element XCTAssertEqual(serverTextField.value as? String, VectorL10n.authenticationServerSelectionServerUrl, "The text field should show placeholder text in this state.") @@ -81,7 +62,9 @@ class AuthenticationServerSelectionUITests: MockScreenTest { XCTAssertFalse(confirmButton.isEnabled, "The confirm button should be disabled when the address is empty.") } - func verifyInvalidAddress() { + func testInvalidAddress() { + app.goToScreenWithIdentifier(MockAuthenticationServerSelectionScreenState.invalidAddress.title) + let serverTextField = app.textFields.element XCTAssertEqual(serverTextField.value as? String, "thisisbad", "The text field should show the entered server.") @@ -94,7 +77,9 @@ class AuthenticationServerSelectionUITests: MockScreenTest { XCTAssertEqual(textFieldFooter.label, VectorL10n.errorCommonMessage) } - func verifyNonModalPresentation() { + func testNonModalPresentation() { + app.goToScreenWithIdentifier(MockAuthenticationServerSelectionScreenState.nonModal.title) + let dismissButton = app.buttons["dismissButton"] XCTAssertFalse(dismissButton.exists, "The dismiss button should be hidden when not in modal presentation.") diff --git a/RiotSwiftUI/Modules/Authentication/SoftLogout/Test/UI/AuthenticationSoftLogoutUITests.swift b/RiotSwiftUI/Modules/Authentication/SoftLogout/Test/UI/AuthenticationSoftLogoutUITests.swift index 52bd56ca5..52268610a 100644 --- a/RiotSwiftUI/Modules/Authentication/SoftLogout/Test/UI/AuthenticationSoftLogoutUITests.swift +++ b/RiotSwiftUI/Modules/Authentication/SoftLogout/Test/UI/AuthenticationSoftLogoutUITests.swift @@ -17,35 +17,10 @@ import XCTest import RiotSwiftUI -class AuthenticationSoftLogoutUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockAuthenticationSoftLogoutScreenState.self - } - - override class func createTest() -> MockScreenTest { - return AuthenticationSoftLogoutUITests(selector: #selector(verifyAuthenticationSoftLogoutScreen)) - } - - func verifyAuthenticationSoftLogoutScreen() throws { - guard let screenState = screenState as? MockAuthenticationSoftLogoutScreenState else { fatalError("no screen") } - switch screenState { - case .emptyPassword: - verifyEmptyPassword() - case .enteredPassword: - verifyEnteredPassword() - case .ssoOnly: - verifySSOOnly() - case .noSSO: - verifyNoSSO() - case .fallback: - verifyFallback() - case .noKeyBackup: - verifyNoKeyBackup() - } - } - - func verifyEmptyPassword() { +class AuthenticationSoftLogoutUITests: MockScreenTestCase { + func testEmptyPassword() { + app.goToScreenWithIdentifier(MockAuthenticationSoftLogoutScreenState.emptyPassword.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown.") XCTAssertTrue(app.staticTexts["messageLabel1"].exists, "The message 1 should be shown.") XCTAssertTrue(app.staticTexts["messageLabel2"].exists, "The message 2 should be shown.") @@ -77,7 +52,9 @@ class AuthenticationSoftLogoutUITests: MockScreenTest { XCTAssertGreaterThan(ssoButtons.count, 0, "There should be at least 1 SSO button shown.") } - func verifyEnteredPassword() { + func testEnteredPassword() { + app.goToScreenWithIdentifier(MockAuthenticationSoftLogoutScreenState.enteredPassword.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown.") XCTAssertTrue(app.staticTexts["messageLabel1"].exists, "The message 1 should be shown.") XCTAssertTrue(app.staticTexts["messageLabel2"].exists, "The message 2 should be shown.") @@ -109,7 +86,9 @@ class AuthenticationSoftLogoutUITests: MockScreenTest { XCTAssertGreaterThan(ssoButtons.count, 0, "There should be at least 1 SSO button shown.") } - func verifySSOOnly() { + func testSSOOnly() { + app.goToScreenWithIdentifier(MockAuthenticationSoftLogoutScreenState.ssoOnly.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown.") XCTAssertTrue(app.staticTexts["messageLabel1"].exists, "The message 1 should be shown.") XCTAssertTrue(app.staticTexts["messageLabel2"].exists, "The message 2 should be shown.") @@ -138,7 +117,9 @@ class AuthenticationSoftLogoutUITests: MockScreenTest { XCTAssertGreaterThan(ssoButtons.count, 0, "There should be at least 1 SSO button shown.") } - func verifyNoSSO() { + func testNoSSO() { + app.goToScreenWithIdentifier(MockAuthenticationSoftLogoutScreenState.noSSO.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown.") XCTAssertTrue(app.staticTexts["messageLabel1"].exists, "The message 1 should be shown.") XCTAssertTrue(app.staticTexts["messageLabel2"].exists, "The message 2 should be shown.") @@ -167,7 +148,9 @@ class AuthenticationSoftLogoutUITests: MockScreenTest { XCTAssertEqual(ssoButtons.count, 0, "There should be no SSO button shown.") } - func verifyFallback() { + func testFallback() { + app.goToScreenWithIdentifier(MockAuthenticationSoftLogoutScreenState.fallback.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown.") XCTAssertTrue(app.staticTexts["messageLabel1"].exists, "The message 1 should be shown.") XCTAssertTrue(app.staticTexts["messageLabel2"].exists, "The message 2 should be shown.") @@ -197,7 +180,9 @@ class AuthenticationSoftLogoutUITests: MockScreenTest { XCTAssertEqual(ssoButtons.count, 0, "There should be no SSO button shown.") } - func verifyNoKeyBackup() { + func testNoKeyBackup() { + app.goToScreenWithIdentifier(MockAuthenticationSoftLogoutScreenState.noKeyBackup.title) + XCTAssertFalse(app.staticTexts["messageLabel2"].exists, "The message 2 should not be shown.") } diff --git a/RiotSwiftUI/Modules/Authentication/Terms/Test/UI/AuthenticationTermsUITests.swift b/RiotSwiftUI/Modules/Authentication/Terms/Test/UI/AuthenticationTermsUITests.swift index f7ea429eb..3cb31c36a 100644 --- a/RiotSwiftUI/Modules/Authentication/Terms/Test/UI/AuthenticationTermsUITests.swift +++ b/RiotSwiftUI/Modules/Authentication/Terms/Test/UI/AuthenticationTermsUITests.swift @@ -17,26 +17,20 @@ import XCTest import RiotSwiftUI -class AuthenticationTermsUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockAuthenticationTermsScreenState.self +class AuthenticationTermsUITests: MockScreenTestCase { + func testMatrixDotOrg() { + app.goToScreenWithIdentifier(MockAuthenticationTermsScreenState.matrixDotOrg.title) + verifyTerms(accepted: false) } - - override class func createTest() -> MockScreenTest { - return AuthenticationTermsUITests(selector: #selector(verifyAuthenticationTermsScreen)) + + func testAccepted() { + app.goToScreenWithIdentifier(MockAuthenticationTermsScreenState.accepted.title) + verifyTerms(accepted: true) } - - func verifyAuthenticationTermsScreen() throws { - guard let screenState = screenState as? MockAuthenticationTermsScreenState else { fatalError("no screen") } - switch screenState { - case .matrixDotOrg: - verifyTerms(accepted: false) - case .accepted: - verifyTerms(accepted: true) - case .multiple: - verifyTerms(accepted: false) - } + + func testMultiple() { + app.goToScreenWithIdentifier(MockAuthenticationTermsScreenState.multiple.title) + verifyTerms(accepted: false) } func verifyTerms(accepted: Bool) { diff --git a/RiotSwiftUI/Modules/Authentication/VerifyEmail/Test/UI/AuthenticationVerifyEmailUITests.swift b/RiotSwiftUI/Modules/Authentication/VerifyEmail/Test/UI/AuthenticationVerifyEmailUITests.swift index c80a0cdb8..73706abcd 100644 --- a/RiotSwiftUI/Modules/Authentication/VerifyEmail/Test/UI/AuthenticationVerifyEmailUITests.swift +++ b/RiotSwiftUI/Modules/Authentication/VerifyEmail/Test/UI/AuthenticationVerifyEmailUITests.swift @@ -17,29 +17,10 @@ import XCTest import RiotSwiftUI -class AuthenticationVerifyEmailUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockAuthenticationVerifyEmailScreenState.self - } - - override class func createTest() -> MockScreenTest { - return AuthenticationVerifyEmailUITests(selector: #selector(verifyAuthenticationVerifyEmailScreen)) - } - - func verifyAuthenticationVerifyEmailScreen() throws { - guard let screenState = screenState as? MockAuthenticationVerifyEmailScreenState else { fatalError("no screen") } - switch screenState { - case .emptyAddress: - verifyEmptyAddress() - case .enteredAddress: - verifyEnteredAddress() - case .hasSentEmail: - verifyWaitingForEmailLink() - } - } - - func verifyEmptyAddress() { +class AuthenticationVerifyEmailUITests: MockScreenTestCase { + func testEmptyAddress() { + app.goToScreenWithIdentifier(MockAuthenticationVerifyEmailScreenState.emptyAddress.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown before an email is sent.") XCTAssertTrue(app.staticTexts["messageLabel"].exists, "The message should be shown before an email is sent.") @@ -60,7 +41,9 @@ class AuthenticationVerifyEmailUITests: MockScreenTest { XCTAssertEqual(cancelButton.label, "Cancel") } - func verifyEnteredAddress() { + func testEnteredAddress() { + app.goToScreenWithIdentifier(MockAuthenticationVerifyEmailScreenState.enteredAddress.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown before an email is sent.") XCTAssertTrue(app.staticTexts["messageLabel"].exists, "The message should be shown before an email is sent.") @@ -80,7 +63,9 @@ class AuthenticationVerifyEmailUITests: MockScreenTest { XCTAssertEqual(cancelButton.label, "Cancel") } - func verifyWaitingForEmailLink() { + func testWaitingForEmailLink() { + app.goToScreenWithIdentifier(MockAuthenticationVerifyEmailScreenState.hasSentEmail.title) + XCTAssertFalse(app.staticTexts["titleLabel"].exists, "The title should be hidden once an email has been sent.") XCTAssertFalse(app.staticTexts["messageLabel"].exists, "The message should be hidden once an email has been sent.") XCTAssertFalse(app.textFields["addressTextField"].exists, "The text field should be hidden once an email has been sent.") diff --git a/RiotSwiftUI/Modules/Authentication/VerifyMsisdn/Test/UI/AuthenticationVerifyMsisdnUITests.swift b/RiotSwiftUI/Modules/Authentication/VerifyMsisdn/Test/UI/AuthenticationVerifyMsisdnUITests.swift index a9fddacb8..f5528acfa 100644 --- a/RiotSwiftUI/Modules/Authentication/VerifyMsisdn/Test/UI/AuthenticationVerifyMsisdnUITests.swift +++ b/RiotSwiftUI/Modules/Authentication/VerifyMsisdn/Test/UI/AuthenticationVerifyMsisdnUITests.swift @@ -17,31 +17,10 @@ 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() { +class AuthenticationVerifyMsisdnUITests: MockScreenTestCase { + func testEmptyPhoneNumber() { + app.goToScreenWithIdentifier(MockAuthenticationVerifyMsisdnScreenState.emptyPhoneNumber.title) + let titleLabel = app.staticTexts["titleLabel"] XCTAssertTrue(titleLabel.exists, "The title should be shown.") @@ -65,7 +44,9 @@ class AuthenticationVerifyMsisdnUITests: MockScreenTest { XCTAssertEqual(cancelButton.label, "Cancel") } - func verifyEnteredPhoneNumber() { + func testEnteredPhoneNumber() { + app.goToScreenWithIdentifier(MockAuthenticationVerifyMsisdnScreenState.enteredPhoneNumber.title) + let titleLabel = app.staticTexts["titleLabel"] XCTAssertTrue(titleLabel.exists, "The title should be shown.") @@ -88,7 +69,9 @@ class AuthenticationVerifyMsisdnUITests: MockScreenTest { XCTAssertEqual(cancelButton.label, "Cancel") } - func verifyHasSentSMS() { + func testHasSentSMS() { + app.goToScreenWithIdentifier(MockAuthenticationVerifyMsisdnScreenState.hasSentSMS.title) + let titleLabel = app.staticTexts["titleLabel"] XCTAssertTrue(titleLabel.exists, "The title should be shown.") @@ -116,7 +99,9 @@ class AuthenticationVerifyMsisdnUITests: MockScreenTest { XCTAssertEqual(backButton.label, "Back") } - func verifyEnteredOTP() { + func testEnteredOTP() { + app.goToScreenWithIdentifier(MockAuthenticationVerifyMsisdnScreenState.enteredOTP.title) + let titleLabel = app.staticTexts["titleLabel"] XCTAssertTrue(titleLabel.exists, "The title should be shown.") diff --git a/RiotSwiftUI/Modules/Common/Test/UI/MockScreenTest.swift b/RiotSwiftUI/Modules/Common/Test/UI/MockScreenTest.swift index 583b6099c..3c00337d1 100644 --- a/RiotSwiftUI/Modules/Common/Test/UI/MockScreenTest.swift +++ b/RiotSwiftUI/Modules/Common/Test/UI/MockScreenTest.swift @@ -18,55 +18,16 @@ import XCTest import RiotSwiftUI /// XCTestCase subclass to ease testing of `MockScreenState`. -/// Creates a test case for each screen state, launches the app, -/// goes to the correct screen and provides the state and key for each -/// invocation of the test. -class MockScreenTest: XCTestCase { - - enum Constants { - static let defaultTimeout: TimeInterval = 3 - } - - class var screenType: MockScreenState.Type? { - return nil - } - - class func createTest() -> MockScreenTest { - return MockScreenTest() - } - - var screenState: MockScreenState? - var screenStateKey: String? +/// Launches the app with an environment variable used to disable animations. +/// Begin each test with the following code before checking the UI: +/// ``` +/// app.goToScreenWithIdentifier(MockTemplateScreenState.someScreenState.title) +/// ``` +class MockScreenTestCase: XCTestCase { let app = XCUIApplication() - - override class var defaultTestSuite: XCTestSuite { - let testSuite = XCTestSuite(name: NSStringFromClass(self)) - guard let screenType = screenType else { - return testSuite - } - - // Create a test case for each screen state - screenType.screenStates.enumerated().forEach { index, screenState in - let key = screenType.screenNames[index] - addTestFor(screenState: screenState, screenStateKey: key, toTestSuite: testSuite) - } - return testSuite - } - - class func addTestFor(screenState: MockScreenState, screenStateKey: String, toTestSuite testSuite: XCTestSuite) { - let test = createTest() - test.screenState = screenState - test.screenStateKey = screenStateKey - testSuite.addTest(test) - } open override func setUpWithError() throws { - // For every test case launch the app and go to the relevant screen - continueAfterFailure = false app.launchEnvironment = ["IS_RUNNING_UI_TESTS": "1"] app.launch() - - guard let screenKey = screenStateKey else { fatalError("no screen") } - app.goToScreenWithIdentifier(screenKey) } } diff --git a/RiotSwiftUI/Modules/LocationSharing/LiveLocationLabPromotion/Test/UI/LiveLocationLabPromotionUITests.swift b/RiotSwiftUI/Modules/LocationSharing/LiveLocationLabPromotion/Test/UI/LiveLocationLabPromotionUITests.swift index 20fe9f0a5..4b71228fc 100644 --- a/RiotSwiftUI/Modules/LocationSharing/LiveLocationLabPromotion/Test/UI/LiveLocationLabPromotionUITests.swift +++ b/RiotSwiftUI/Modules/LocationSharing/LiveLocationLabPromotion/Test/UI/LiveLocationLabPromotionUITests.swift @@ -17,6 +17,6 @@ import XCTest import RiotSwiftUI -class LiveLocationLabPromotionUITests: MockScreenTest { +class LiveLocationLabPromotionUITests: MockScreenTestCase { // Nothing to test as the view is completely static } diff --git a/RiotSwiftUI/Modules/Onboarding/Avatar/Test/UI/OnboardingAvatarUITests.swift b/RiotSwiftUI/Modules/Onboarding/Avatar/Test/UI/OnboardingAvatarUITests.swift index 762728dd5..dc71847b5 100644 --- a/RiotSwiftUI/Modules/Onboarding/Avatar/Test/UI/OnboardingAvatarUITests.swift +++ b/RiotSwiftUI/Modules/Onboarding/Avatar/Test/UI/OnboardingAvatarUITests.swift @@ -17,27 +17,13 @@ import XCTest import RiotSwiftUI -class OnboardingAvatarUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockOnboardingAvatarScreenState.self - } - - override class func createTest() -> MockScreenTest { - return OnboardingAvatarUITests(selector: #selector(verifyOnboardingAvatarScreen)) - } - - func verifyOnboardingAvatarScreen() throws { - guard let screenState = screenState as? MockOnboardingAvatarScreenState else { fatalError("no screen") } - switch screenState { - case .placeholderAvatar(let userId, let displayName): - verifyPlaceholderAvatar(userId: userId, displayName: displayName) - case .userSelectedAvatar: - verifyUserSelectedAvatar() - } - } +class OnboardingAvatarUITests: MockScreenTestCase { + let userId = "@example:matrix.org" + let displayName = "Jane" - func verifyPlaceholderAvatar(userId: String, displayName: String) { + func testPlaceholderAvatar() { + app.goToScreenWithIdentifier(MockOnboardingAvatarScreenState.placeholderAvatar(userId: userId, displayName: displayName).title) + guard let firstLetter = displayName.uppercased().first else { XCTFail("Unable to get the first letter of the display name.") return @@ -55,7 +41,9 @@ class OnboardingAvatarUITests: MockScreenTest { XCTAssertFalse(saveButton.isEnabled, "The save button should not be enabled.") } - func verifyUserSelectedAvatar() { + func testUserSelectedAvatar() { + app.goToScreenWithIdentifier(MockOnboardingAvatarScreenState.userSelectedAvatar(userId: userId, displayName: displayName).title) + let placeholderAvatar = app.otherElements["placeholderAvatar"] XCTAssertFalse(placeholderAvatar.exists, "The placeholder avatar should be hidden.") diff --git a/RiotSwiftUI/Modules/Onboarding/Celebration/Test/UI/OnboardingCelebrationUITests.swift b/RiotSwiftUI/Modules/Onboarding/Celebration/Test/UI/OnboardingCelebrationUITests.swift index 27de0a119..12d0f210a 100644 --- a/RiotSwiftUI/Modules/Onboarding/Celebration/Test/UI/OnboardingCelebrationUITests.swift +++ b/RiotSwiftUI/Modules/Onboarding/Celebration/Test/UI/OnboardingCelebrationUITests.swift @@ -17,6 +17,6 @@ import XCTest import RiotSwiftUI -class OnboardingCelebrationUITests: MockScreenTest { +class OnboardingCelebrationUITests: MockScreenTestCase { // Nothing to test as the view is completely static } diff --git a/RiotSwiftUI/Modules/Onboarding/Congratulations/Test/UI/OnboardingCongratulationsUITests.swift b/RiotSwiftUI/Modules/Onboarding/Congratulations/Test/UI/OnboardingCongratulationsUITests.swift index 43ccaffb8..9b4c8f9f6 100644 --- a/RiotSwiftUI/Modules/Onboarding/Congratulations/Test/UI/OnboardingCongratulationsUITests.swift +++ b/RiotSwiftUI/Modules/Onboarding/Congratulations/Test/UI/OnboardingCongratulationsUITests.swift @@ -17,27 +17,10 @@ import XCTest import RiotSwiftUI -class OnboardingCongratulationsUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockOnboardingCongratulationsScreenState.self - } - - override class func createTest() -> MockScreenTest { - return OnboardingCongratulationsUITests(selector: #selector(verifyOnboardingCongratulationsScreen)) - } - - func verifyOnboardingCongratulationsScreen() throws { - guard let screenState = screenState as? MockOnboardingCongratulationsScreenState else { fatalError("no screen") } - switch screenState { - case .regular: - verifyButtons() - case .personalizationDisabled: - verifyButtonsWhenPersonalizationIsDisabled() - } - } - - func verifyButtons() { +class OnboardingCongratulationsUITests: MockScreenTestCase { + func testButtons() { + app.goToScreenWithIdentifier(MockOnboardingCongratulationsScreenState.regular.title) + let personalizeButton = app.buttons["personalizeButton"] XCTAssertTrue(personalizeButton.exists, "The personalization button should be shown.") @@ -45,7 +28,9 @@ class OnboardingCongratulationsUITests: MockScreenTest { XCTAssertTrue(homeButton.exists, "The home button should always be shown.") } - func verifyButtonsWhenPersonalizationIsDisabled() { + func testButtonsWhenPersonalizationIsDisabled() { + app.goToScreenWithIdentifier(MockOnboardingCongratulationsScreenState.personalizationDisabled.title) + let personalizeButton = app.buttons["personalizeButton"] XCTAssertFalse(personalizeButton.exists, "The personalization button should be hidden.") diff --git a/RiotSwiftUI/Modules/Onboarding/DisplayName/Test/UI/OnboardingDisplayNameUITests.swift b/RiotSwiftUI/Modules/Onboarding/DisplayName/Test/UI/OnboardingDisplayNameUITests.swift index 177be76e3..6c27e09de 100644 --- a/RiotSwiftUI/Modules/Onboarding/DisplayName/Test/UI/OnboardingDisplayNameUITests.swift +++ b/RiotSwiftUI/Modules/Onboarding/DisplayName/Test/UI/OnboardingDisplayNameUITests.swift @@ -17,29 +17,10 @@ import XCTest import RiotSwiftUI -class OnboardingDisplayNameUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockOnboardingDisplayNameScreenState.self - } - - override class func createTest() -> MockScreenTest { - return OnboardingDisplayNameUITests(selector: #selector(verifyOnboardingDisplayNameScreen)) - } - - func verifyOnboardingDisplayNameScreen() throws { - guard let screenState = screenState as? MockOnboardingDisplayNameScreenState else { fatalError("no screen") } - switch screenState { - case .emptyTextField: - verifyEmptyTextField() - case .filledTextField(let displayName): - verifyDisplayName(displayName: displayName) - case .longDisplayName(displayName: let displayName): - verifyLongDisplayName(displayName: displayName) - } - } - - func verifyEmptyTextField() { +class OnboardingDisplayNameUITests: MockScreenTestCase { + func testEmptyTextField() { + app.goToScreenWithIdentifier(MockOnboardingDisplayNameScreenState.emptyTextField.title) + let textField = app.textFields.element XCTAssertTrue(textField.exists, "The textfield should always be shown.") XCTAssertEqual(textField.value as? String, VectorL10n.onboardingDisplayNamePlaceholder, "When the textfield is empty, the value should match the placeholder.") @@ -54,7 +35,10 @@ class OnboardingDisplayNameUITests: MockScreenTest { XCTAssertFalse(saveButton.isEnabled, "The save button should not be enabled.") } - func verifyDisplayName(displayName: String) { + func testDisplayName() { + let displayName = "Test User" + app.goToScreenWithIdentifier(MockOnboardingDisplayNameScreenState.filledTextField(displayName: displayName).title) + let textField = app.textFields.element XCTAssertTrue(textField.exists, "The textfield should always be shown.") XCTAssertEqual(textField.value as? String, displayName, "When a name has been set, it should show in the textfield.") @@ -69,7 +53,12 @@ class OnboardingDisplayNameUITests: MockScreenTest { XCTAssertEqual(footer.label, VectorL10n.onboardingDisplayNameHint, "The footer should display a hint when an acceptable name is entered.") } - func verifyLongDisplayName(displayName: String) { + func testLongDisplayName() { + let displayName = """ + Bacon ipsum dolor amet filet mignon chicken kevin andouille. Doner shoulder beef, brisket bresaola turkey jowl venison. Ham hock cow turducken, chislic venison doner short loin strip steak tri-tip jowl. Sirloin pork belly hamburger ribeye. Tail capicola alcatra short ribs turkey doner. + """ + app.goToScreenWithIdentifier(MockOnboardingDisplayNameScreenState.longDisplayName(displayName: displayName).title) + let textField = app.textFields.element XCTAssertTrue(textField.exists, "The textfield should always be shown.") XCTAssertEqual(textField.value as? String, displayName, "When a name has been set, it should show in the textfield.") diff --git a/RiotSwiftUI/Modules/Onboarding/UseCase/Test/UI/OnboardingUseCaseUITests.swift b/RiotSwiftUI/Modules/Onboarding/UseCase/Test/UI/OnboardingUseCaseUITests.swift index 929e6e328..fbb0a9a64 100644 --- a/RiotSwiftUI/Modules/Onboarding/UseCase/Test/UI/OnboardingUseCaseUITests.swift +++ b/RiotSwiftUI/Modules/Onboarding/UseCase/Test/UI/OnboardingUseCaseUITests.swift @@ -17,6 +17,6 @@ import XCTest import RiotSwiftUI -class OnboardingUseCaseUITests: MockScreenTest { +class OnboardingUseCaseUITests: MockScreenTestCase { // The view has no parameters or changing state to test. } diff --git a/RiotSwiftUI/Modules/Room/LiveLocationSharingViewer/Test/UI/LiveLocationSharingViewerUITests.swift b/RiotSwiftUI/Modules/Room/LiveLocationSharingViewer/Test/UI/LiveLocationSharingViewerUITests.swift index f3e032d7c..6d4333d4c 100644 --- a/RiotSwiftUI/Modules/Room/LiveLocationSharingViewer/Test/UI/LiveLocationSharingViewerUITests.swift +++ b/RiotSwiftUI/Modules/Room/LiveLocationSharingViewer/Test/UI/LiveLocationSharingViewerUITests.swift @@ -17,9 +17,6 @@ import XCTest import RiotSwiftUI -class LiveLocationSharingViewerUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockLiveLocationSharingViewerScreenState.self - } +class LiveLocationSharingViewerUITests: MockScreenTestCase { + // Tests to be implemented. } diff --git a/RiotSwiftUI/Modules/Room/LocationSharing/Test/UI/LocationSharingUITests.swift b/RiotSwiftUI/Modules/Room/LocationSharing/Test/UI/LocationSharingUITests.swift index 65029026c..d9fb19faa 100644 --- a/RiotSwiftUI/Modules/Room/LocationSharing/Test/UI/LocationSharingUITests.swift +++ b/RiotSwiftUI/Modules/Room/LocationSharing/Test/UI/LocationSharingUITests.swift @@ -17,17 +17,7 @@ import XCTest import RiotSwiftUI -class LocationSharingUITests: XCTestCase { - - private var app: XCUIApplication! - - override func setUp() { - continueAfterFailure = false - - app = XCUIApplication() - app.launch() - } - +class LocationSharingUITests: MockScreenTestCase { func testInitialUserLocation() { goToScreenWithIdentifier(MockLocationSharingScreenState.shareUserLocation.title) diff --git a/RiotSwiftUI/Modules/Room/PollEditForm/Test/UI/PollEditFormUITests.swift b/RiotSwiftUI/Modules/Room/PollEditForm/Test/UI/PollEditFormUITests.swift index 2ce4ca26c..d56c88391 100644 --- a/RiotSwiftUI/Modules/Room/PollEditForm/Test/UI/PollEditFormUITests.swift +++ b/RiotSwiftUI/Modules/Room/PollEditForm/Test/UI/PollEditFormUITests.swift @@ -17,19 +17,9 @@ import XCTest import RiotSwiftUI -class PollEditFormUITests: XCTestCase { - - private var app: XCUIApplication! - - override func setUp() { - continueAfterFailure = false - - app = XCUIApplication() - app.launch() - app.goToScreenWithIdentifier(MockPollEditFormScreenState.standard.title) - } - +class PollEditFormUITests: MockScreenTestCase { func testInitialStateComponents() { + app.goToScreenWithIdentifier(MockPollEditFormScreenState.standard.title) XCTAssert(app.scrollViews.firstMatch.exists) @@ -58,6 +48,7 @@ class PollEditFormUITests: XCTestCase { } func testRemoveAddAnswerOptions() { + app.goToScreenWithIdentifier(MockPollEditFormScreenState.standard.title) let deleteAnswerOptionButton = app.buttons["Delete answer option"].firstMatch diff --git a/RiotSwiftUI/Modules/Room/RoomAccess/RoomAccessTypeChooser/Test/UI/RoomAccessTypeChooserUITests.swift b/RiotSwiftUI/Modules/Room/RoomAccess/RoomAccessTypeChooser/Test/UI/RoomAccessTypeChooserUITests.swift index 0e51a82d4..d6f5b3dbb 100644 --- a/RiotSwiftUI/Modules/Room/RoomAccess/RoomAccessTypeChooser/Test/UI/RoomAccessTypeChooserUITests.swift +++ b/RiotSwiftUI/Modules/Room/RoomAccess/RoomAccessTypeChooser/Test/UI/RoomAccessTypeChooserUITests.swift @@ -17,6 +17,6 @@ import XCTest import RiotSwiftUI -class RoomAccessTypeChooserUITests: MockScreenTest { +class RoomAccessTypeChooserUITests: MockScreenTestCase { // Tests to be implemented. } diff --git a/RiotSwiftUI/Modules/Room/RoomUpgrade/Test/UI/RoomUpgradeUITests.swift b/RiotSwiftUI/Modules/Room/RoomUpgrade/Test/UI/RoomUpgradeUITests.swift index e78261aea..5b59c1c5d 100644 --- a/RiotSwiftUI/Modules/Room/RoomUpgrade/Test/UI/RoomUpgradeUITests.swift +++ b/RiotSwiftUI/Modules/Room/RoomUpgrade/Test/UI/RoomUpgradeUITests.swift @@ -17,6 +17,6 @@ import XCTest import RiotSwiftUI -class RoomUpgradeUITests: MockScreenTest { +class RoomUpgradeUITests: MockScreenTestCase { // Tests to be implemented. } diff --git a/RiotSwiftUI/Modules/Room/StaticLocationSharingViewer/Test/UI/StaticLocationViewingUITests.swift b/RiotSwiftUI/Modules/Room/StaticLocationSharingViewer/Test/UI/StaticLocationViewingUITests.swift index d459b6df3..d6f26f247 100644 --- a/RiotSwiftUI/Modules/Room/StaticLocationSharingViewer/Test/UI/StaticLocationViewingUITests.swift +++ b/RiotSwiftUI/Modules/Room/StaticLocationSharingViewer/Test/UI/StaticLocationViewingUITests.swift @@ -17,28 +17,6 @@ import XCTest import RiotSwiftUI -class StaticLocationViewingUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockStaticLocationViewingScreenState.self - } - - override class func createTest() -> MockScreenTest { - return StaticLocationViewingUITests(selector: #selector(verifyStaticLocationViewingScreen)) - } - - func verifyStaticLocationViewingScreen() { - guard let screenState = screenState as? MockStaticLocationViewingScreenState else { fatalError("no screen") } - - switch screenState { - case .showUserLocation: - verifyInitialExistingLocation() - case .showPinLocation: - verifyInitialExistingLocation() - } - } - - func verifyInitialExistingLocation() { - // This test has issues running consistently on CI. Removed for now until the issue has been fixed. - } +class StaticLocationViewingUITests: MockScreenTestCase { + // This test has issues running consistently on CI. Removed for now until the issue has been fixed. } diff --git a/RiotSwiftUI/Modules/Room/TimelinePoll/Test/UI/TimelinePollUITests.swift b/RiotSwiftUI/Modules/Room/TimelinePoll/Test/UI/TimelinePollUITests.swift index 0cf4d5071..98b520ea7 100644 --- a/RiotSwiftUI/Modules/Room/TimelinePoll/Test/UI/TimelinePollUITests.swift +++ b/RiotSwiftUI/Modules/Room/TimelinePoll/Test/UI/TimelinePollUITests.swift @@ -17,17 +17,7 @@ import XCTest import RiotSwiftUI -class TimelinePollUITests: XCTestCase { - - private var app: XCUIApplication! - - override func setUp() { - continueAfterFailure = false - - app = XCUIApplication() - app.launch() - } - +class TimelinePollUITests: MockScreenTestCase { func testOpenDisclosedPoll() { app.goToScreenWithIdentifier(MockTimelinePollScreenState.openDisclosed.title) diff --git a/RiotSwiftUI/Modules/Room/UserSuggestion/Test/UI/UserSuggestionUITests.swift b/RiotSwiftUI/Modules/Room/UserSuggestion/Test/UI/UserSuggestionUITests.swift index 8b5af53c0..53e3c883d 100644 --- a/RiotSwiftUI/Modules/Room/UserSuggestion/Test/UI/UserSuggestionUITests.swift +++ b/RiotSwiftUI/Modules/Room/UserSuggestion/Test/UI/UserSuggestionUITests.swift @@ -17,18 +17,11 @@ import XCTest import RiotSwiftUI -class UserSuggestionUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockUserSuggestionScreenState.self - } - - override class func createTest() -> MockScreenTest { - return UserSuggestionUITests(selector: #selector(verifyUserSuggestionScreen)) - } - - func verifyUserSuggestionScreen() throws { - XCTAssert(app.tables.firstMatch.exists) +class UserSuggestionUITests: MockScreenTestCase { + func testUserSuggestionScreen() throws { + app.goToScreenWithIdentifier(MockUserSuggestionScreenState.multipleResults.title) + + XCTAssert(app.tables.firstMatch.waitForExistence(timeout: 1)) let firstButton = app.tables.firstMatch.buttons.firstMatch _ = firstButton.waitForExistence(timeout: 10) diff --git a/RiotSwiftUI/Modules/Settings/ChangePassword/Test/UI/ChangePasswordUITests.swift b/RiotSwiftUI/Modules/Settings/ChangePassword/Test/UI/ChangePasswordUITests.swift index d534eac16..c96ef6f27 100644 --- a/RiotSwiftUI/Modules/Settings/ChangePassword/Test/UI/ChangePasswordUITests.swift +++ b/RiotSwiftUI/Modules/Settings/ChangePassword/Test/UI/ChangePasswordUITests.swift @@ -17,31 +17,10 @@ import XCTest import RiotSwiftUI -class ChangePasswordUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockChangePasswordScreenState.self - } - - override class func createTest() -> MockScreenTest { - return ChangePasswordUITests(selector: #selector(verifyChangePasswordScreen)) - } - - func verifyChangePasswordScreen() throws { - guard let screenState = screenState as? MockChangePasswordScreenState else { fatalError("no screen") } - switch screenState { - case .allEmpty: - verifyAllEmpty() - case .cannotSubmit: - verifyCannotSubmit() - case .canSubmit: - verifyCanSubmit() - case .canSubmitAndSignoutAllDevicesChecked: - verifyCanSubmitAndSignoutAllDevicesChecked() - } - } - - func verifyAllEmpty() { +class ChangePasswordUITests: MockScreenTestCase { + func testAllEmpty() { + app.goToScreenWithIdentifier(MockChangePasswordScreenState.allEmpty.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown.") XCTAssertTrue(app.staticTexts["passwordRequirementsLabel"].exists, "The password requirements label should be shown.") @@ -66,7 +45,9 @@ class ChangePasswordUITests: MockScreenTest { XCTAssertFalse(signoutAllDevicesToggle.isOn, "Sign out all devices should be unchecked") } - func verifyCannotSubmit() { + func testCannotSubmit() { + app.goToScreenWithIdentifier(MockChangePasswordScreenState.cannotSubmit.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown.") XCTAssertTrue(app.staticTexts["passwordRequirementsLabel"].exists, "The password requirements label should be shown.") @@ -91,7 +72,9 @@ class ChangePasswordUITests: MockScreenTest { XCTAssertFalse(signoutAllDevicesToggle.isOn, "Sign out all devices should be unchecked") } - func verifyCanSubmit() { + func testCanSubmit() { + app.goToScreenWithIdentifier(MockChangePasswordScreenState.canSubmit.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown.") XCTAssertTrue(app.staticTexts["passwordRequirementsLabel"].exists, "The password requirements label should be shown.") @@ -116,7 +99,9 @@ class ChangePasswordUITests: MockScreenTest { XCTAssertFalse(signoutAllDevicesToggle.isOn, "Sign out all devices should be unchecked") } - func verifyCanSubmitAndSignoutAllDevicesChecked() { + func testCanSubmitAndSignoutAllDevicesChecked() { + app.goToScreenWithIdentifier(MockChangePasswordScreenState.canSubmitAndSignoutAllDevicesChecked.title) + XCTAssertTrue(app.staticTexts["titleLabel"].exists, "The title should be shown.") XCTAssertTrue(app.staticTexts["passwordRequirementsLabel"].exists, "The password requirements label should be shown.") diff --git a/RiotSwiftUI/Modules/Spaces/MatrixItemChooser/Test/UI/MatrixItemChooserUITests.swift b/RiotSwiftUI/Modules/Spaces/MatrixItemChooser/Test/UI/MatrixItemChooserUITests.swift index c5e8f305b..edcd683a3 100644 --- a/RiotSwiftUI/Modules/Spaces/MatrixItemChooser/Test/UI/MatrixItemChooserUITests.swift +++ b/RiotSwiftUI/Modules/Spaces/MatrixItemChooser/Test/UI/MatrixItemChooserUITests.swift @@ -17,44 +17,27 @@ import XCTest import RiotSwiftUI -class MatrixItemChooserUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockMatrixItemChooserScreenState.self - } - - override class func createTest() -> MockScreenTest { - return MatrixItemChooserUITests(selector: #selector(verifyMatrixItemChooserScreen)) - } - - func verifyMatrixItemChooserScreen() throws { - guard let screenState = screenState as? MockMatrixItemChooserScreenState else { fatalError("no screen") } - switch screenState { - case .noItems: - verifyEmptyScreen() - case .items: - verifyPopulatedScreen() - case .selectedItems: - verifyPopulatedWithSelectionScreen() - case .selectionHeader: - break - } - } - - func verifyEmptyScreen() { +class MatrixItemChooserUITests: MockScreenTestCase { + func testEmptyScreen() { + app.goToScreenWithIdentifier(MockMatrixItemChooserScreenState.noItems.title) + XCTAssertEqual(app.staticTexts["titleText"].label, VectorL10n.spacesCreationAddRoomsTitle) XCTAssertEqual(app.staticTexts["messageText"].label, VectorL10n.spacesCreationAddRoomsMessage) XCTAssertEqual(app.staticTexts["emptyListMessage"].exists, true) XCTAssertEqual(app.staticTexts["emptyListMessage"].label, VectorL10n.spacesNoResultFoundTitle) } - func verifyPopulatedScreen() { + func testPopulatedScreen() { + app.goToScreenWithIdentifier(MockMatrixItemChooserScreenState.items.title) + XCTAssertEqual(app.staticTexts["titleText"].label, VectorL10n.spacesCreationAddRoomsTitle) XCTAssertEqual(app.staticTexts["messageText"].label, VectorL10n.spacesCreationAddRoomsMessage) XCTAssertEqual(app.staticTexts["emptyListMessage"].exists, false) } - func verifyPopulatedWithSelectionScreen() { + func testPopulatedWithSelectionScreen() { + app.goToScreenWithIdentifier(MockMatrixItemChooserScreenState.selectedItems.title) + XCTAssertEqual(app.staticTexts["titleText"].label, VectorL10n.spacesCreationAddRoomsTitle) XCTAssertEqual(app.staticTexts["messageText"].label, VectorL10n.spacesCreationAddRoomsMessage) XCTAssertEqual(app.staticTexts["emptyListMessage"].exists, false) diff --git a/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationEmailInvites/Test/UI/SpaceCreationEmailInvitesUITests.swift b/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationEmailInvites/Test/UI/SpaceCreationEmailInvitesUITests.swift index 2b680e2aa..897230312 100644 --- a/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationEmailInvites/Test/UI/SpaceCreationEmailInvitesUITests.swift +++ b/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationEmailInvites/Test/UI/SpaceCreationEmailInvitesUITests.swift @@ -19,31 +19,31 @@ import XCTest import RiotSwiftUI -class SpaceCreationEmailInvitesUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockSpaceCreationEmailInvitesScreenState.self - } - - override class func createTest() -> MockScreenTest { - return SpaceCreationEmailInvitesUITests(selector: #selector(verifySpaceCreationEmailInvitesScreen)) - } - - func verifySpaceCreationEmailInvitesScreen() throws { - guard let screenState = screenState as? MockSpaceCreationEmailInvitesScreenState else { fatalError("no screen") } - switch screenState { - case .defaultEmailValues: - verifyEmailValues() - case .emailEntered: - verifyEmailValues() - case .emailValidationFailed: - verifyEmailValues() - case .loading: - verifyEmailValues() - } +class SpaceCreationEmailInvitesUITests: MockScreenTestCase { + func testDefaultEmailValues() { + app.goToScreenWithIdentifier(MockSpaceCreationEmailInvitesScreenState.defaultEmailValues.title) + + let emailTextFieldsCount = app.textFields.matching(identifier: "emailTextField").count + XCTAssertEqual(emailTextFieldsCount, 2) } - func verifyEmailValues() { + func testEmailEntered() { + app.goToScreenWithIdentifier(MockSpaceCreationEmailInvitesScreenState.emailEntered.title) + + let emailTextFieldsCount = app.textFields.matching(identifier: "emailTextField").count + XCTAssertEqual(emailTextFieldsCount, 2) + } + + func testEmailValidationFailed() { + app.goToScreenWithIdentifier(MockSpaceCreationEmailInvitesScreenState.emailValidationFailed.title) + + let emailTextFieldsCount = app.textFields.matching(identifier: "emailTextField").count + XCTAssertEqual(emailTextFieldsCount, 2) + } + + func testLoading() { + app.goToScreenWithIdentifier(MockSpaceCreationEmailInvitesScreenState.loading.title) + let emailTextFieldsCount = app.textFields.matching(identifier: "emailTextField").count XCTAssertEqual(emailTextFieldsCount, 2) } diff --git a/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationMenu/Test/UI/SpaceCreationMenuUITests.swift b/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationMenu/Test/UI/SpaceCreationMenuUITests.swift index c2f457f79..251fb5429 100644 --- a/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationMenu/Test/UI/SpaceCreationMenuUITests.swift +++ b/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationMenu/Test/UI/SpaceCreationMenuUITests.swift @@ -19,25 +19,10 @@ import XCTest import RiotSwiftUI -class SpaceCreationMenuUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockSpaceCreationMenuScreenState.self - } - - override class func createTest() -> MockScreenTest { - return SpaceCreationMenuUITests(selector: #selector(verifySpaceCreationMenuScreen)) - } - - func verifySpaceCreationMenuScreen() throws { - guard let screenState = screenState as? MockSpaceCreationMenuScreenState else { fatalError("no screen") } - switch screenState { - case .options: - verifySpaceCreationMenuOptions() - } - } - - func verifySpaceCreationMenuOptions() { +class SpaceCreationMenuUITests: MockScreenTestCase { + func testSpaceCreationMenuOptions() { + app.goToScreenWithIdentifier(MockSpaceCreationMenuScreenState.options.title) + let optionButtonCount = app.buttons.matching(identifier:"optionButton").count XCTAssertEqual(optionButtonCount, 2) @@ -49,5 +34,4 @@ class SpaceCreationMenuUITests: MockScreenTest { XCTAssert(detailText.exists) XCTAssertEqual(detailText.label, "Some detail text") } - } diff --git a/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationPostProcess/Test/UI/SpaceCreationPostProcessUITests.swift b/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationPostProcess/Test/UI/SpaceCreationPostProcessUITests.swift index e453d6436..75c624772 100644 --- a/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationPostProcess/Test/UI/SpaceCreationPostProcessUITests.swift +++ b/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationPostProcess/Test/UI/SpaceCreationPostProcessUITests.swift @@ -19,21 +19,6 @@ import XCTest import RiotSwiftUI -class SpaceCreationPostProcessUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockSpaceCreationPostProcessScreenState.self - } - - override class func createTest() -> MockScreenTest { - return SpaceCreationPostProcessUITests(selector: #selector(verifySpaceCreationPostProcessScreen)) - } - - func verifySpaceCreationPostProcessScreen() throws { - guard let screenState = screenState as? MockSpaceCreationPostProcessScreenState else { fatalError("no screen") } - } - - func verifyTasksList() { - } - +class SpaceCreationPostProcessUITests: MockScreenTestCase { + // No tests have been implemented } diff --git a/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationRooms/Test/UI/SpaceCreationRoomsUITests.swift b/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationRooms/Test/UI/SpaceCreationRoomsUITests.swift index 2d9d633c1..2dedafb37 100644 --- a/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationRooms/Test/UI/SpaceCreationRoomsUITests.swift +++ b/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationRooms/Test/UI/SpaceCreationRoomsUITests.swift @@ -19,27 +19,17 @@ import XCTest import RiotSwiftUI -class SpaceCreationRoomsUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockSpaceCreationRoomsScreenState.self - } - - override class func createTest() -> MockScreenTest { - return SpaceCreationRoomsUITests(selector: #selector(verifySpaceCreationRoomsScreen)) - } - - func verifySpaceCreationRoomsScreen() throws { - guard let screenState = screenState as? MockSpaceCreationRoomsScreenState else { fatalError("no screen") } - switch screenState { - case .defaultValues: - verifyValueTextFields() - case .valuesEntered: - verifyValueTextFields() - } +class SpaceCreationRoomsUITests: MockScreenTestCase { + func testDefaultValues() { + app.goToScreenWithIdentifier(MockSpaceCreationRoomsScreenState.defaultValues.title) + + let emailTextFieldsCount = app.textFields.matching(identifier: "roomTextField").count + XCTAssertEqual(emailTextFieldsCount, 3) } - func verifyValueTextFields() { + func testValuesEntered() { + app.goToScreenWithIdentifier(MockSpaceCreationRoomsScreenState.valuesEntered.title) + let emailTextFieldsCount = app.textFields.matching(identifier: "roomTextField").count XCTAssertEqual(emailTextFieldsCount, 3) } diff --git a/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationSettings/Test/UI/SpaceCreationSettingsUITests.swift b/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationSettings/Test/UI/SpaceCreationSettingsUITests.swift index 9d6dfc4c7..f1f0e705d 100644 --- a/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationSettings/Test/UI/SpaceCreationSettingsUITests.swift +++ b/RiotSwiftUI/Modules/Spaces/SpaceCreation/SpaceCreationSettings/Test/UI/SpaceCreationSettingsUITests.swift @@ -19,32 +19,18 @@ import XCTest import RiotSwiftUI -class SpaceCreationSettingsUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockSpaceCreationSettingsScreenState.self - } - - override class func createTest() -> MockScreenTest { - return SpaceCreationSettingsUITests(selector: #selector(verifySpaceCreationSettingsScreen)) - } - - func verifySpaceCreationSettingsScreen() throws { - guard let screenState = screenState as? MockSpaceCreationSettingsScreenState else { fatalError("no screen") } - switch screenState { - case .privateSpace: break - case .validated: break - case .validationFailed: break - } - } - - func verifyPrivateSpace() { +class SpaceCreationSettingsUITests: MockScreenTestCase { + func testPrivateSpace() { + app.goToScreenWithIdentifier(MockSpaceCreationSettingsScreenState.privateSpace.title) + let addressTextField = app.groups["addressTextField"] XCTAssertEqual(addressTextField.exists, false) } - func verifyPublicValidated() { + func testPublicValidated() { + app.goToScreenWithIdentifier(MockSpaceCreationSettingsScreenState.validated.title) + let addressTextField = app.groups["addressTextField"] - XCTAssertEqual(addressTextField.exists, true) + XCTAssertEqual(addressTextField.exists, false) } } diff --git a/RiotSwiftUI/Modules/Spaces/SpaceSettings/SpaceSettings/Test/UI/SpaceSettingsUITests.swift b/RiotSwiftUI/Modules/Spaces/SpaceSettings/SpaceSettings/Test/UI/SpaceSettingsUITests.swift index bc5e3900d..abece45dd 100644 --- a/RiotSwiftUI/Modules/Spaces/SpaceSettings/SpaceSettings/Test/UI/SpaceSettingsUITests.swift +++ b/RiotSwiftUI/Modules/Spaces/SpaceSettings/SpaceSettings/Test/UI/SpaceSettingsUITests.swift @@ -17,6 +17,6 @@ import XCTest import RiotSwiftUI -class SpaceSettingsUITests: MockScreenTest { +class SpaceSettingsUITests: MockScreenTestCase { // Tests to be implemented. } diff --git a/RiotSwiftUI/Modules/Template/SimpleScreenExample/Test/UI/TemplateSimpleScreenUITests.swift b/RiotSwiftUI/Modules/Template/SimpleScreenExample/Test/UI/TemplateSimpleScreenUITests.swift index d09fc7d6b..4b02918dd 100644 --- a/RiotSwiftUI/Modules/Template/SimpleScreenExample/Test/UI/TemplateSimpleScreenUITests.swift +++ b/RiotSwiftUI/Modules/Template/SimpleScreenExample/Test/UI/TemplateSimpleScreenUITests.swift @@ -17,28 +17,22 @@ import XCTest import RiotSwiftUI -class TemplateSimpleScreenUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockTemplateSimpleScreenScreenState.self - } - - override class func createTest() -> MockScreenTest { - return TemplateSimpleScreenUITests(selector: #selector(verifyTemplateSimpleScreenScreen)) - } - - func verifyTemplateSimpleScreenScreen() throws { - guard let screenState = screenState as? MockTemplateSimpleScreenScreenState else { fatalError("no screen") } - switch screenState { - case .promptType(let promptType): - verifyTemplateSimpleScreenPromptType(promptType: promptType) - } - } - - func verifyTemplateSimpleScreenPromptType(promptType: TemplateSimpleScreenPromptType) { +class TemplateSimpleScreenUITests: MockScreenTestCase { + func testTemplateSimpleScreenPromptRegular() { + let promptType = TemplateSimpleScreenPromptType.regular + app.goToScreenWithIdentifier(MockTemplateSimpleScreenScreenState.promptType(promptType).title) + + let title = app.staticTexts["title"] + XCTAssert(title.exists) + XCTAssertEqual(title.label, promptType.title) + } + + func testTemplateSimpleScreenPromptUpgrade() { + let promptType = TemplateSimpleScreenPromptType.upgrade + app.goToScreenWithIdentifier(MockTemplateSimpleScreenScreenState.promptType(promptType).title) + let title = app.staticTexts["title"] XCTAssert(title.exists) XCTAssertEqual(title.label, promptType.title) } - } diff --git a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Test/UI/TemplateUserProfileUITests.swift b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Test/UI/TemplateUserProfileUITests.swift index 690a3c43c..b23b4174e 100644 --- a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Test/UI/TemplateUserProfileUITests.swift +++ b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Test/UI/TemplateUserProfileUITests.swift @@ -17,33 +17,38 @@ import XCTest import RiotSwiftUI -class TemplateUserProfileUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockTemplateUserProfileScreenState.self +class TemplateUserProfileUITests: MockScreenTestCase { + func testTemplateUserProfilePresenceIdle() { + let presence = TemplateUserProfilePresence.idle + app.goToScreenWithIdentifier(MockTemplateUserProfileScreenState.presence(presence).title) + + let presenceText = app.staticTexts["presenceText"] + XCTAssert(presenceText.exists) + XCTAssertEqual(presenceText.label, presence.title) } - - override class func createTest() -> MockScreenTest { - return TemplateUserProfileUITests(selector: #selector(verifyTemplateUserProfileScreen)) + + func testTemplateUserProfilePresenceOffline() { + let presence = TemplateUserProfilePresence.offline + app.goToScreenWithIdentifier(MockTemplateUserProfileScreenState.presence(presence).title) + + let presenceText = app.staticTexts["presenceText"] + XCTAssert(presenceText.exists) + XCTAssertEqual(presenceText.label, presence.title) } - - func verifyTemplateUserProfileScreen() throws { - guard let screenState = screenState as? MockTemplateUserProfileScreenState else { fatalError("no screen") } - switch screenState { - case .presence(let presence): - verifyTemplateUserProfilePresence(presence: presence) - case .longDisplayName(let name): - verifyTemplateUserProfileLongName(name: name) - } - } - - func verifyTemplateUserProfilePresence(presence: TemplateUserProfilePresence) { + + func testTemplateUserProfilePresenceOnline() { + let presence = TemplateUserProfilePresence.online + app.goToScreenWithIdentifier(MockTemplateUserProfileScreenState.presence(presence).title) + let presenceText = app.staticTexts["presenceText"] XCTAssert(presenceText.exists) XCTAssertEqual(presenceText.label, presence.title) } - func verifyTemplateUserProfileLongName(name: String) { + func testTemplateUserProfileLongName() { + let name = "Somebody with a super long name we would like to test" + app.goToScreenWithIdentifier(MockTemplateUserProfileScreenState.longDisplayName(name).title) + let displayNameText = app.staticTexts["displayNameText"] XCTAssert(displayNameText.exists) XCTAssertEqual(displayNameText.label, name) diff --git a/RiotSwiftUI/Modules/Template/TemplateAdvancedRoomsExample/TemplateRoomChat/Test/UI/TemplateRoomChatUITests.swift b/RiotSwiftUI/Modules/Template/TemplateAdvancedRoomsExample/TemplateRoomChat/Test/UI/TemplateRoomChatUITests.swift index b06b509c6..449eddcc0 100644 --- a/RiotSwiftUI/Modules/Template/TemplateAdvancedRoomsExample/TemplateRoomChat/Test/UI/TemplateRoomChatUITests.swift +++ b/RiotSwiftUI/Modules/Template/TemplateAdvancedRoomsExample/TemplateRoomChat/Test/UI/TemplateRoomChatUITests.swift @@ -17,46 +17,31 @@ import XCTest import RiotSwiftUI -class TemplateRoomChatUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockTemplateRoomChatScreenState.self - } - - override class func createTest() -> MockScreenTest { - return TemplateRoomChatUITests(selector: #selector(verifyTemplateRoomChatScreen)) - } - - func verifyTemplateRoomChatScreen() throws { - guard let screenState = screenState as? MockTemplateRoomChatScreenState else { fatalError("no screen") } - switch screenState { - case .initializingRoom: - verifyInitializingRoom() - case .failedToInitializeRoom: - verifyFailedToInitializeRoom() - case .noMessages: - verifyNoMessages() - case .messages: - verifyMessages() - } - } - - func verifyInitializingRoom() { +class TemplateRoomChatUITests: MockScreenTestCase { + func testInitializingRoom() { + app.goToScreenWithIdentifier(MockTemplateRoomChatScreenState.initializingRoom.title) + let loadingProgress = app.activityIndicators["loadingProgress"] XCTAssert(loadingProgress.exists) } - func verifyFailedToInitializeRoom() { + func testFailedToInitializeRoom() { + app.goToScreenWithIdentifier(MockTemplateRoomChatScreenState.failedToInitializeRoom.title) + let errorMessage = app.staticTexts["errorMessage"] XCTAssert(errorMessage.exists) } - func verifyNoMessages() { + func testNoMessages() { + app.goToScreenWithIdentifier(MockTemplateRoomChatScreenState.noMessages.title) + let errorMessage = app.staticTexts["errorMessage"] XCTAssert(errorMessage.exists) } - func verifyMessages() { + func testMessages() { + app.goToScreenWithIdentifier(MockTemplateRoomChatScreenState.messages.title) + // Verify bubble grouping with: // 3 bubbles let bubbleCount = app.images.matching(identifier:"bubbleImage").count @@ -65,8 +50,6 @@ class TemplateRoomChatUITests: MockScreenTest { // and 4 text items let bubbleTextItemCount = app.staticTexts.matching(identifier:"bubbleTextContent").count XCTAssertEqual(bubbleTextItemCount, 4) - - } } diff --git a/RiotSwiftUI/Modules/Template/TemplateAdvancedRoomsExample/TemplateRoomList/Test/UI/TemplateRoomListUITests.swift b/RiotSwiftUI/Modules/Template/TemplateAdvancedRoomsExample/TemplateRoomList/Test/UI/TemplateRoomListUITests.swift index 7a7befcc3..8ee0012e2 100644 --- a/RiotSwiftUI/Modules/Template/TemplateAdvancedRoomsExample/TemplateRoomList/Test/UI/TemplateRoomListUITests.swift +++ b/RiotSwiftUI/Modules/Template/TemplateAdvancedRoomsExample/TemplateRoomList/Test/UI/TemplateRoomListUITests.swift @@ -17,33 +17,18 @@ import XCTest import RiotSwiftUI -class TemplateRoomListUITests: MockScreenTest { - - override class var screenType: MockScreenState.Type { - return MockTemplateRoomListScreenState.self - } - - override class func createTest() -> MockScreenTest { - return TemplateRoomListUITests(selector: #selector(verifyTemplateRoomListScreen)) - } - - func verifyTemplateRoomListScreen() throws { - guard let screenState = screenState as? MockTemplateRoomListScreenState else { fatalError("no screen") } - switch screenState { - case .noRooms: - verifyTemplateRoomListNoRooms() - case .rooms: - verifyTemplateRoomListRooms() - } - } - - func verifyTemplateRoomListNoRooms() { +class TemplateRoomListUITests: MockScreenTestCase { + func testTemplateRoomListNoRooms() { + app.goToScreenWithIdentifier(MockTemplateRoomListScreenState.noRooms.title) + let errorMessage = app.staticTexts["errorMessage"] XCTAssert(errorMessage.exists) XCTAssert(errorMessage.label == "No Rooms") } - func verifyTemplateRoomListRooms() { + func testTemplateRoomListRooms() { + app.goToScreenWithIdentifier(MockTemplateRoomListScreenState.rooms.title) + let displayNameCount = app.buttons.matching(identifier:"roomNameText").count XCTAssertEqual(displayNameCount, 3) } diff --git a/changelog.d/6432.build b/changelog.d/6432.build new file mode 100644 index 000000000..36fde2b9f --- /dev/null +++ b/changelog.d/6432.build @@ -0,0 +1 @@ +Fix UI tests failing on CI but not being reported by prefixing all tests with `test`.