Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e9c111949 | ||
|
|
7c15357108 | ||
|
|
ea6ee8cc64 | ||
|
|
557775af45 | ||
|
|
7333fe03e7 |
@@ -9,6 +9,7 @@ struct SybilQuickQuestionView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@FocusState private var promptFocused: Bool
|
||||
@State private var promptSelection: TextSelection?
|
||||
@State private var selectionAppliedForFocusRequest: Int?
|
||||
|
||||
private var hasAnswerContent: Bool {
|
||||
!viewModel.quickQuestionMessages.isEmpty || viewModel.quickQuestionError != nil
|
||||
@@ -36,9 +37,15 @@ struct SybilQuickQuestionView: View {
|
||||
guard !Task.isCancelled else {
|
||||
return
|
||||
}
|
||||
promptFocused = true
|
||||
let prompt = viewModel.quickQuestionPrompt
|
||||
promptSelection = TextSelection(range: prompt.startIndex..<prompt.endIndex)
|
||||
if promptFocused {
|
||||
selectPromptForCurrentFocusRequest()
|
||||
} else {
|
||||
promptFocused = true
|
||||
}
|
||||
}
|
||||
.onChange(of: promptFocused) { _, isFocused in
|
||||
guard isFocused else { return }
|
||||
selectPromptForCurrentFocusRequest()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,6 +213,13 @@ struct SybilQuickQuestionView: View {
|
||||
promptFocused = false
|
||||
_ = viewModel.sendQuickQuestion()
|
||||
}
|
||||
|
||||
private func selectPromptForCurrentFocusRequest() {
|
||||
guard selectionAppliedForFocusRequest != focusRequest else { return }
|
||||
let prompt = viewModel.quickQuestionPrompt
|
||||
promptSelection = TextSelection(range: prompt.startIndex..<prompt.endIndex)
|
||||
selectionAppliedForFocusRequest = focusRequest
|
||||
}
|
||||
}
|
||||
|
||||
private struct QuickQuestionPickerPill: View {
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import XCTest
|
||||
|
||||
/// Exercises Quick Question through its real home-screen action and shared SwiftUI field.
|
||||
@MainActor
|
||||
final class QuickQuestionSelectionUITests: XCTestCase {
|
||||
private let app = XCUIApplication()
|
||||
private let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
|
||||
|
||||
override func setUp() async throws {
|
||||
continueAfterFailure = false
|
||||
try await control(["action": "reset", "count": 0])
|
||||
app.launchArguments = [
|
||||
"-sybil.ios.apiBaseURL", "http://127.0.0.1:8799/api",
|
||||
"-sybil.ios.adminToken", "fixture-token"
|
||||
]
|
||||
}
|
||||
|
||||
override func tearDown() async throws {
|
||||
app.terminate()
|
||||
}
|
||||
|
||||
func testQuickQuestionKeepsKeyboardVisibleAcrossSeparateKeypressesAndStaysCompact() {
|
||||
app.launch()
|
||||
openQuickQuestionFromHomeScreen()
|
||||
|
||||
let prompt = quickQuestionPrompt()
|
||||
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
||||
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
|
||||
XCTAssertLessThan(prompt.frame.height, 80, "Quick Question should retain its original compact single-line field.")
|
||||
|
||||
prompt.typeText("a")
|
||||
XCTAssertTrue(app.keyboards.firstMatch.exists, "Keyboard should remain visible after the first keypress.")
|
||||
prompt.typeText("b")
|
||||
XCTAssertTrue(app.keyboards.firstMatch.exists, "Keyboard should remain visible after the second keypress.")
|
||||
prompt.typeText("c")
|
||||
XCTAssertTrue(app.keyboards.firstMatch.exists, "Keyboard should remain visible after the third keypress.")
|
||||
XCTAssertEqual(prompt.value as? String, "abc")
|
||||
}
|
||||
|
||||
func testQuickQuestionDismissalAndReappearanceSelectsRetainedDraftForReplacement() {
|
||||
app.launch()
|
||||
openQuickQuestionFromHomeScreen()
|
||||
|
||||
let prompt = quickQuestionPrompt()
|
||||
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
||||
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
|
||||
prompt.typeText("retained draft")
|
||||
XCTAssertEqual(prompt.value as? String, "retained draft")
|
||||
|
||||
dismissQuickQuestion()
|
||||
let dismissed = XCTNSPredicateExpectation(predicate: NSPredicate(format: "exists == false"), object: prompt)
|
||||
wait(for: [dismissed], timeout: 5)
|
||||
|
||||
// Reopen through the same home-screen Quick Question route after the
|
||||
// sheet has actually disappeared.
|
||||
openQuickQuestionFromHomeScreen()
|
||||
|
||||
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
||||
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
|
||||
XCTAssertEqual(prompt.value as? String, "retained draft")
|
||||
prompt.typeText("replacement")
|
||||
XCTAssertEqual(prompt.value as? String, "replacement")
|
||||
}
|
||||
|
||||
private func quickQuestionPrompt() -> XCUIElement {
|
||||
app.textFields["Ask anything..."]
|
||||
}
|
||||
|
||||
private func dismissQuickQuestion() {
|
||||
let header = app.staticTexts["Quick question"]
|
||||
XCTAssertTrue(header.waitForExistence(timeout: 5))
|
||||
let dismissStart = header.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
|
||||
let dismissEnd = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.9))
|
||||
dismissStart.press(forDuration: 0.1, thenDragTo: dismissEnd)
|
||||
}
|
||||
|
||||
private func openQuickQuestionFromHomeScreen() {
|
||||
XCUIDevice.shared.press(.home)
|
||||
let sybilIcon = springboard.icons.matching(identifier: "Sybil").firstMatch
|
||||
XCTAssertTrue(sybilIcon.waitForExistence(timeout: 10))
|
||||
let homeScreen = springboard.otherElements["Home screen icons"]
|
||||
if !sybilIcon.isHittable, homeScreen.waitForExistence(timeout: 5) {
|
||||
for _ in 0..<2 where !sybilIcon.isHittable {
|
||||
homeScreen.swipeLeft()
|
||||
}
|
||||
}
|
||||
XCTAssertTrue(sybilIcon.isHittable, "Navigate to the home-screen page containing Sybil before opening its quick action.")
|
||||
sybilIcon.press(forDuration: 1.2)
|
||||
|
||||
let quickQuestion = springboard.buttons["Quick question"]
|
||||
XCTAssertTrue(quickQuestion.waitForExistence(timeout: 5))
|
||||
quickQuestion.tap()
|
||||
}
|
||||
|
||||
private func control(_ body: [String: Any]) async throws {
|
||||
var request = URLRequest(url: URL(string: "http://127.0.0.1:8799/control")!)
|
||||
request.httpMethod = "POST"
|
||||
request.httpBody = try JSONSerialization.data(withJSONObject: body)
|
||||
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||
let (_, response) = try await URLSession.shared.data(for: request)
|
||||
XCTAssertEqual((response as? HTTPURLResponse)?.statusCode, 200)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user