#if os(macOS) import AppKit import SwiftUI import Observation import Testing @testable import EquipoMac @MainActor @Observable private final class GrowingContent { var expanded = false } @MainActor @Suite(.serialized) struct ResizingHostTests { @Test func lateContentRemeasuresItsHost() async throws { let state = GrowingContent() var heights: [CGFloat] = [] let host = ResizingHostingView(content: GrowingView(state: state), width: 300) { _, height in heights.append(height) } let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 400, height: 400), styleMask: [.borderless], backing: .buffered, defer: false) window.contentView = host defer { window.contentView = nil } window.orderFront(nil) func waitForHeight(_ height: CGFloat) async throws { for _ in 0..<250 { host.layoutSubtreeIfNeeded() if heights.last == height { return } try await Task.sleep(for: .milliseconds(20)) } #expect(heights.last == height) } try await waitForHeight(30) state.expanded = true try await waitForHeight(160) state.expanded = false try await waitForHeight(30) window.orderOut(nil) } } private struct GrowingView: View { var state: GrowingContent var body: some View { Color.clear.frame(height: state.expanded ? 160 : 30) } } #endif