field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | README | LICENSE

TeraSettingsIdentityUI.swift (5269B)


      1 import XCTest
      2 
      3 extension TeraRemoteQualificationUITests {
      4   @MainActor
      5   func openSettingsFromMe(
      6     _ app: XCUIApplication,
      7     meSheet: XCUIElement
      8   ) -> Bool {
      9     let meList = meSheet.descendants(matching: .collectionView).firstMatch
     10     guard meList.waitForExistence(timeout: 10) else { return false }
     11     let settings = app.descendants(matching: .any)["radroots.support.settings"]
     12     for _ in 0 ..< 8 {
     13       if settings.exists,
     14         settings.isHittable,
     15         settings.frame.minY >= meSheet.frame.minY,
     16         settings.frame.maxY <= meSheet.frame.maxY
     17       {
     18         settings.tap()
     19         return app.descendants(matching: .any)["radroots.support.settings.view"]
     20           .waitForExistence(timeout: 20)
     21       }
     22       meList.swipeUp()
     23     }
     24     return false
     25   }
     26 
     27   @MainActor
     28   func exerciseSettingsIdentityOverscroll(
     29     _ app: XCUIApplication,
     30     expectedPublicKey: String
     31   ) throws {
     32     app.tabBars.buttons["Today"].tap()
     33     let account = app.descendants(matching: .any)["radroots.support.account"]
     34     XCTAssertTrue(account.waitForExistence(timeout: 10))
     35     account.tap()
     36     let meSheet = app.descendants(matching: .any)["radroots.support.me.sheet"]
     37     XCTAssertTrue(meSheet.waitForExistence(timeout: 10))
     38     XCTAssertTrue(openSettingsFromMe(app, meSheet: meSheet))
     39 
     40     let settings = app.descendants(matching: .any)["radroots.support.settings.view"]
     41     let profile = app.descendants(matching: .any)["radroots.settings.profile.name"]
     42     let navigation = app.navigationBars["Settings"]
     43     for _ in 0 ..< 12 {
     44       if profile.exists, profile.isHittable,
     45         profile.frame.minY >= max(settings.frame.minY, navigation.frame.maxY),
     46         profile.frame.maxY <= settings.frame.maxY
     47       {
     48         break
     49       }
     50       settings.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.75))
     51         .press(
     52           forDuration: 0.1,
     53           thenDragTo: settings.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.35))
     54         )
     55     }
     56     _ = try XCTUnwrap(
     57       profile.exists && profile.isHittable ? profile : nil,
     58       "The native overscroll regression must reach the later Profile section"
     59     )
     60     let publicKey = app.descendants(matching: .any)["radroots.settings.identity.public_key"]
     61     let revealed = revealSettingsPublicKey(app, publicKey: publicKey)
     62     XCTAssertTrue(revealed, "Settings identity navigation must recover after overscroll")
     63     guard revealed else { return }
     64     XCTAssertEqual(publicKey.value as? String, expectedPublicKey)
     65 
     66     let back = app.navigationBars.buttons["Me"].firstMatch
     67     XCTAssertTrue(back.waitForExistence(timeout: 10))
     68     back.tap()
     69     let done = app.navigationBars.buttons["Done"].firstMatch
     70     XCTAssertTrue(done.waitForExistence(timeout: 10))
     71     done.tap()
     72     XCTAssertTrue(meSheet.waitForNonExistence(timeout: 10))
     73   }
     74 
     75   @MainActor
     76   func revealSettingsPublicKey(_ app: XCUIApplication, publicKey: XCUIElement) -> Bool {
     77     let settings = app.descendants(matching: .any)["radroots.support.settings.view"]
     78     guard settings.waitForExistence(timeout: 10) else { return false }
     79     let navigation = app.navigationBars["Settings"]
     80     // Settings uses lazy rows. Read the real identity only after revealing it
     81     // through the same visible scroll surface available to the user at AX5.
     82     for _ in 0 ..< 8 {
     83       if publicKey.exists, publicKey.isHittable,
     84         publicKey.frame.minY >= max(settings.frame.minY, navigation.frame.maxY),
     85         publicKey.frame.maxY <= settings.frame.maxY
     86       {
     87         return true
     88       }
     89       let aboveViewport = publicKey.exists && publicKey.frame.height > 0
     90         && publicKey.frame.minY < max(settings.frame.minY, navigation.frame.maxY)
     91       let laterSectionVisible = [
     92         "radroots.settings.profile.name",
     93         "radroots.settings.network.environment",
     94         "radroots.settings.relays.add",
     95         "radroots.settings.retry.network",
     96         "radroots.settings.blossom.primary",
     97       ].contains { identifier in
     98         let row = app.descendants(matching: .any)[identifier]
     99         return row.exists && row.isHittable
    100       }
    101       let movingBack = aboveViewport || laterSectionVisible
    102       // Overlapping drags retain the same eight checks without skipping a
    103       // large lazy row, and return when the real row has passed the viewport.
    104       settings.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: movingBack ? 0.35 : 0.75))
    105         .press(
    106           forDuration: 0.1,
    107           thenDragTo: settings.coordinate(
    108             withNormalizedOffset: CGVector(dx: 0.5, dy: movingBack ? 0.75 : 0.35)
    109           )
    110         )
    111     }
    112     return false
    113   }
    114 
    115   @MainActor
    116   func reachRoot(_ app: XCUIApplication) {
    117     for _ in 0 ..< 6 {
    118       if app.tabBars.firstMatch.waitForExistence(timeout: 3) {
    119         return
    120       }
    121       for identifier in [
    122         "radroots.identity.create",
    123         "radroots.identity.unlock",
    124         "radroots.configuration.reconfigure",
    125         "radroots.identity.recover",
    126         "radroots.runtime.retry",
    127       ] {
    128         let action = app.descendants(matching: .any)[identifier]
    129         if action.exists, action.isHittable {
    130           action.tap()
    131           break
    132         }
    133       }
    134     }
    135     XCTFail("Tera did not reach the two-tab root without interactive authentication")
    136   }
    137 }