field_ios

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

TeraPhotoQualificationInput.swift (3455B)


      1 import XCTest
      2 
      3 extension TeraRemoteQualificationUITests {
      4   @MainActor
      5   func preparePhotoUpdate(_ app: XCUIApplication, marker: String) -> XCUIElement? {
      6     guard let type = openAdd(app) else {
      7       XCTFail("The Add bottom tab did not present the Add surface")
      8       return nil
      9     }
     10     let newDraft = app.buttons["radroots.add.new"]
     11     XCTAssertTrue(newDraft.waitForExistence(timeout: 10))
     12     newDraft.tap()
     13 
     14     guard selectPhotoUpdate(app, type: type) else { return nil }
     15     let content = app.descendants(matching: .any)["radroots.add.content"]
     16     XCTAssertTrue(content.waitForExistence(timeout: 10))
     17     guard waitUntilHittable(content, timeout: 10) else {
     18       XCTFail("Photo update content did not become hittable")
     19       return nil
     20     }
     21     content.tap()
     22     content.typeText(marker)
     23     let keyboardDone = app.buttons["radroots.add.keyboard.done"]
     24     XCTAssertTrue(keyboardDone.waitForExistence(timeout: 10))
     25     keyboardDone.tap()
     26     XCTAssertFalse(app.keyboards.firstMatch.waitForExistence(timeout: 5))
     27 
     28     let library = app.descendants(matching: .any)["radroots.add.media.library"]
     29     scrollTo(app, element: library)
     30     guard library.waitForExistence(timeout: 10), waitUntilHittable(library, timeout: 10) else {
     31       XCTFail("The Photo Library action did not become available through the visible UI")
     32       return nil
     33     }
     34     library.tap()
     35     let preparedStatus = app.staticTexts.matching(
     36       NSPredicate(format: "label == 'Photo prepared. Add descriptive text before publishing.'")
     37     ).firstMatch
     38     TeraAccessibilityNavigation.scroll(app, to: preparedStatus, up: false, test: self)
     39     guard preparedStatus.waitForExistence(timeout: 60) else {
     40       XCTFail("The selected Photo update did not report the visible prepared state")
     41       return nil
     42     }
     43     let prepared = app.descendants(matching: .any)["radroots.add.media.prepared"]
     44     scrollTo(app, element: prepared)
     45     guard prepared.waitForExistence(timeout: 10) else {
     46       XCTFail("The selected Photo update did not reach the visible prepared state")
     47       return nil
     48     }
     49     do {
     50       try enterPhotoDescription(app)
     51     } catch {
     52       return nil
     53     }
     54     return readySubmit(app)
     55   }
     56 
     57   @MainActor
     58   private func selectPhotoUpdate(_ app: XCUIApplication, type: XCUIElement) -> Bool {
     59     for _ in 0 ..< 3 where !app.buttons["Photo update"].exists {
     60       type.tap()
     61       _ = app.buttons["Photo update"].waitForExistence(timeout: 10)
     62     }
     63     let photoUpdate = app.buttons["Photo update"]
     64     guard photoUpdate.exists else {
     65       XCTFail("The Add type picker did not present Photo update")
     66       return false
     67     }
     68     guard waitUntilHittable(photoUpdate, timeout: 10) else {
     69       XCTFail("Photo update did not become hittable")
     70       return false
     71     }
     72 
     73     var selectedPhotoUpdate = false
     74     for _ in 0 ..< 3 where !selectedPhotoUpdate {
     75       photoUpdate.tap()
     76       selectedPhotoUpdate = waitForValue(type, value: "Photo update", timeout: 10)
     77       if !selectedPhotoUpdate, !photoUpdate.exists {
     78         type.tap()
     79         _ = photoUpdate.waitForExistence(timeout: 10)
     80       }
     81     }
     82     guard selectedPhotoUpdate else {
     83       XCTFail("Photo update selection did not update the Add composer type")
     84       return false
     85     }
     86     return true
     87   }
     88 
     89   @MainActor
     90   func enterPhotoDescription(_ app: XCUIApplication) throws {
     91     try enterText(app, identifier: "radroots.add.media.alt", value: "A green test image prepared for the photo update")
     92   }
     93 }