Skip to content

Commit 2bedb4b

Browse files
authored
Fix tests in Xcode 14. (pointfreeco#1135)
* Fix tests in Xcode 14. * wip * Update download example with proper cancel button.
1 parent 192dadd commit 2bedb4b

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

Examples/CaseStudies/SwiftUICaseStudies/04-HigherOrderReducers-ResuableOfflineDownloads/DownloadComponent.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ enum DownloadComponentAction: Equatable {
3535
case downloadClient(Result<DownloadClient.Action, DownloadClient.Error>)
3636

3737
enum AlertAction: Equatable {
38-
case cancelButtonTapped
3938
case deleteButtonTapped
4039
case dismiss
4140
case nevermindButtonTapped
41+
case stopButtonTapped
4242
}
4343
}
4444

@@ -57,11 +57,6 @@ extension Reducer {
5757
Reducer<DownloadComponentState<ID>, DownloadComponentAction, DownloadComponentEnvironment> {
5858
state, action, environment in
5959
switch action {
60-
case .alert(.cancelButtonTapped):
61-
state.mode = .notDownloaded
62-
state.alert = nil
63-
return .cancel(id: state.id)
64-
6560
case .alert(.deleteButtonTapped):
6661
state.alert = nil
6762
state.mode = .notDownloaded
@@ -72,14 +67,19 @@ extension Reducer {
7267
state.alert = nil
7368
return .none
7469

70+
case .alert(.stopButtonTapped):
71+
state.mode = .notDownloaded
72+
state.alert = nil
73+
return .cancel(id: state.id)
74+
7575
case .buttonTapped:
7676
switch state.mode {
7777
case .downloaded:
7878
state.alert = deleteAlert
7979
return .none
8080

8181
case .downloading:
82-
state.alert = cancelAlert
82+
state.alert = stopAlert
8383
return .none
8484

8585
case .notDownloaded:
@@ -91,7 +91,7 @@ extension Reducer {
9191
.cancellable(id: state.id)
9292

9393
case .startingToDownload:
94-
state.alert = cancelAlert
94+
state.alert = stopAlert
9595
return .none
9696
}
9797

@@ -122,14 +122,14 @@ private let deleteAlert = AlertState(
122122
secondaryButton: nevermindButton
123123
)
124124

125-
private let cancelAlert = AlertState(
126-
title: .init("Do you want to cancel downloading this map?"),
127-
primaryButton: .destructive(.init("Cancel"), action: .send(.cancelButtonTapped)),
125+
private let stopAlert = AlertState(
126+
title: .init("Do you want to stop downloading this map?"),
127+
primaryButton: .destructive(.init("Stop"), action: .send(.stopButtonTapped)),
128128
secondaryButton: nevermindButton
129129
)
130130

131131
let nevermindButton = AlertState<DownloadComponentAction.AlertAction>.Button
132-
.default(.init("Nevermind"), action: .send(.nevermindButtonTapped))
132+
.cancel(.init("Nevermind"), action: .send(.nevermindButtonTapped))
133133

134134
struct DownloadComponent<ID: Equatable>: View {
135135
let store: Store<DownloadComponentState<ID>, DownloadComponentAction>

Examples/CaseStudies/SwiftUICaseStudiesTests/04-HigherOrderReducers-ReusableOfflineDownloadsTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ class ReusableComponentsDownloadComponentTests: XCTestCase {
115115

116116
store.send(.buttonTapped) {
117117
$0.alert = .init(
118-
title: .init("Do you want to cancel downloading this map?"),
119-
primaryButton: .destructive(.init("Cancel"), action: .send(.cancelButtonTapped)),
120-
secondaryButton: .default(.init("Nevermind"), action: .send(.nevermindButtonTapped))
118+
title: .init("Do you want to stop downloading this map?"),
119+
primaryButton: .destructive(.init("Stop"), action: .send(.stopButtonTapped)),
120+
secondaryButton: .cancel(.init("Nevermind"), action: .send(.nevermindButtonTapped))
121121
)
122122
}
123123

124-
store.send(.alert(.cancelButtonTapped)) {
124+
store.send(.alert(.stopButtonTapped)) {
125125
$0.alert = nil
126126
$0.mode = .notDownloaded
127127
}
@@ -152,9 +152,9 @@ class ReusableComponentsDownloadComponentTests: XCTestCase {
152152

153153
store.send(.buttonTapped) {
154154
$0.alert = .init(
155-
title: .init("Do you want to cancel downloading this map?"),
156-
primaryButton: .destructive(.init("Cancel"), action: .send(.cancelButtonTapped)),
157-
secondaryButton: .default(.init("Nevermind"), action: .send(.nevermindButtonTapped))
155+
title: .init("Do you want to stop downloading this map?"),
156+
primaryButton: .destructive(.init("Stop"), action: .send(.stopButtonTapped)),
157+
secondaryButton: .cancel(.init("Nevermind"), action: .send(.nevermindButtonTapped))
158158
)
159159
}
160160

@@ -188,7 +188,7 @@ class ReusableComponentsDownloadComponentTests: XCTestCase {
188188
$0.alert = .init(
189189
title: .init("Do you want to delete this map from your offline storage?"),
190190
primaryButton: .destructive(.init("Delete"), action: .send(.deleteButtonTapped)),
191-
secondaryButton: .default(.init("Nevermind"), action: .send(.nevermindButtonTapped))
191+
secondaryButton: .cancel(.init("Nevermind"), action: .send(.nevermindButtonTapped))
192192
)
193193
}
194194

Tests/ComposableArchitectureTests/EffectTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ final class EffectTests: XCTestCase {
228228
func testTask() {
229229
let expectation = self.expectation(description: "Complete")
230230
var result: Int?
231-
Effect<Int, Never>.task {
231+
Effect<Int, Never>.task { @MainActor in
232232
expectation.fulfill()
233233
return 42
234234
}
@@ -242,7 +242,7 @@ final class EffectTests: XCTestCase {
242242
let expectation = self.expectation(description: "Complete")
243243
struct MyError: Error {}
244244
var result: Error?
245-
Effect<Int, Error>.task {
245+
Effect<Int, Error>.task { @MainActor in
246246
expectation.fulfill()
247247
throw MyError()
248248
}

0 commit comments

Comments
 (0)