#if os(macOS) import AppKit import SwiftUI import Testing @testable import EquipoKit @testable import EquipoMac /// Paul, 2026-11-30: in the Mac conversation, a question with four options /// drew them in one row and the long first title spilled out of its button. @MainActor @Suite(.serialized) struct MacChoiceTests { static let options = ["It's on Amadan, I'll give you the repos", "It's hosted somewhere else", "It's a new project, start one", "I meant a different name"] private func optionButtons(_ options: [String], width: CGFloat) throws -> [ActionButton] { let s = try ProjectsReviewTests().session(ScriptedTransport()) var card: ThinCard = try Fixture.decode("project-card") card.placementByName = nil; card.rememberName = nil; card.options = options let view = LiveTranscript(session: s, openTask: { _ in }) view.frame = NSRect(x: 0, y: 0, width: width, height: 800) let window = NSWindow(contentRect: view.frame, styleMask: [.borderless], backing: .buffered, defer: false) window.contentView = view defer { window.contentView = nil } view.update(items: [.question(card, RosterByline(who: .coordinator, verb: "asks", project: nil, time: nil))]); view.layout() func all(_ v: NSView) -> [ActionButton] { ((v as? ActionButton).map { [$0] } ?? []) + v.subviews.flatMap(all) } let found = options.compactMap { title in all(view).first { $0.title == title } } try #require(found.count == options.count) if let directory = ProcessInfo.processInfo.environment["EQUIPO_CHOICE_SCREENSHOTS"], let bitmap = view.bitmapImageRepForCachingDisplay(in: view.bounds) { view.cacheDisplay(in: view.bounds, to: bitmap) let name = "mac-\(options.count)-\(Int(width)).png" try bitmap.representation(using: .png, properties: [:])?.write(to: URL(fileURLWithPath: directory).appendingPathComponent(name)) } return found } @Test(arguments: [700.0, 1000.0]) func longOptionsStackAndNoTitleSpills(width: Double) throws { let buttons = try optionButtons(Self.options, width: width) for b in buttons { #expect(b.frame.width >= ActionButton.idealWidth(b.title) || b.frame.height > 32, "\(b.title) at \(Int(width)): \(b.frame.width) < \(ActionButton.idealWidth(b.title)) on one line") } #expect(Set(buttons.map(\.frame.minY)).count == buttons.count, "one per line") #expect(Set(buttons.map(\.frame.width)).count == 1) } @Test func shortOptionsStayInARow() throws { let buttons = try optionButtons(["Yes", "No", "Not yet"], width: 700) #expect(Set(buttons.map(\.frame.minY)).count == 1) #expect(buttons.allSatisfy { $0.frame.width >= ActionButton.idealWidth($0.title) }) } @Test func sendingKeepsTheRow() { func place(busy: Bool) -> [NSRect] { let host = FlippedView() let buttons = ["Yes", "No", "Not yet"].enumerated().map { index, title in button(title, index == 0 ? .primary : .choice, busy: busy && index == 0 ? "Sending…" : nil) } _ = placeChoices(buttons, in: host, x: 0, y: 0, width: 260) return buttons.map(\.frame) } let idle = place(busy: false) #expect(Set(idle.map(\.minY)).count == 1) #expect(place(busy: true) == idle) } @Test func aTitleLongerThanTheCardWraps() { let title = "It's on Amadan, I'll give you the repos, all of them, under the oficina organisation" let b = button(title, .primary) let bottom = placeChoices([b, button("No")], in: FlippedView(), x: 0, y: 0, width: 240) #expect(b.frame.width == 240) #expect(b.frame.height > 32, "taller, so the wrapped title fits") #expect(bottom > b.frame.maxY) } } #endif