native macOS codings agent orchestrator prowl.onev.cat
Something went wrong. Try again.
3.6 kB · 120 lines
Swift
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121import ComposableArchitectureimport DependenciesTestSupportimport Testing
@testable import supacode
@MainActor@Suite(.serialized)struct UpdatesFeatureTests { private struct Configuration: Equatable { var checks: Bool var checkInBackground: Bool }
@Test(.dependencies) func applySettingsConfiguresAutomaticChecks() async { let configuration = LockIsolated<Configuration?>(nil) let store = TestStore(initialState: UpdatesFeature.State()) { UpdatesFeature() } withDependencies: { $0.updaterClient.configure = { checks, checkInBackground in configuration.withValue { $0 = Configuration(checks: checks, checkInBackground: checkInBackground) } } }
await store.send(.applySettings(automaticallyChecks: true)) { $0.didConfigureUpdates = true }
#expect(configuration.value == Configuration(checks: true, checkInBackground: true)) }
@Test(.dependencies) func downloadedUpdateEventMarksUpdateReadyToInstall() async { let store = TestStore(initialState: UpdatesFeature.State()) { UpdatesFeature() }
await store.send(.updaterEvent(.downloadedUpdateReadyToInstall(version: "2026.6.6"))) { $0.isUpdateAvailable = true $0.isUpdateReadyToInstall = true $0.availableVersion = "2026.6.6" } }
@Test(.dependencies) func updateButtonInstallsDownloadedUpdateWhenReady() async { let installCount = LockIsolated(0) var state = UpdatesFeature.State() state.isUpdateAvailable = true state.isUpdateReadyToInstall = true state.availableVersion = "2026.6.6" let store = TestStore(initialState: state) { UpdatesFeature() } withDependencies: { $0.updaterClient.installDownloadedUpdate = { installCount.withValue { $0 += 1 } } }
await store.send(.activateUpdateButton) { $0.isUpdateAvailable = false $0.isUpdateReadyToInstall = false $0.availableVersion = nil }
#expect(installCount.value == 1) }
@Test(.dependencies) func updateButtonChecksForUpdatesWhenOnlyAvailable() async { let checkCount = LockIsolated(0) var state = UpdatesFeature.State() state.isUpdateAvailable = true state.availableVersion = "2026.6.6" let store = TestStore(initialState: state) { UpdatesFeature() } withDependencies: { $0.analyticsClient.capture = { _, _ in } $0.updaterClient.checkForUpdates = { checkCount.withValue { $0 += 1 } } }
await store.send(.activateUpdateButton) await store.receive(\.checkForUpdates) { $0.isUpdateAvailable = false $0.availableVersion = nil }
#expect(checkCount.value == 1) }
@Test(.dependencies) func checkForUpdatesInstallsDownloadedUpdateWhenReady() async { let checkCount = LockIsolated(0) let installCount = LockIsolated(0) var state = UpdatesFeature.State() state.isUpdateAvailable = true state.isUpdateReadyToInstall = true state.availableVersion = "2026.6.6" let store = TestStore(initialState: state) { UpdatesFeature() } withDependencies: { $0.analyticsClient.capture = { _, _ in } $0.updaterClient.checkForUpdates = { checkCount.withValue { $0 += 1 } } $0.updaterClient.installDownloadedUpdate = { installCount.withValue { $0 += 1 } } }
await store.send(.checkForUpdates) { $0.isUpdateAvailable = false $0.isUpdateReadyToInstall = false $0.availableVersion = nil }
#expect(checkCount.value == 0) #expect(installCount.value == 1) }}