fix: match provider picker to action popup
This commit is contained in:
@@ -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])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user