Skip to content

Commit

Permalink
Optimize text entry (#68)
Browse files Browse the repository at this point in the history
# Optimize text entry

## ♻️ Current situation & Problem
Update to the next release of XCTestExtensions for optimized text entry
and slightly reduced testing time.


## ⚙️ Release Notes 
* Update to the next release of XCTestExtensions for optimized text
entry and slightly reduced testing time.


## 📚 Documentation
--


## ✅ Testing
--

## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
Supereg authored Aug 20, 2024
1 parent 24a4b84 commit 40fa3f5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ struct LoginSetupView<PasswordReset: View>: View {
.sheet(isPresented: $presentingPasswordForgetSheet) {
passwordReset
}
.onTapGesture {
focusedField = nil
}
}


Expand Down
18 changes: 10 additions & 8 deletions Tests/UITests/TestAppUITests/AccountOverviewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,17 @@ final class AccountOverviewTests: XCTestCase { // swiftlint:disable:this type_bo
XCTAssertFalse(app.navigationBars.buttons["Done"].isEnabled)

// edit email
try app.textFields["E-Mail Address"].delete(count: 12, dismissKeyboard: false)
#if !os(visionOS)
try app.textFields["E-Mail Address"].delete(count: 12, options: [.disableKeyboardDismiss, .tapFromRight])
#else
try app.textFields["E-Mail Address"].delete(count: 12, options: [.disableKeyboardDismiss])
#endif

// failed validation
XCTAssertTrue(app.staticTexts["The provided email is invalid."].waitForExistence(timeout: 2.0))
XCTAssertFalse(app.buttons["Done"].isEnabled)

app.typeText("tum.de") // we still have keyboard focus
app.dismissKeyboard()
try app.textFields["E-Mail Address"].enter(value: "tum.de", options: .skipTextFieldSelection)
XCTAssertTrue(app.buttons["Done"].waitForExistence(timeout: 2.0))
app.buttons["Done"].tap()

Expand Down Expand Up @@ -349,15 +352,14 @@ final class AccountOverviewTests: XCTestCase { // swiftlint:disable:this type_bo
XCTAssertTrue(app.secureTextFields["enter password"].exists)
XCTAssertTrue(app.secureTextFields["re-enter password"].exists)

try app.secureTextFields["enter password"].enter(value: "12345", dismissKeyboard: false)
try app.secureTextFields["enter password"].enter(value: "12345", options: .disableKeyboardDismiss)
XCTAssertTrue(app.staticTexts.matching(identifier: warningLength).firstMatch.waitForExistence(timeout: 2.0))
XCTAssertEqual(app.staticTexts.matching(identifier: warningLength).count, 2) // additional red warning.
app.typeText("6789")
app.dismissKeyboard()
try app.secureTextFields["enter password"].enter(value: "6789", options: .skipTextFieldSelection)

try app.secureTextFields["re-enter password"].enter(value: "12345", dismissKeyboard: false)
try app.secureTextFields["re-enter password"].enter(value: "12345", options: .disableKeyboardDismiss)
XCTAssertTrue(app.staticTexts["Passwords do not match."].waitForExistence(timeout: 2.0))
app.typeText("6789")
try app.secureTextFields["re-enter password"].enter(value: "6789", options: .skipTextFieldSelection)

XCTAssertTrue(app.buttons["Done"].waitForExistence(timeout: 2.0))
app.buttons["Done"].tap()
Expand Down
35 changes: 14 additions & 21 deletions Tests/UITests/TestAppUITests/AccountSetupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ final class AccountSetupTests: XCTestCase { // swiftlint:disable:this type_body_
app.alerts["Credentials do not match"].scrollViews.otherElements.buttons["OK"].tap()

// retype password
try app.secureTextFields["Password"].delete(count: Defaults.password.dropLast(3).count, dismissKeyboard: false)
app.typeText(Defaults.password)
app.dismissKeyboard()
try app.secureTextFields["Password"].delete(count: Defaults.password.dropLast(3).count, options: .disableKeyboardDismiss)
try app.secureTextFields["Password"].enter(value: Defaults.password, options: .skipTextFieldSelection)

// this takes us back to the home screen
XCTAssertTrue(app.buttons["Login"].waitForExistence(timeout: 0.5)) // might need time to to get enabled
Expand Down Expand Up @@ -256,13 +255,11 @@ final class AccountSetupTests: XCTestCase { // swiftlint:disable:this type_body_
XCTAssertFalse(app.staticTexts["This field cannot be empty."].exists)

// verify empty validation appearing
try app.collectionViews.textFields["E-Mail Address"].enter(value: "a", dismissKeyboard: false)
app.typeText(XCUIKeyboardKey.delete.rawValue) // we have remaining focus
app.dismissKeyboard()
try app.collectionViews.textFields["E-Mail Address"].enter(value: "a", options: .disableKeyboardDismiss)
try app.collectionViews.textFields["E-Mail Address"].delete(count: 1, options: .skipTextFieldSelection)

try app.collectionViews.secureTextFields["Password"].enter(value: "a", dismissKeyboard: false)
app.typeText(XCUIKeyboardKey.delete.rawValue) // we have remaining focus
app.dismissKeyboard()
try app.collectionViews.secureTextFields["Password"].enter(value: "a", options: .disableKeyboardDismiss)
try app.collectionViews.secureTextFields["Password"].delete(count: 1, options: .skipTextFieldSelection)

XCTAssertTrue(app.staticTexts["This field cannot be empty."].waitForExistence(timeout: 2.0))
XCTAssertEqual(app.staticTexts.matching(identifier: "This field cannot be empty.").count, 2)
Expand All @@ -275,16 +272,14 @@ final class AccountSetupTests: XCTestCase { // swiftlint:disable:this type_body_
let password = "123456789"

// enter email with validation
try app.collectionViews.textFields["E-Mail Address"].enter(value: String(email.dropLast(13)), dismissKeyboard: false)
try app.collectionViews.textFields["E-Mail Address"].enter(value: String(email.dropLast(13)), options: .disableKeyboardDismiss)
XCTAssertTrue(app.staticTexts["The provided email is invalid."].waitForExistence(timeout: 2.0))
app.typeText(String(email.dropFirst(13))) // we stay focused
app.dismissKeyboard()
try app.collectionViews.textFields["E-Mail Address"].enter(value: String(email.dropFirst(13)), options: .skipTextFieldSelection)

// enter password with validation
try app.collectionViews.secureTextFields["Password"].enter(value: String(password.dropLast(5)), dismissKeyboard: false)
try app.collectionViews.secureTextFields["Password"].enter(value: String(password.dropLast(5)), options: .disableKeyboardDismiss)
XCTAssertTrue(app.staticTexts["Your password must be at least 8 characters long."].waitForExistence(timeout: 2.0))
app.typeText(String(password.dropFirst(4))) // stay focused, such that password field will not reset after regaining focus
app.dismissKeyboard()
try app.collectionViews.secureTextFields["Password"].enter(value: String(password.dropFirst(4)), options: .skipTextFieldSelection)

#if os(visionOS)
app.scrollUpInSetup()
Expand Down Expand Up @@ -322,15 +317,13 @@ final class AccountSetupTests: XCTestCase { // swiftlint:disable:this type_body_
XCTAssertTrue(app.collectionViews.buttons["Signup"].exists)
XCTAssertFalse(app.collectionViews.buttons["Signup"].isEnabled)

try app.textFields["enter first name"].enter(value: "a", dismissKeyboard: false)
app.typeText(XCUIKeyboardKey.delete.rawValue) // we have remaining focus
app.dismissKeyboard()
try app.textFields["enter first name"].enter(value: "a", options: .disableKeyboardDismiss)
try app.textFields["enter first name"].delete(count: 1, options: .skipTextFieldSelection)

XCTAssertTrue(app.staticTexts["This field cannot be empty."].waitForExistence(timeout: 1.0))

try app.textFields["enter last name"].enter(value: "a", dismissKeyboard: false)
app.typeText(XCUIKeyboardKey.delete.rawValue)
app.dismissKeyboard()
try app.textFields["enter last name"].enter(value: "a", options: .disableKeyboardDismiss)
try app.textFields["enter last name"].delete(count: 1, options: .skipTextFieldSelection)

XCTAssertEqual(app.staticTexts.matching(identifier: "This field cannot be empty.").count, 2)
}
Expand Down
7 changes: 7 additions & 0 deletions Tests/UITests/TestAppUITests/DocumentationHintsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@ final class DocumentationHintsTests: XCTestCase {
app.buttons["Open Documentation"].tap()

let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
#if os(visionOS)
sleep(3)
#endif
XCTAssert(safari.wait(for: .runningForeground, timeout: 5))
XCTAssertTrue(safari.staticTexts["Swift Package Index"].waitForExistence(timeout: 10.0))
XCTAssertTrue(safari.staticTexts["Initial Setup"].waitForExistence(timeout: 2.0)) // The initial setup article
safari.terminate()

app.activate()
XCTAssertTrue(app.wait(for: .runningForeground, timeout: 2.0))
}

@MainActor
Expand Down
12 changes: 6 additions & 6 deletions Tests/UITests/TestAppUITests/EntryViewsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ final class EntryViewsTests: XCTestCase {
XCTAssertTrue(app.textFields["Numeric Key"].exists)
// ensure empty value is translated to empty string (placeholder value) and not zero
XCTAssertEqual(app.textFields["Numeric Key"].value as? String, "Numeric Key")
try app.textFields["Numeric Key"].enter(value: "1234", dismissKeyboard: false)
try app.textFields["Numeric Key"].enter(value: "1234", options: .disableKeyboardDismiss)
XCTAssertTrue(app.staticTexts["Integer Value, 1234"].waitForExistence(timeout: 0.5))
app.typeText("a")
try app.textFields["Numeric Key"].enter(value: "a", options: [.skipTextFieldSelection, .disableKeyboardDismiss])
XCTAssertTrue(app.staticTexts["The input can only consist of digits."].waitForExistence(timeout: 2.0))
app.typeText(XCUIKeyboardKey.delete.rawValue)
try app.textFields["Numeric Key"].delete(count: 1, options: [.skipTextFieldSelection, .disableKeyboardDismiss])
app.navigationBars.buttons["Dismiss"].tap() // dismisses the keyboard (workaround for numpad keyboard)


XCTAssertTrue(app.staticTexts["Double Value, 1.5"].exists)
XCTAssertTrue(app.textFields["Double Key"].exists)
XCTAssertEqual(app.textFields["Double Key"].value as? String, "1.5")

try app.textFields["Double Key"].delete(count: 3, dismissKeyboard: false)
try app.textFields["Double Key"].delete(count: 3, options: .disableKeyboardDismiss)
XCTAssertTrue(app.staticTexts["Double Value, 0"].exists)
app.typeText("23.5")
try app.textFields["Double Key"].enter(value: "23.5", options: [.skipTextFieldSelection, .disableKeyboardDismiss])
XCTAssertTrue(app.staticTexts["Double Value, 23.5"].waitForExistence(timeout: 2.0))
app.typeText("a")
try app.textFields["Double Key"].enter(value: "a", options: [.skipTextFieldSelection, .disableKeyboardDismiss])
app.navigationBars.buttons["Dismiss"].tap() // dismisses the keyboard (workaround for numpad keyboard)
XCTAssertTrue(app.staticTexts["The input can only consist of digits."].waitForExistence(timeout: 2.0))
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/UITests/UITests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/StanfordSpezi/XCTestExtensions";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.4.9;
kind = upToNextMajorVersion;
minimumVersion = 1.0.0;
};
};
A969240D2A9A198800E2128B /* XCRemoteSwiftPackageReference "swift-argument-parser" */ = {
Expand Down

0 comments on commit 40fa3f5

Please sign in to comment.