diff --git a/Sources/ParcelUI/Resources/TourDemos.xcstrings b/Sources/ParcelUI/Resources/TourDemos.xcstrings index d48b8792..a5af84fe 100644 --- a/Sources/ParcelUI/Resources/TourDemos.xcstrings +++ b/Sources/ParcelUI/Resources/TourDemos.xcstrings @@ -1,6 +1,19 @@ { "sourceLanguage": "en", "strings": { + "Windows arranging themselves into tidy tiles": { + "extractionState": "manual", + "localizations": { + "en": {"stringUnit": {"state": "translated", "value": "Windows arranging themselves into tidy tiles"}}, + "es": {"stringUnit": {"state": "translated", "value": "Ventanas que se organizan solas en mosaicos ordenados"}}, + "fr": {"stringUnit": {"state": "translated", "value": "Des fenêtres qui s’organisent en mosaïque bien ordonnée"}}, + "de": {"stringUnit": {"state": "translated", "value": "Fenster ordnen sich von selbst zu übersichtlichen Kacheln an"}}, + "ja": {"stringUnit": {"state": "translated", "value": "ウインドウが自動できれいなタイル状に整列します"}}, + "zh-Hans": {"stringUnit": {"state": "translated", "value": "窗口自动排列成整齐的平铺布局"}}, + "ko": {"stringUnit": {"state": "translated", "value": "윈도우가 스스로 깔끔한 타일로 정렬됩니다"}}, + "pt-BR": {"stringUnit": {"state": "translated", "value": "Janelas se organizando sozinhas em blocos alinhados"}} + } + }, "Switch to %@": { "comment": "Demo card title; placeholder is the destination layout name.", "extractionState": "manual", diff --git a/Sources/ParcelUI/Tour/TourDemoCanvas.swift b/Sources/ParcelUI/Tour/TourDemoCanvas.swift index 1421c352..dba1558c 100644 --- a/Sources/ParcelUI/Tour/TourDemoCanvas.swift +++ b/Sources/ParcelUI/Tour/TourDemoCanvas.swift @@ -2,22 +2,30 @@ import ParcelConfig import SwiftUI struct TourDemoCanvas: View { - let configuration: ParcelConfiguration - let layout: ConfigLayout - let windowCount: Int - let kind: TourDemoKind - let showsResult: Bool + let scene: TourDemoScene + var decorative = false @Environment(\.colorSchemeContrast) private var contrast - var body: some View { - let scene = TourDemoScene( + init(scene: TourDemoScene, decorative: Bool = false) { + self.scene = scene + self.decorative = decorative + } + + init( + configuration: ParcelConfiguration, layout: ConfigLayout, windowCount: Int, + kind: TourDemoKind, showsResult: Bool + ) { + scene = TourDemoScene( configuration: configuration, layout: layout, windowCount: windowCount, kind: kind, showsResult: showsResult ) + } + + var body: some View { GeometryReader { geometry in ZStack(alignment: .topLeading) { ForEach(scene.windows) { window in - TourDemoWindowView(window: window) + TourDemoWindowView(window: window, decorative: decorative) .frame( width: window.frame.width * geometry.size.width, height: window.frame.height * geometry.size.height @@ -27,6 +35,7 @@ struct TourDemoCanvas: View { y: window.frame.midY * geometry.size.height ) .zIndex(window.floating || window.stackCount > 1 ? 1 : 0) + .transition(.opacity) } } } diff --git a/Sources/ParcelUI/Tour/TourDemoKind.swift b/Sources/ParcelUI/Tour/TourDemoKind.swift index df66b9b4..31dc2761 100644 --- a/Sources/ParcelUI/Tour/TourDemoKind.swift +++ b/Sources/ParcelUI/Tour/TourDemoKind.swift @@ -36,7 +36,8 @@ enum TourDemoKind: String, CaseIterable, Identifiable, Sendable { var token: MotionToken { switch self { - case .welcome, .swap, .layout: .shuffle + case .welcome: .settle + case .swap, .layout: .shuffle case .next: .glance case .stack: .stack case .float: .pop diff --git a/Sources/ParcelUI/Tour/TourDemoLoopPlayback.swift b/Sources/ParcelUI/Tour/TourDemoLoopPlayback.swift new file mode 100644 index 00000000..82bd7ce3 --- /dev/null +++ b/Sources/ParcelUI/Tour/TourDemoLoopPlayback.swift @@ -0,0 +1,23 @@ +struct TourDemoLoopPlayback: Equatable { + private(set) var step = TourDemoStep.oneWindow + private(set) var isPlaying = false + private(set) var generation = 0 + + mutating func update(animated: Bool, pageVisible: Bool, windowActive: Bool) -> Int? { + generation += 1 + isPlaying = animated && pageVisible && windowActive + if !animated { + step = .grid + } else if isPlaying { + step = .oneWindow + } + return isPlaying ? generation : nil + } + + @discardableResult + mutating func advance(generation expected: Int) -> Bool { + guard isPlaying, generation == expected else { return false } + step = step.next + return true + } +} diff --git a/Sources/ParcelUI/Tour/TourDemoPlayer.swift b/Sources/ParcelUI/Tour/TourDemoPlayer.swift index 60337915..61088c62 100644 --- a/Sources/ParcelUI/Tour/TourDemoPlayer.swift +++ b/Sources/ParcelUI/Tour/TourDemoPlayer.swift @@ -15,6 +15,14 @@ struct TourDemoPlayer: View { } var body: some View { + if kind == .welcome { + TourDemoWelcome(configuration: configuration) + } else { + interactiveDemo + } + } + + private var interactiveDemo: some View { Button(action: replay) { content(motion.spec == nil || playback.showsResult) .contentShape(.rect) @@ -29,7 +37,6 @@ struct TourDemoPlayer: View { ) .accessibilityInputLabels([Text(kind.title)]) .onHover(perform: hover) - .onAppear(perform: appear) .onChange(of: motion) { resetPlayback() } .onDisappear(perform: resetPlayback) } @@ -39,10 +46,6 @@ struct TourDemoPlayer: View { replay() } - private func appear() { - if kind == .welcome { replay() } - } - private func replay() { guard let animation = motion.animation else { resetPlayback() diff --git a/Sources/ParcelUI/Tour/TourDemoPresenceView.swift b/Sources/ParcelUI/Tour/TourDemoPresenceView.swift new file mode 100644 index 00000000..8b465dba --- /dev/null +++ b/Sources/ParcelUI/Tour/TourDemoPresenceView.swift @@ -0,0 +1,48 @@ +import AppKit + +final class TourDemoPresenceView: NSView { + private let publish: (Bool) -> Void + + init(publish: @escaping (Bool) -> Void) { + self.publish = publish + super.init(frame: .zero) + setAccessibilityElement(false) + } + + required init?(coder: NSCoder) { nil } + + override func viewDidMoveToWindow() { + super.viewDidMoveToWindow() + stopObserving() + if let window { + for name in [ + NSWindow.didBecomeKeyNotification, NSWindow.didResignKeyNotification, + NSWindow.didChangeOcclusionStateNotification, NSWindow.didMiniaturizeNotification, + NSWindow.didDeminiaturizeNotification, NSWindow.willCloseNotification, + ] { + NotificationCenter.default.addObserver(self, selector: #selector(refresh), name: name, object: window) + } + } + refresh() + } + + func stopObserving() { + NotificationCenter.default.removeObserver(self) + } + + override func hitTest(_ point: NSPoint) -> NSView? { nil } + + @objc private func refresh() { + // Window attachment happens during SwiftUI updates; publish on the next actor turn. + Task { @MainActor [weak self] in + guard let self else { return } + publish(Self.isActive(window)) + } + } + + static func isActive(_ window: NSWindow?) -> Bool { + guard let window else { return false } + return window.isVisible && window.isKeyWindow && !window.isMiniaturized + && window.occlusionState.contains(.visible) + } +} diff --git a/Sources/ParcelUI/Tour/TourDemoScene.swift b/Sources/ParcelUI/Tour/TourDemoScene.swift index 250e5b51..e19fccb5 100644 --- a/Sources/ParcelUI/Tour/TourDemoScene.swift +++ b/Sources/ParcelUI/Tour/TourDemoScene.swift @@ -25,16 +25,6 @@ struct TourDemoScene: Equatable { } var windows = Self.arrange( configuration: configuration, layout: self.layout, identifiers: Array(0.. [TourDemoWindow] { guard !identifiers.isEmpty else { return [] } - let screen = Rect(x: 0, y: 0, width: 1280, height: 800) + let screen = Rect(x: 0, y: 0, width: 1600, height: 1000) let values = configuration.layout.global let order = identifiers.map { WindowID(rawValue: UInt32($0 + 1)) } let coreLayout: Layout = @@ -105,11 +95,12 @@ struct TourDemoScene: Equatable { guard let frame = result.frames[stack.visible] else { preconditionFailure("Every visible miniature window needs a layout frame") } + let miniatureFrame = frame.learningRect return TourDemoWindow( id: Int(stack.visible.rawValue) - 1, frame: CGRect( - x: frame.minX / screen.size.width, y: frame.minY / screen.size.height, - width: frame.size.width / screen.size.width, height: frame.size.height / screen.size.height), + x: miniatureFrame.minX / screen.size.width, y: miniatureFrame.minY / screen.size.height, + width: miniatureFrame.width / screen.size.width, height: miniatureFrame.height / screen.size.height), focused: stack.windows.contains(order[0]), stackCount: stack.windows.count, floating: false, dimmed: false) } diff --git a/Sources/ParcelUI/Tour/TourDemoStep.swift b/Sources/ParcelUI/Tour/TourDemoStep.swift new file mode 100644 index 00000000..431f8eb9 --- /dev/null +++ b/Sources/ParcelUI/Tour/TourDemoStep.swift @@ -0,0 +1,38 @@ +import ParcelConfig + +enum TourDemoStep: Int, CaseIterable, Sendable { + case oneWindow, twoWindows, threeWindows, fourWindows, grid, side + + var windowCount: Int { + switch self { + case .oneWindow: 1 + case .twoWindows: 2 + case .threeWindows: 3 + case .fourWindows, .grid, .side: 4 + } + } + + var layout: ConfigLayout { + switch self { + case .oneWindow, .twoWindows, .threeWindows, .fourWindows: .columns + case .grid: .grid + case .side: .side + } + } + + var next: Self { + switch self { + case .oneWindow: .twoWindows + case .twoWindows: .threeWindows + case .threeWindows: .fourWindows + case .fourWindows: .grid + case .grid: .side + case .side: .oneWindow + } + } + + func scene(configuration: ParcelConfiguration) -> TourDemoScene { + TourDemoScene( + configuration: configuration, layout: layout, windowCount: windowCount, kind: .welcome, showsResult: true) + } +} diff --git a/Sources/ParcelUI/Tour/TourDemoWelcome.swift b/Sources/ParcelUI/Tour/TourDemoWelcome.swift new file mode 100644 index 00000000..561dab84 --- /dev/null +++ b/Sources/ParcelUI/Tour/TourDemoWelcome.swift @@ -0,0 +1,75 @@ +import ParcelConfig +import SwiftUI + +struct TourDemoWelcome: View { + let configuration: ParcelConfiguration + @Environment(\.accessibilityReduceMotion) private var reduceMotion + @State private var playback = TourDemoLoopPlayback() + @State private var windowActive = false + @State private var pageVisible = false + + private var motion: TourDemoMotion { + TourDemoMotion(configuration: configuration.motion, reduceMotion: reduceMotion, kind: .welcome) + } + + var body: some View { + TourDemoCanvas( + scene: (motion.spec == nil ? TourDemoStep.grid : playback.step).scene(configuration: configuration), + decorative: true + ) + .aspectRatio(1.6, contentMode: .fit) + .id(playback.isPlaying) + .transaction { + if !playback.isPlaying || motion.spec == nil { + $0.animation = nil + $0.disablesAnimations = true + } + } + .allowsHitTesting(false) + .accessibilityHidden(false) + .accessibilityElement(children: .ignore) + .accessibilityLabel(TourDemoText.text("Windows arranging themselves into tidy tiles")) + .background(TourDemoWindowPresence(isActive: $windowActive).frame(width: 0, height: 0)) + .onAppear { pageVisible = true } + .onDisappear { + pageVisible = false + stop() + } + .task(id: Request(motion: motion, pageVisible: pageVisible, windowActive: windowActive)) { + await play() + } + } + + private func stop() { + var transaction = Transaction(animation: nil) + transaction.disablesAnimations = true + withTransaction(transaction) { + _ = playback.update(animated: motion.spec != nil, pageVisible: false, windowActive: false) + } + } + + private func play() async { + let generation = playback.update( + animated: motion.spec != nil, pageVisible: pageVisible, windowActive: windowActive) + guard let generation, let spec = motion.spec, let animation = motion.animation else { return } + while !Task.isCancelled { + do { + try await Task.sleep(for: .seconds(1.6 + spec.duration)) + } catch is CancellationError { + return + } catch { + preconditionFailure("Unexpected miniature clock failure: \(error)") + } + guard !Task.isCancelled else { return } + var advanced = false + withAnimation(animation) { advanced = playback.advance(generation: generation) } + guard advanced else { return } + } + } + + private struct Request: Equatable { + let motion: TourDemoMotion + let pageVisible: Bool + let windowActive: Bool + } +} diff --git a/Sources/ParcelUI/Tour/TourDemoWindowPresence.swift b/Sources/ParcelUI/Tour/TourDemoWindowPresence.swift new file mode 100644 index 00000000..52ff28f3 --- /dev/null +++ b/Sources/ParcelUI/Tour/TourDemoWindowPresence.swift @@ -0,0 +1,15 @@ +import SwiftUI + +struct TourDemoWindowPresence: NSViewRepresentable { + @Binding var isActive: Bool + + func makeNSView(context: Context) -> TourDemoPresenceView { + TourDemoPresenceView { isActive = $0 } + } + + func updateNSView(_ view: TourDemoPresenceView, context: Context) {} + + static func dismantleNSView(_ view: TourDemoPresenceView, coordinator: ()) { + view.stopObserving() + } +} diff --git a/Sources/ParcelUI/Tour/TourDemoWindowView.swift b/Sources/ParcelUI/Tour/TourDemoWindowView.swift index 133b70b6..cd61751c 100644 --- a/Sources/ParcelUI/Tour/TourDemoWindowView.swift +++ b/Sources/ParcelUI/Tour/TourDemoWindowView.swift @@ -2,26 +2,54 @@ import SwiftUI struct TourDemoWindowView: View { let window: TourDemoWindow + var decorative = false + @Environment(\.colorScheme) private var colorScheme @Environment(\.accessibilityReduceTransparency) private var reduceTransparency @Environment(\.colorSchemeContrast) private var contrast private var border: Color { - window.focused && contrast != .increased ? .accentColor : .primary + decorative || contrast == .increased ? .primary : (window.focused ? .accentColor : .primary) + } + + private var fill: Color { + guard decorative else { + return Color(nsColor: window.dimmed ? .windowBackgroundColor : .controlBackgroundColor) + } + guard let palette = AppearancePaletteColors.curated(.kiln, dark: colorScheme == .dark) else { + preconditionFailure("The welcome demo needs its brand palette") + } + let color = [palette.active, palette.inactive, palette.glow, palette.active][window.id % 4] + return Color(red: color.red, green: color.green, blue: color.blue) } var body: some View { ZStack { RoundedRectangle(cornerRadius: 5) - .fill(Color(nsColor: window.dimmed ? .windowBackgroundColor : .controlBackgroundColor)) + .fill(fill) .strokeBorder( border, style: StrokeStyle( - lineWidth: window.focused || contrast == .increased ? 2 : 1, + lineWidth: contrast == .increased || (!decorative && window.focused) ? 2 : 1, dash: window.floating ? [3, 2] : [])) - Text((window.id + 1).formatted()) - .font(.body.monospacedDigit()) - .bold() - .foregroundStyle(window.dimmed ? .secondary : .primary) + if decorative { + VStack(alignment: .leading, spacing: 5) { + HStack(spacing: 3) { + ForEach(0..<3) { _ in Circle().frame(width: 3, height: 3) } + } + .padding(.bottom, 5) + Capsule().frame(height: 3) + Capsule().frame(height: 3).padding(.trailing, 12) + Spacer(minLength: 0) + } + .foregroundStyle(.white.opacity(contrast == .increased ? 1 : 0.65)) + .padding(8) + .clipped() + } else { + Text((window.id + 1).formatted()) + .font(.body.monospacedDigit()) + .bold() + .foregroundStyle(window.dimmed ? .secondary : .primary) + } if window.stackCount > 1 { Image(systemName: "square.on.square") .font(.caption) diff --git a/Tests/ParcelUITests/Tour/TourDemoTests.swift b/Tests/ParcelUITests/Tour/TourDemoTests.swift index 11cb6d84..bca3b049 100644 --- a/Tests/ParcelUITests/Tour/TourDemoTests.swift +++ b/Tests/ParcelUITests/Tour/TourDemoTests.swift @@ -1,6 +1,8 @@ import Foundation +import ImageIO import ParcelAnimation import ParcelConfig +import ParcelCore import SwiftUI import Testing @@ -339,6 +341,164 @@ struct TourDemoTests { } } + @Test func welcomeArrivalsThenLayoutsLoopWithoutLosingIdentity() throws { + #expect(TourDemoStep.allCases.map(\.windowCount) == [1, 2, 3, 4, 4, 4]) + #expect(TourDemoStep.allCases.map(\.layout) == [.columns, .columns, .columns, .columns, .grid, .side]) + var playback = TourDemoLoopPlayback() + let started = playback.update(animated: true, pageVisible: true, windowActive: true) + let generation = try #require(started) + for step in TourDemoStep.allCases { + #expect(playback.step == step) + let scene = step.scene(configuration: .defaults) + #expect(Set(scene.windows.map(\.id)) == Set(0.. TourDemoScene { -- knotmirror 0.0.1 From 8596ad7317b7d535e1253879e6e575151aa84046 Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Thu, 5 Nov 2026 13:14:56 -0500 Subject: [PATCH 2/2] Verify welcome playback and cancellation Signed-off-by: Vincent Taverna --- Benchmarks/idle-waits.json | 3 +- .../ParcelUI/Tour/TourDemoLoopPlayback.swift | 3 +- Sources/ParcelUI/Tour/TourDemoWelcome.swift | 26 +++--- .../Tour/TourDemoHostTests.swift | 88 +++++++++++++++++++ Tests/ParcelUITests/Tour/TourDemoTests.swift | 12 +++ 5 files changed, 119 insertions(+), 13 deletions(-) create mode 100644 Tests/ParcelUITests/Tour/TourDemoHostTests.swift diff --git a/Benchmarks/idle-waits.json b/Benchmarks/idle-waits.json index 31b89887..548bc97b 100644 --- a/Benchmarks/idle-waits.json +++ b/Benchmarks/idle-waits.json @@ -35,5 +35,6 @@ {"path":"ParcelUI/HoverBar/HoverBarController.swift","count":1,"why":"Pointer activity schedules a hover deadline; cancelled when hidden or stopped."}, {"path":"ParcelUI/Settings/AlwaysFloatConfirmation.swift","count":1,"why":"Explicit confirmation countdown owns this wait while visible; expires after 12 or 60 unpaused seconds, pauses for accessibility and interaction, and cancels when the notice closes."}, {"path":"ParcelUI/Settings/SettingsView.swift","count":3,"why":"Search input owns one 350 ms announcement debounce; a selected result owns one 100 ms layout-resolution wait and one two-second highlight deadline. Replaced input, selection, or view cancellation ends the corresponding wait; there is no idle poll."}, - {"path":"ParcelUI/Tour/TourView.swift","count":1,"why":"Finite tour motion; ends at its token duration."} + {"path":"ParcelUI/Tour/TourView.swift","count":1,"why":"Finite tour motion; ends at its token duration."}, + {"path":"ParcelUI/Tour/TourDemoWelcome.swift","count":1,"why":"Only the visible, key welcome page owns a miniature dwell of 1.6 seconds plus the motion token duration. Page removal, key or visibility loss, Reduce Motion and motion-off cancel playback; no hidden or static view arms a wait."} ] diff --git a/Sources/ParcelUI/Tour/TourDemoLoopPlayback.swift b/Sources/ParcelUI/Tour/TourDemoLoopPlayback.swift index 82bd7ce3..153fecaf 100644 --- a/Sources/ParcelUI/Tour/TourDemoLoopPlayback.swift +++ b/Sources/ParcelUI/Tour/TourDemoLoopPlayback.swift @@ -3,7 +3,8 @@ struct TourDemoLoopPlayback: Equatable { private(set) var isPlaying = false private(set) var generation = 0 - mutating func update(animated: Bool, pageVisible: Bool, windowActive: Bool) -> Int? { + mutating func update(animated: Bool, pageVisible: Bool, windowActive: Bool, cancelled: Bool = false) -> Int? { + guard !cancelled else { return nil } generation += 1 isPlaying = animated && pageVisible && windowActive if !animated { diff --git a/Sources/ParcelUI/Tour/TourDemoWelcome.swift b/Sources/ParcelUI/Tour/TourDemoWelcome.swift index 561dab84..6ed267ca 100644 --- a/Sources/ParcelUI/Tour/TourDemoWelcome.swift +++ b/Sources/ParcelUI/Tour/TourDemoWelcome.swift @@ -13,18 +13,21 @@ struct TourDemoWelcome: View { } var body: some View { - TourDemoCanvas( - scene: (motion.spec == nil ? TourDemoStep.grid : playback.step).scene(configuration: configuration), - decorative: true - ) - .aspectRatio(1.6, contentMode: .fit) - .id(playback.isPlaying) - .transaction { - if !playback.isPlaying || motion.spec == nil { - $0.animation = nil - $0.disablesAnimations = true + ZStack { + TourDemoCanvas( + scene: (motion.spec == nil ? TourDemoStep.grid : playback.step).scene(configuration: configuration), + decorative: true + ) + // Drop in-flight interpolation without restarting the page's lifecycle. + .id(playback.isPlaying) + .transaction { + if !playback.isPlaying || motion.spec == nil { + $0.animation = nil + $0.disablesAnimations = true + } } } + .aspectRatio(1.6, contentMode: .fit) .allowsHitTesting(false) .accessibilityHidden(false) .accessibilityElement(children: .ignore) @@ -50,7 +53,8 @@ struct TourDemoWelcome: View { private func play() async { let generation = playback.update( - animated: motion.spec != nil, pageVisible: pageVisible, windowActive: windowActive) + animated: motion.spec != nil, pageVisible: pageVisible, windowActive: windowActive, + cancelled: Task.isCancelled) guard let generation, let spec = motion.spec, let animation = motion.animation else { return } while !Task.isCancelled { do { diff --git a/Tests/ParcelUITests/Tour/TourDemoHostTests.swift b/Tests/ParcelUITests/Tour/TourDemoHostTests.swift new file mode 100644 index 00000000..bbe2c4a4 --- /dev/null +++ b/Tests/ParcelUITests/Tour/TourDemoHostTests.swift @@ -0,0 +1,88 @@ +import AppKit +import ImageIO +import ParcelConfig +import SwiftUI +import Testing + +@testable import ParcelTestSupport +@testable import ParcelUI + +extension AppKitTestSuite.TourSetupRenderingTests { + @Test func welcomeObservesOnlyItsOwnKeyVisibleWindowAndDetachesCleanly() async throws { + try #require(FileManager.default.fileExists(atPath: "/tmp/parcel-m3-free"), "The QA screen must be available") + _ = NSApplication.shared + let window = LearningPanel(title: "Welcome demo fixture", interactive: true) + window.setFrame(CGRect(x: 100, y: 100, width: 256, height: 160), display: false) + window.isRestorable = false + window.becomesKeyOnlyIfNeeded = false + var active = false + let presence = TourDemoPresenceView { active = $0 } + window.contentView = presence + defer { + presence.stopObserving() + window.close() + } + #expect(!TourDemoPresenceView.isActive(nil)) + #expect(!active) + window.makeKeyAndOrderFront(nil) + try await waitForUI("Owned demo window becomes active") { active } + #expect(TourDemoPresenceView.isActive(window)) + window.resignKey() + try await waitForUI("Losing key status stops the demo") { !active } + window.makeKey() + try await waitForUI("Returning to the demo resumes it") { active } + window.orderOut(nil) + try await waitForUI("Ordering the demo out stops it") { !active } + window.contentView = nil + try await waitForUI("Detached observer has no active window") { presence.window == nil && !active } + } + + @Test( + .enabled( + if: ProcessInfo.processInfo.environment["PARCEL_TOUR_DEMO_QA_DIR"] != nil, + "Own-view recording requires a private QA output directory")) + func recordOwnedWelcomeWithoutScreenCaptureOrProductState() async throws { + let path = try #require(ProcessInfo.processInfo.environment["PARCEL_TOUR_DEMO_QA_DIR"]) + try #require(FileManager.default.fileExists(atPath: "/tmp/parcel-m3-free"), "The QA screen must be available") + try E2EConsoleSession.requireUnlockedConsole() + let file = URL(fileURLWithPath: path, isDirectory: true).appendingPathComponent("welcome-loop.gif") + try #require(!FileManager.default.fileExists(atPath: file.path), "Refuse to overwrite QA evidence") + _ = NSApplication.shared + let window = LearningPanel(title: "Welcome demo fixture", interactive: true) + window.setFrame(CGRect(x: 100, y: 100, width: 256, height: 160), display: false) + window.isRestorable = false + window.becomesKeyOnlyIfNeeded = false + let host = NSHostingView( + rootView: TourDemoWelcome(configuration: .defaults) + .environment(\.colorScheme, .light)) + window.contentView = host + defer { window.close() } + window.makeKeyAndOrderFront(nil) + try await waitForUI("Owned welcome is key and visible") { TourDemoPresenceView.isActive(window) } + let destination = try #require( + CGImageDestinationCreateWithURL(file as CFURL, "com.compuserve.gif" as CFString, 112, nil)) + CGImageDestinationSetProperties( + destination, [kCGImagePropertyGIFDictionary: [kCGImagePropertyGIFLoopCount: 0]] as CFDictionary) + var sampledFrames = Set() + for _ in 0..<112 { + try #require( + FileManager.default.fileExists(atPath: "/tmp/parcel-m3-free"), "QA screen availability changed") + try E2EConsoleSession.requireUnlockedConsole() + try #require(TourDemoPresenceView.isActive(window), "Recording must stay in its owned window") + host.layoutSubtreeIfNeeded() + let bitmap = try #require(host.bitmapImageRepForCachingDisplay(in: host.bounds)) + host.cacheDisplay(in: host.bounds, to: bitmap) + let image = try #require(bitmap.cgImage) + let bytes = try #require(image.dataProvider?.data) + sampledFrames.insert(bytes as Data) + CGImageDestinationAddImage( + destination, image, [kCGImagePropertyGIFDictionary: [kCGImagePropertyGIFDelayTime: 0.1]] as CFDictionary + ) + try await Task.sleep(for: .milliseconds(100)) + } + #expect(CGImageDestinationFinalize(destination)) + #expect( + sampledFrames.count > TourDemoStep.allCases.count, "Recording must include moving frames, not just stills") + } + +} diff --git a/Tests/ParcelUITests/Tour/TourDemoTests.swift b/Tests/ParcelUITests/Tour/TourDemoTests.swift index bca3b049..4859b553 100644 --- a/Tests/ParcelUITests/Tour/TourDemoTests.swift +++ b/Tests/ParcelUITests/Tour/TourDemoTests.swift @@ -432,6 +432,18 @@ struct TourDemoTests { #expect(fresh) } + @Test func cancelledStartsCannotInvalidateANewerLoop() throws { + var playback = TourDemoLoopPlayback() + let started = playback.update(animated: true, pageVisible: true, windowActive: true) + let generation = try #require(started) + let active = playback + let cancelled = playback.update(animated: true, pageVisible: true, windowActive: true, cancelled: true) + #expect(cancelled == nil) + #expect(playback == active) + let advanced = playback.advance(generation: generation) + #expect(advanced) + } + @Test func reduceMotionStopsAnActiveLoopAtAStaticGrid() throws { var playback = TourDemoLoopPlayback() let run = playback.update(animated: true, pageVisible: true, windowActive: true)