This commit is contained in:
@@ -49,6 +49,23 @@ final class QuickQuestionSelectionUITests: XCTestCase {
|
||||
|
||||
func testQuickQuestionComposerStartsCompactAndGrowsForMultilineText() {
|
||||
app.launch()
|
||||
let agentButton = app.buttons["agent-sidebar"]
|
||||
if !agentButton.waitForExistence(timeout: 2) || !agentButton.isHittable {
|
||||
let showSidebar = app.buttons["Show sidebar"]
|
||||
XCTAssertTrue(showSidebar.waitForExistence(timeout: 15))
|
||||
showSidebar.tap()
|
||||
}
|
||||
XCTAssertTrue(agentButton.waitForExistence(timeout: 5))
|
||||
agentButton.tap()
|
||||
|
||||
let normalField = app.textFields["agent-composer"]
|
||||
let normalView = app.textViews["agent-composer"]
|
||||
XCTAssertTrue(normalField.waitForExistence(timeout: 5) || normalView.waitForExistence(timeout: 5))
|
||||
let normalComposer = normalField.exists ? normalField : normalView
|
||||
let normalHeight = normalComposer.frame.height
|
||||
XCTAssertLessThan(normalHeight, 80, "The normal composer should start at one line.")
|
||||
|
||||
XCUIDevice.shared.press(.home)
|
||||
openQuickQuestionFromHomeScreen()
|
||||
|
||||
let prompt = quickQuestionPromptElement()
|
||||
@@ -56,6 +73,7 @@ final class QuickQuestionSelectionUITests: XCTestCase {
|
||||
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
|
||||
let oneLineHeight = prompt.frame.height
|
||||
XCTAssertLessThan(oneLineHeight, 80, "The Quick Question field must not fill the sheet when empty.")
|
||||
XCTAssertEqual(oneLineHeight, normalHeight, accuracy: 4, "The six-line Return field must keep the normal composer’s compact first line.")
|
||||
captureFrame("quick-question-empty-keyboard-visible", element: prompt)
|
||||
capture("quick-question-empty-keyboard-visible")
|
||||
|
||||
@@ -128,6 +146,63 @@ final class QuickQuestionSelectionUITests: XCTestCase {
|
||||
)
|
||||
}
|
||||
|
||||
func testQuickQuestionReturnSubmitsPromptExactlyOnceWithoutNewline() async throws {
|
||||
app.launch()
|
||||
openQuickQuestionFromHomeScreen()
|
||||
|
||||
let prompt = quickQuestionPromptElement()
|
||||
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
||||
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
|
||||
prompt.typeText("Return submits once\n")
|
||||
|
||||
XCTAssertTrue(app.staticTexts["Fixture answer"].waitForExistence(timeout: 10))
|
||||
XCTAssertEqual(prompt.value as? String, "Return submits once", "Return must submit without adding a newline.")
|
||||
let state = try await control(["action": "state"])
|
||||
let submitted = try XCTUnwrap(state["quickQuestions"] as? [[String: Any]])
|
||||
XCTAssertEqual(submitted.count, 1, "One Return press must submit exactly one quick question.")
|
||||
XCTAssertEqual(submitted.first?["question"] as? String, "Return submits once")
|
||||
}
|
||||
|
||||
func testQuickQuestionMultilinePasteDoesNotSubmit() async throws {
|
||||
app.launch()
|
||||
openQuickQuestionFromHomeScreen()
|
||||
|
||||
let prompt = quickQuestionPromptElement()
|
||||
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
||||
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
|
||||
let pasted = "First line\nSecond line"
|
||||
UIPasteboard.general.string = pasted
|
||||
prompt.press(forDuration: 1.2)
|
||||
let paste = app.descendants(matching: .any)
|
||||
.matching(NSPredicate(format: "label == %@", "Paste"))
|
||||
.firstMatch
|
||||
XCTAssertTrue(paste.waitForExistence(timeout: 5))
|
||||
paste.tap()
|
||||
|
||||
XCTAssertEqual(prompt.value as? String, pasted)
|
||||
let state = try await control(["action": "state"])
|
||||
let submitted = try XCTUnwrap(state["quickQuestions"] as? [[String: Any]])
|
||||
XCTAssertTrue(submitted.isEmpty, "Pasting multiline text must not submit the question.")
|
||||
}
|
||||
|
||||
func testSharedNormalComposerReturnInsertsNewline() async throws {
|
||||
app.launch()
|
||||
let textField = app.textFields["Enter Prompt"]
|
||||
let textView = app.textViews["Enter Prompt"]
|
||||
XCTAssertTrue(textField.waitForExistence(timeout: 5) || textView.waitForExistence(timeout: 5))
|
||||
let composer = textField.exists ? textField : textView
|
||||
composer.tap()
|
||||
composer.typeText("Normal chat keeps newline\n")
|
||||
|
||||
XCTAssertTrue((composer.value as? String)?.contains("\n") == true)
|
||||
let state = try await control(["action": "state"])
|
||||
let log = try XCTUnwrap(state["log"] as? [[String: Any]])
|
||||
XCTAssertFalse(
|
||||
log.contains { $0["method"] as? String == "POST" && ($0["path"] as? String)?.hasSuffix("/chat-completions/stream") == true },
|
||||
"Plain Return in normal chat must insert a newline without submitting."
|
||||
)
|
||||
}
|
||||
|
||||
private func quickQuestionPromptElement() -> XCUIElement {
|
||||
let textField = app.textFields["quick-question-prompt"]
|
||||
return textField.exists ? textField : app.textViews["quick-question-prompt"]
|
||||
@@ -168,12 +243,14 @@ final class QuickQuestionSelectionUITests: XCTestCase {
|
||||
add(attachment)
|
||||
}
|
||||
|
||||
private func control(_ body: [String: Any]) async throws {
|
||||
@discardableResult
|
||||
private func control(_ body: [String: Any]) async throws -> [String: Any] {
|
||||
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)
|
||||
let (data, response) = try await URLSession.shared.data(for: request)
|
||||
XCTAssertEqual((response as? HTTPURLResponse)?.statusCode, 200)
|
||||
return try XCTUnwrap(JSONSerialization.jsonObject(with: data) as? [String: Any])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user