fix: match provider picker to action popup

This commit is contained in:
2026-10-18 00:05:46 +02:00
parent 11e604e79e
commit d829565188
5 changed files with 99 additions and 29 deletions
@@ -29,3 +29,35 @@ import Testing
actions.close(animated: false)
}
}
@Test @MainActor func providerPickerOpensBelowAnchorAndKeepsCurrentSelection() throws {
_ = NSApplication.shared
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 750, height: 480),
styleMask: .borderless, backing: .buffered, defer: false)
window.isReleasedWhenClosed = false
let host = try #require(window.contentView)
let pill = NSView(frame: NSRect(x: 500, y: 420, width: 230, height: 36))
let anchor = NSButton(frame: pill.bounds)
pill.addSubview(anchor)
host.addSubview(pill)
let popup = ApplicationActionsController()
defer { popup.close(animated: false); window.orderOut(nil) }
var selections: [Bool] = []
popup.selectProvider = { selections.append($0) }
popup.showProviders(selectedOpenAI: true, relativeTo: anchor)
host.layoutSubtreeIfNeeded()
let rect = popup.view.convert(popup.view.bounds, to: host)
#expect(rect.maxY < pill.frame.minY)
#expect(rect.maxX == pill.frame.maxX)
#expect(pill.alphaValue == 1)
_ = popup.handle(#selector(NSResponder.insertNewline(_:)))
#expect(selections == [true])
// Reopen during the close animation, then switch modes without retaining the old anchor.
popup.showTranslation(relativeTo: anchor)
popup.showProviders(selectedOpenAI: false, relativeTo: anchor)
host.layoutSubtreeIfNeeded()
#expect(popup.view.convert(popup.view.bounds, to: host).maxY < pill.frame.minY)
popup.moveSelection(by: 1)
_ = popup.handle(#selector(NSResponder.insertNewline(_:)))
#expect(selections == [true, true])
}
@@ -185,7 +185,6 @@ func translationExecutionRejectsOldCompletionsWithoutClearingNewRequests() async
tool.input = { input }
let views = descendants(tool.view)
let output = try #require(views.compactMap { $0 as? NSTextView }.first)
let provider = tool.providerPicker
let button = try #require(views.compactMap { $0 as? NSButton }.first { $0.action == NSSelectorFromString("performPrimaryAction") })
tool.translate()
try await waitForTranslation { requests.pending.count == 1 }
@@ -200,8 +199,7 @@ func translationExecutionRejectsOldCompletionsWithoutClearingNewRequests() async
tool.translate()
#expect(requests.inputs.count == 2)
provider.selectItem(at: 1)
_ = tool.perform(provider.action, with: provider)
tool.selectProvider(openAI: true)
#expect(defaults.string(forKey: "translationProvider") == "openai")
tool.translate()
try await waitForTranslation { requests.pending.count == 3 }