Skip to content

Commit 3473d9b

Browse files
committed
Fix tests in Xcode 14. (#1135)
* Fix tests in Xcode 14. * wip * Update download example with proper cancel button.
1 parent 2058549 commit 3473d9b

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
@@ -36,10 +36,10 @@ enum DownloadComponentAction: Equatable {
3636
case downloadClient(Result<DownloadClient.Action, DownloadClient.Error>)
3737

3838
enum AlertAction: Equatable {
39-
case cancelButtonTapped
4039
case deleteButtonTapped
4140
case dismiss
4241
case nevermindButtonTapped
42+
case stopButtonTapped
4343
}
4444
}
4545

@@ -58,11 +58,6 @@ extension Reducer {
5858
Reducer<DownloadComponentState<ID>, DownloadComponentAction, DownloadComponentEnvironment> {
5959
state, action, environment in
6060
switch action {
61-
case .alert(.cancelButtonTapped):
62-
state.mode = .notDownloaded
63-
state.alert = nil
64-
return .cancel(id: state.id)
65-
6661
case .alert(.deleteButtonTapped):
6762
state.alert = nil
6863
state.mode = .notDownloaded
@@ -73,14 +68,19 @@ extension Reducer {
7368
state.alert = nil
7469
return .none
7570

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

8282
case .downloading:
83-
state.alert = cancelAlert
83+
state.alert = stopAlert
8484
return .none
8585

8686
case .notDownloaded:
@@ -92,7 +92,7 @@ extension Reducer {
9292
.cancellable(id: state.id)
9393

9494
case .startingToDownload:
95-
state.alert = cancelAlert
95+
state.alert = stopAlert
9696
return .none
9797
}
9898

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

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

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

135135
struct DownloadComponent<ID: Equatable>: View {
136136
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
@@ -116,13 +116,13 @@ class ReusableComponentsDownloadComponentTests: XCTestCase {
116116

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

125-
store.send(.alert(.cancelButtonTapped)) {
125+
store.send(.alert(.stopButtonTapped)) {
126126
$0.alert = nil
127127
$0.mode = .notDownloaded
128128
}
@@ -153,9 +153,9 @@ class ReusableComponentsDownloadComponentTests: XCTestCase {
153153

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

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

Tests/ComposableArchitectureTests/EffectTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ final class EffectTests: XCTestCase {
200200
func testTask() {
201201
let expectation = self.expectation(description: "Complete")
202202
var result: Int?
203-
Effect<Int, Never>.task {
203+
Effect<Int, Never>.task { @MainActor in
204204
expectation.fulfill()
205205
return 42
206206
}
@@ -213,7 +213,7 @@ final class EffectTests: XCTestCase {
213213
let expectation = self.expectation(description: "Complete")
214214
struct MyError: Error {}
215215
var result: Error?
216-
let disposable = Effect<Int, Error>.task {
216+
let disposable = Effect<Int, Error>.task { @MainActor in
217217
expectation.fulfill()
218218
throw MyError()
219219
}

0 commit comments

Comments
 (0)