import AppKit import SwiftUI /// Verify the production section fills its assigned row even when the scope note wraps. @main struct ProcessSectionChecks { @MainActor static func main() { _ = NSApplication.shared; NSApp.setActivationPolicy(.accessory) Task { @MainActor in let window = NSWindow(contentRect: NSRect(x: 30, y: 30, width: 628, height: 176), styleMask: [.borderless], backing: .buffered, defer: false) window.isReleasedWhenClosed = false; window.level = .floating let host = NSHostingView(rootView: AnyView(EmptyView())); host.sizingOptions = [] window.contentView = host; window.orderFrontRegardless() let rows = (0..<100).map { ProcessMetrics(id: .init(pid: Int32($0 + 1), seconds: 1, microseconds: 0), name: "worker-\($0)", path: "/fixture/worker", cpu: 0.1, footprintBytes: 1 << 20, threads: 2, restricted: false) } let snapshot = ProcessSnapshot(date: Date(), enumerated: 100, readable: 100, rows: rows, failed: false) let energy = ProcessEnergySnapshot(date: Date(), candidates: 100, readable: 100, rows: [], state: .available) for dark in [false,true] { window.appearance = NSAppearance(named: dark ? .darkAqua : .aqua) for language in ["zh-Hans","zh-Hant","en"] { for width: CGFloat in [340,628] { window.setContentSize(NSSize(width: width, height: 176)) host.rootView = AnyView(ProcessTableView(snapshot: snapshot, energy: energy, state: ProcessTableState()) .environment(\.locale, Locale(identifier: language)) .environment(\.colorScheme, dark ? .dark : .light)) try? await Task.sleep(for: .milliseconds(100)); host.layoutSubtreeIfNeeded() let scrolls = descendants(host).compactMap { $0 as? NSScrollView }.filter { $0.documentView is NSTableView } precondition(scrolls.count == 1) let scroll = scrolls[0], rect = scroll.convert(scroll.bounds, to: host) let topRect = host.isFlipped ? rect : CGRect(x: rect.minX, y: host.bounds.height - rect.maxY, width: rect.width, height: rect.height) precondition(abs(topRect.maxY - 166) < 1 && topRect.height > 75, "The native table must fill the equal-height row down to its 10pt inset: \(language), \(width), \(topRect)") precondition(abs(topRect.minX - 10) < 1 && abs(topRect.maxX - (width - 10)) < 1) } } } host.rootView = AnyView(EmptyView()); window.orderOut(nil); window.close() print("PASS: production process section at 176pt, wrapped scope notes, full remaining table height, two widths, three languages and light/dark") NSApp.terminate(nil) } NSApp.run() } @MainActor private static func descendants(_ view: NSView) -> [NSView] { [view] + view.subviews.flatMap(descendants) } }