Fix unit and UI tests. (#460)

* Fix race condition on session verification tests.
* Fix clear button on text field.
* Add a timeout to UI test signalling.
* Use snapshot testing for login screen.
This commit is contained in:
Doug
2023-01-18 13:28:59 +00:00
committed by GitHub
parent b835b55394
commit 8f906c7be7
20 changed files with 175 additions and 237 deletions
+10 -96
View File
@@ -19,127 +19,41 @@ import XCTest
@MainActor
class LoginScreenUITests: XCTestCase {
var app: XCUIApplication!
@MainActor
override func setUp() async throws {
app = nil
}
func testMatrixDotOrg() {
// Given the initial login screen which defaults to matrix.org.
app = Application.launch()
let app = Application.launch()
app.goToScreenWithIdentifier(.login)
let state = "matrix.org"
validateLoginFormIsVisible(for: state)
validateOIDCButtonIsHidden(for: state)
validateNextButtonIsDisabled(for: state)
validateUnsupportedServerTextIsHidden(for: state)
app.assertScreenshot(.login)
// When typing in a username and password.
app.textFields.element.clearAndTypeText("@test:matrix.org")
app.secureTextFields.element.clearAndTypeText("12345678")
app.textFields["usernameTextField"].clearAndTypeText("@test:matrix.org")
app.secureTextFields["passwordTextField"].clearAndTypeText("12345678")
// Then the form should be ready to submit.
validateNextButtonIsEnabled(for: "matrix.org with credentials entered")
app.assertScreenshot(.login, step: 0)
}
func testOIDC() {
// Given the initial login screen.
app = Application.launch()
let app = Application.launch()
app.goToScreenWithIdentifier(.login)
// When entering a username on a homeserver that only supports OIDC.
app.textFields.element.clearAndTypeText("@test:company.com\n")
app.textFields["usernameTextField"].clearAndTypeText("@test:company.com\n")
// Then the screen should be configured for OIDC.
let state = "an OIDC only server"
validateOIDCButtonIsShown(for: state)
validateLoginFormIsHidden(for: state)
validateUnsupportedServerTextIsHidden(for: state)
app.assertScreenshot(.login, step: 1)
}
func testUnsupported() {
// Given the initial login screen.
app = Application.launch()
let app = Application.launch()
app.goToScreenWithIdentifier(.login)
// When entering a username on a homeserver with an unsupported flow.
app.textFields.element.clearAndTypeText("@test:server.net\n")
app.textFields["usernameTextField"].clearAndTypeText("@test:server.net\n")
// Then the screen should not allow login to continue.
let state = "an unsupported server"
validateUnsupportedServerTextIsShown(for: state)
validateLoginFormIsHidden(for: state)
validateOIDCButtonIsHidden(for: state)
}
/// Checks that the username and password text fields are shown along with the next button.
func validateLoginFormIsVisible(for state: String) {
let usernameTextField = app.textFields.element
let passwordTextField = app.secureTextFields.element
let nextButton = app.buttons["nextButton"]
XCTAssertTrue(usernameTextField.exists, "Username input should be shown for \(state).")
XCTAssertTrue(passwordTextField.exists, "Password input should be shown for \(state).")
XCTAssertTrue(nextButton.exists, "The next button should be shown for \(state).")
XCTAssertEqual(nextButton.label, ElementL10n.loginSignupSubmit)
}
/// Checks that the username and password text fields are hidden along with the next button.
func validateLoginFormIsHidden(for state: String) {
let usernameTextField = app.textFields.element
let passwordTextField = app.secureTextFields.element
let nextButton = app.buttons["nextButton"]
XCTAssertFalse(usernameTextField.exists, "Username input should not be shown for \(state).")
XCTAssertFalse(passwordTextField.exists, "Password input should not be shown for \(state).")
XCTAssertFalse(nextButton.exists, "The next button should not be shown for \(state).")
}
/// Checks that the next button is shown but is disabled.
func validateNextButtonIsDisabled(for state: String) {
let nextButton = app.buttons["nextButton"]
XCTAssertTrue(nextButton.exists, "The next button should be shown.")
XCTAssertFalse(nextButton.isEnabled, "The next button should be disabled for \(state).")
XCTAssertEqual(nextButton.label, ElementL10n.loginSignupSubmit)
}
/// Checks that the next button is shown and is enabled.
func validateNextButtonIsEnabled(for state: String) {
let nextButton = app.buttons["nextButton"]
XCTAssertTrue(nextButton.exists, "The next button should be shown.")
XCTAssertTrue(nextButton.isEnabled, "The next button should be enabled for \(state).")
XCTAssertEqual(nextButton.label, ElementL10n.loginSignupSubmit)
}
/// Checks that the OIDC button is shown on the screen.
func validateOIDCButtonIsShown(for state: String) {
let oidcButton = app.buttons["oidcButton"]
XCTAssertTrue(oidcButton.waitForExistence(timeout: 1), "The OIDC button should be shown for \(state).")
XCTAssertEqual(oidcButton.label, ElementL10n.loginContinue)
}
/// Checks that the OIDC button is not shown on the screen.
func validateOIDCButtonIsHidden(for state: String) {
let oidcButton = app.buttons["oidcButton"]
XCTAssertFalse(oidcButton.exists, "The OIDC button should be hidden for \(state).")
}
/// Checks that the unsupported homeserver text is shown on the screen.
func validateUnsupportedServerTextIsShown(for state: String) {
let unsupportedText = app.staticTexts["unsupportedServerText"]
XCTAssertTrue(unsupportedText.waitForExistence(timeout: 1), "The unsupported homeserver text should be shown for \(state).")
XCTAssertEqual(unsupportedText.label, ElementL10n.autodiscoverWellKnownError)
}
/// Checks that the unsupported homeserver text is not shown on the screen.
func validateUnsupportedServerTextIsHidden(for state: String) {
let unsupportedText = app.staticTexts["unsupportedServerText"]
XCTAssertFalse(unsupportedText.exists, "The unsupported homeserver text should be hidden for \(state).")
app.assertScreenshot(.login, step: 2)
}
}
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4b94b634587f6f2326763babe911f68f089f0c82b5d5ecb48a8da9a48d4ed048
size 91500
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2047a424580d38d7780fef8a1287d70fc1663565cc1cbfce30882b7fc2df8993
size 76516
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:572337d216e1705d6c23c47bfaf064f0518f9048e4d9ff06b48079e986702d14
size 83871
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f56d59dee20430b613c93ed9d05547fbc887a5f5f4f66fa9cbc6da14d9d1d86f
size 102841
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:bd8314e6b5eaa80eea9bba1d3a93d1c224707fb81b6280625454d6136c8ca66f
size 80882
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ce3f468a20ae0d814dfc91dd138c5f861505e4b0283c1d3e09f81adad2b6d37e
size 91436
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d6dd66777ae8f3e28df56483cdc1a7ec69c89215e1cff3a4eb89babcca05f68b
size 89322
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:376013470882195ec51279f0ddf31e1704c6751ef10b0154e937df2bd93daf9d
size 74868
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:eb947f6d7daf93f194f513cd0d2c30cf549382c39d7997dab32ace6be08faf1b
size 79052
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f4d64453f35dca2757748779076ceb8ece88d1725f8b276ced97026416eac5d3
size 98345
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c8cbed1a62e312a569b30822a3551a19552f1b363590522ed58a2b7059598f84
size 77367
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:73e27d2985ac00b401c794248e9a582abdef6c4bc024180e0a138781a3d8d087
size 86637