PulseCanvas / app · pulsecanvas.ai / scripts / PresetStripSmoke.swift
| 1 | import Foundation |
| 2 | import AppKit |
| 3 | import SwiftUI |
| 4 | @main struct PresetStripSmoke { |
| 5 | @MainActor static func main() { |
| 6 | _ = NSApplication.shared |
| 7 | let suite = "PulseCanvas.StripTests." + UUID().uuidString |
| 8 | let defaults = UserDefaults(suiteName: suite)! |
| 9 | defer { defaults.removePersistentDomain(forName: suite) } |
| 10 | let library = ProjectMPresets(defaults: defaults) |
| 11 | let strip = PresetStripView(frame: NSRect(x:0,y:0,width:1000,height:90)) |
| 12 | precondition(strip.hasHorizontalScroller && !strip.autohidesScrollers && strip.scrollerStyle == .legacy, "The library row needs a persistent scrollbar") |
| 13 | var chosen = -1 |
| 14 | for scene in [10, 2000, library.sceneNames.count - 1, 22, 7000] where library.availableScenes.contains(scene) { |
| 15 | let beforeSelection = strip.contentView.bounds.origin.x |
| 16 | strip.update(library:library,selected:scene,accent:.systemPink,background:.black) {chosen=$0} |
| 17 | strip.layoutSubtreeIfNeeded() |
| 18 | precondition(abs(strip.contentView.bounds.origin.x - beforeSelection) < 1, "Selecting a visualizer must not jump the row") |
| 19 | let font = NSFont.systemFont(ofSize:12,weight:.medium) |
| 20 | let position = library.availableScenes.firstIndex(of: scene)! |
| 21 | let start = library.availableScenes.prefix(position).map { library.sceneNames[$0] }.reduce(CGFloat(0)) { $0 + ceil(($1 as NSString).size(withAttributes:[.font:font]).width) + 78 } |
| 22 | strip.contentView.scroll(to: NSPoint(x:min(start,max(0,strip.documentView!.frame.width-strip.contentView.bounds.width)),y:0)) |
| 23 | strip.reflectScrolledClipView(strip.contentView) |
| 24 | strip.layoutSubtreeIfNeeded() |
| 25 | let buttons = strip.documentView!.subviews.compactMap {$0 as? NSButton} |
| 26 | precondition(!buttons.isEmpty && buttons.count < 20, "The row must only instantiate visible buttons") |
| 27 | let selected = buttons.first {$0.tag == scene}! |
| 28 | let textWidth = (selected.title as NSString).size(withAttributes:[.font:NSFont.systemFont(ofSize:12,weight:.medium)]).width |
| 29 | precondition(selected.frame.width >= textWidth + 71 && selected.frame.height == 62) |
| 30 | precondition(strip.contentView.bounds.intersects(selected.frame), "Large jumps must reach the selected preset directly") |
| 31 | precondition(strip.contentView.bounds.contains(selected.frame), "Scrollbar must not clip the selected card") |
| 32 | precondition(selected.accessibilityLabel() == library.sceneNames[scene] && selected.toolTip != nil) |
| 33 | selected.performClick(nil) |
| 34 | precondition(chosen == scene, "Entire native button sends its own preset identity") |
| 35 | } |
| 36 | let beforeResize = strip.contentView.bounds.origin.x |
| 37 | strip.frame.size.width = 650 |
| 38 | strip.layoutSubtreeIfNeeded() |
| 39 | precondition(abs(strip.contentView.bounds.origin.x - beforeResize) < 1, "Resize must preserve the browsing position") |
| 40 | for (request, scene) in [10, 22, library.sceneNames.count - 1].enumerated() { |
| 41 | strip.update(library:library,selected:scene,accent:.systemPink,background:.black,revealRequest:request + 1) {chosen=$0} |
| 42 | strip.layoutSubtreeIfNeeded() |
| 43 | let revealed = strip.documentView!.subviews.compactMap {$0 as? NSButton}.first {$0.tag == scene}! |
| 44 | precondition(abs(revealed.frame.minX - strip.contentView.bounds.minX) < 1, "Randomizer reveal must align left") |
| 45 | } |
| 46 | let beforeNormalSelection = strip.contentView.bounds.origin.x |
| 47 | strip.update(library:library,selected:22,accent:.systemPink,background:.black,isEnabled:false,revealRequest:3) {chosen=$0} |
| 48 | precondition(abs(strip.contentView.bounds.origin.x - beforeNormalSelection) < 1, "Normal selection after randomize must stay still") |
| 49 | precondition(strip.documentView!.subviews.compactMap {$0 as? NSButton}.allSatisfy {!$0.isEnabled}) |
| 50 | library.setRandomizerGroup(.favorites) |
| 51 | strip.update(library:library,selected:22,accent:.systemPink,background:.black) {chosen=$0} |
| 52 | strip.layoutSubtreeIfNeeded() |
| 53 | precondition(strip.contentView.bounds.minX == 0 && strip.documentView!.subviews.isEmpty, |
| 54 | "An empty filter must clear old controls and reset an out-of-range scroll offset") |
| 55 | library.toggleFavorite(10); library.toggleFavorite(22) |
| 56 | strip.update(library:library,selected:22,accent:.systemPink,background:.black) {chosen=$0} |
| 57 | strip.layoutSubtreeIfNeeded() |
| 58 | let filteredButtons = strip.documentView!.subviews.compactMap {$0 as? NSButton} |
| 59 | precondition(Set(filteredButtons.map(\.tag)) == [10, 22]) |
| 60 | library.setRandomizerGroup(.category("Tunnels")) |
| 61 | strip.update(library:library,selected:22,accent:.systemPink,background:.black) {chosen=$0} |
| 62 | strip.layoutSubtreeIfNeeded() |
| 63 | precondition(strip.documentView!.subviews.compactMap {$0 as? NSButton}.allSatisfy { library.category(for: $0.tag) == "Tunnels" }) |
| 64 | library.setRandomizerGroup(.all) |
| 65 | strip.update(library:library,selected:22,accent:.systemPink,background:.black) {chosen=$0} |
| 66 | strip.layoutSubtreeIfNeeded() |
| 67 | precondition(!strip.documentView!.subviews.isEmpty && strip.contentView.bounds.minX == 0) |
| 68 | print("PASS shared filter: favorites/category affect the top strip; empty and shortened lists clear stale controls and scroll offsets; All restores the gallery") |
| 69 | print("PASS virtual preset row: persistent scrollbar; ordinary selection and resize stay still; randomizer reveal aligns left; fewer than 20 resident controls; full names; accessible whole-card actions") |
| 70 | } |
| 71 | } |