native macOS codings agent orchestrator prowl.onev.cat
Something went wrong. Try again.
Swift
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140import ComposableArchitectureimport DependenciesTestSupportimport Foundationimport Testing
@testable import Prowl
@MainActorstruct AppFeatureDockTests { private func notificationReceived() -> AppFeature.Action { .terminalEvent( .notificationReceived( worktreeID: "/tmp/repo/wt-1", surfaceID: UUID(), title: "Done", body: "Build succeeded", isViewed: false ) ) }
@Test(.dependencies) func notificationReceivedBouncesOnceWhenModeIsOnce() async { var globalSettings = GlobalSettings.default globalSettings.dockBounceMode = .once let bounces = LockIsolated<[DockBounceMode]>([]) let store = TestStore( initialState: AppFeature.State(settings: SettingsFeature.State(settings: globalSettings)) ) { AppFeature() } withDependencies: { $0.dockClient.bounce = { mode in bounces.withValue { $0.append(mode) } } } store.exhaustivity = .off
await store.send(notificationReceived()) await store.finish()
#expect(bounces.value == [.once]) }
@Test(.dependencies) func notificationReceivedBouncesContinuouslyWhenModeIsContinuous() async { var globalSettings = GlobalSettings.default globalSettings.dockBounceMode = .continuous let bounces = LockIsolated<[DockBounceMode]>([]) let store = TestStore( initialState: AppFeature.State(settings: SettingsFeature.State(settings: globalSettings)) ) { AppFeature() } withDependencies: { $0.dockClient.bounce = { mode in bounces.withValue { $0.append(mode) } } } store.exhaustivity = .off
await store.send(notificationReceived()) await store.finish()
#expect(bounces.value == [.continuous]) }
@Test(.dependencies) func notificationReceivedDoesNotBounceWhenModeIsOff() async { // `.off` is the default; no bounce effect should be scheduled at all. let globalSettings = GlobalSettings.default let bounces = LockIsolated<[DockBounceMode]>([]) let store = TestStore( initialState: AppFeature.State(settings: SettingsFeature.State(settings: globalSettings)) ) { AppFeature() } withDependencies: { $0.dockClient.bounce = { mode in bounces.withValue { $0.append(mode) } } } store.exhaustivity = .off
await store.send(notificationReceived()) await store.finish()
#expect(bounces.value.isEmpty) }
@Test(.dependencies) func indicatorChangeShowsBadgeWhenEnabledAndCountPositive() async { var globalSettings = GlobalSettings.default globalSettings.showNotificationDotOnDock = true let badges = LockIsolated<[Int]>([]) let store = TestStore( initialState: AppFeature.State(settings: SettingsFeature.State(settings: globalSettings)) ) { AppFeature() } withDependencies: { $0.dockClient.setNotificationBadge = { count in badges.withValue { $0.append(count) } } } store.exhaustivity = .off
await store.send(.terminalEvent(.notificationIndicatorChanged(count: 2))) { $0.notificationIndicatorCount = 2 } await store.finish()
#expect(badges.value == [2]) }
@Test(.dependencies) func indicatorChangeClearsBadgeWhenDisabled() async { var globalSettings = GlobalSettings.default globalSettings.showNotificationDotOnDock = false let badges = LockIsolated<[Int]>([]) let store = TestStore( initialState: AppFeature.State(settings: SettingsFeature.State(settings: globalSettings)) ) { AppFeature() } withDependencies: { $0.dockClient.setNotificationBadge = { count in badges.withValue { $0.append(count) } } } store.exhaustivity = .off
await store.send(.terminalEvent(.notificationIndicatorChanged(count: 3))) { $0.notificationIndicatorCount = 3 } await store.finish()
#expect(badges.value == [0]) }
@Test(.dependencies) func indicatorChangeClearsBadgeWhenCountZero() async { var globalSettings = GlobalSettings.default globalSettings.showNotificationDotOnDock = true let badges = LockIsolated<[Int]>([]) let store = TestStore( initialState: AppFeature.State(settings: SettingsFeature.State(settings: globalSettings)) ) { AppFeature() } withDependencies: { $0.dockClient.setNotificationBadge = { count in badges.withValue { $0.append(count) } } } store.exhaustivity = .off
await store.send(.terminalEvent(.notificationIndicatorChanged(count: 0))) await store.finish()
#expect(badges.value == [0]) }}