From 95ee8789041bb41c632a6475b38ca5350df917b9 Mon Sep 17 00:00:00 2001 From: Lukas <134181853+bo2themax@users.noreply.github.com> Date: Thu, 26 Mar 2026 19:52:26 +0100 Subject: [PATCH] macOS: add test case for search bar focus change --- .../GhosttyMouseStateTests.swift | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/macos/GhosttyUITests/GhosttyMouseStateTests.swift b/macos/GhosttyUITests/GhosttyMouseStateTests.swift index 9bb270b8e..b8f202617 100644 --- a/macos/GhosttyUITests/GhosttyMouseStateTests.swift +++ b/macos/GhosttyUITests/GhosttyMouseStateTests.swift @@ -49,5 +49,39 @@ final class GhosttyMouseStateTests: GhosttyCustomConfigCase { XCTAssertEqual(NSPasteboard.general.string(forType: .string), nil, "Moving mouse shouldn't select any texts") } + + @MainActor func testSearchFocusState() async throws { + let app = try ghosttyApplication() + app.activate() + XCTAssertTrue(app.windows.firstMatch.waitForExistence(timeout: 5), "New window should appear") + app.typeKey("f", modifierFlags: .command) + + let textfield = app.textFields.firstMatch + XCTAssertTrue(textfield.waitForExistence(timeout: 5), "Search field should appear") + app.typeText("a") + + XCTAssertTrue(textfield.stringValue == "a", "Search text should be `a`") + + textfield.coordinate(withNormalizedOffset: .zero) + .withOffset(.init(dx: textfield.frame.width * 0.5, dy: 0)) + .click() + + app.typeText("b") + + XCTAssertTrue(textfield.stringValue == "ab", "Search text should be `ab`") + + // resign + app.typeKey(.escape, modifierFlags: []) + + // dismiss + app.typeKey(.escape, modifierFlags: []) + + XCTAssertTrue(textfield.waitForNonExistence(timeout: 5), "Search field should disappear") + } } +private extension XCUIElement { + var stringValue: String? { + (value as? String) + } +}