import XCTest

// Add to an existing UI-test target. Replace identifiers to exercise your app.
// Run each configured destination/locale/text size separately; these tests do not
// programmatically change Duo pose and cannot certify a full transition matrix.
final class AdaptiveTransitionTests: XCTestCase {
    override func setUpWithError() throws { continueAfterFailure = false }

    func testDraftSurvivesNavigation() throws {
        let app = XCUIApplication()
        app.launch()
        let draft = app.textFields["draftField"]
        XCTAssertTrue(draft.waitForExistence(timeout: 10))
        draft.tap()
        draft.typeText("Draft survives navigation")
        app.buttons["selectItem"].tap()
        app.buttons["openDetails"].tap()
        app.navigationBars["Details"].buttons.element(boundBy: 0).tap()
        XCTAssertEqual(draft.value as? String, "Draft survives navigation")
        XCTAssertEqual(app.staticTexts["selectionValue"].label, "Item A")
        let attachment = XCTAttachment(screenshot: app.screenshot())
        attachment.lifetime = .keepAlways
        add(attachment)
    }

    func testDraftAfterHumanAssistedDisplayTransition() throws {
        let app = XCUIApplication()
        app.launch()
        let draft = app.textFields["draftField"]
        XCTAssertTrue(draft.waitForExistence(timeout: 10))
        draft.tap()
        draft.typeText("Draft survives display transition")
        app.buttons["selectItem"].tap()
        // During this wait, use Device Hub to perform ONE recorded pose/resize
        // transition, inspect keyboard and controls, then tap Confirm transition review.
        // Capture the exact transition in the matrix; confirmation is human supplied.
        XCTAssertTrue(app.staticTexts["transitionConfirmation"].waitForExistence(timeout: 120),
                      "Perform and confirm the recorded transition within 120 seconds.")
        XCTAssertEqual(draft.value as? String, "Draft survives display transition")
        XCTAssertEqual(app.staticTexts["selectionValue"].label, "Item A")
        for _ in 0..<3 {
            if app.buttons["primaryAction"].isHittable { break }
            app.swipeUp()
        }
        XCTAssertTrue(app.buttons["primaryAction"].isHittable)
        let attachment = XCTAttachment(screenshot: app.screenshot())
        attachment.lifetime = .keepAlways
        add(attachment)
    }
}
