Skip to content

Commit 705ee6e

Browse files
authored
Merge pull request #3 from trading-point/michael/fix-examples
Fix all remaining projects and tests
2 parents 97ea705 + 35f8a10 commit 705ee6e

File tree

55 files changed

+377
-339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+377
-339
lines changed

Examples/CaseStudies/SwiftUICaseStudiesTests/02-Effects-BasicsTests.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import ComposableArchitecture
2+
import ReactiveSwift
23
import XCTest
34

45
@testable import SwiftUICaseStudies
56

67
class EffectsBasicsTests: XCTestCase {
7-
let scheduler = DispatchQueue.testScheduler
8+
let scheduler = TestScheduler()
89

910
func testCountDown() {
1011
let store = TestStore(
1112
initialState: EffectsBasicsState(),
1213
reducer: effectsBasicsReducer,
1314
environment: EffectsBasicsEnvironment(
14-
mainQueue: self.scheduler.eraseToAnyScheduler(),
15+
mainQueue: self.scheduler,
1516
numberFact: { _ in fatalError("Unimplemented") }
1617
)
1718
)
@@ -23,7 +24,7 @@ class EffectsBasicsTests: XCTestCase {
2324
.send(.decrementButtonTapped) {
2425
$0.count = 0
2526
},
26-
.do { self.scheduler.advance(by: 1) },
27+
.do { self.scheduler.advance(by: .seconds(1)) },
2728
.receive(.incrementButtonTapped) {
2829
$0.count = 1
2930
}
@@ -35,7 +36,7 @@ class EffectsBasicsTests: XCTestCase {
3536
initialState: EffectsBasicsState(),
3637
reducer: effectsBasicsReducer,
3738
environment: EffectsBasicsEnvironment(
38-
mainQueue: self.scheduler.eraseToAnyScheduler(),
39+
mainQueue: self.scheduler,
3940
numberFact: { n in Effect(value: "\(n) is a good number Brent") }
4041
)
4142
)

Examples/CaseStudies/SwiftUICaseStudiesTests/02-Effects-CancellationTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import Combine
21
import ComposableArchitecture
2+
import ReactiveSwift
33
import XCTest
44

55
@testable import SwiftUICaseStudies
66

77
class EffectsCancellationTests: XCTestCase {
8-
let scheduler = DispatchQueue.testScheduler
8+
let scheduler = TestScheduler()
99

1010
func testTrivia_SuccessfulRequest() throws {
1111
let store = TestStore(
1212
initialState: .init(),
1313
reducer: effectsCancellationReducer,
1414
environment: .init(
15-
mainQueue: self.scheduler.eraseToAnyScheduler(),
15+
mainQueue: self.scheduler,
1616
trivia: { n in Effect(value: "\(n) is a good number Brent") }
1717
)
1818
)
@@ -42,8 +42,8 @@ class EffectsCancellationTests: XCTestCase {
4242
initialState: .init(),
4343
reducer: effectsCancellationReducer,
4444
environment: .init(
45-
mainQueue: self.scheduler.eraseToAnyScheduler(),
46-
trivia: { _ in Fail(error: TriviaApiError()).eraseToEffect() }
45+
mainQueue: self.scheduler,
46+
trivia: { _ in Effect(error: TriviaApiError()) }
4747
)
4848
)
4949

@@ -71,7 +71,7 @@ class EffectsCancellationTests: XCTestCase {
7171
initialState: .init(),
7272
reducer: effectsCancellationReducer,
7373
environment: .init(
74-
mainQueue: self.scheduler.eraseToAnyScheduler(),
74+
mainQueue: self.scheduler,
7575
trivia: { n in Effect(value: "\(n) is a good number Brent") }
7676
)
7777
)
@@ -94,7 +94,7 @@ class EffectsCancellationTests: XCTestCase {
9494
initialState: .init(),
9595
reducer: effectsCancellationReducer,
9696
environment: .init(
97-
mainQueue: self.scheduler.eraseToAnyScheduler(),
97+
mainQueue: self.scheduler,
9898
trivia: { n in Effect(value: "\(n) is a good number Brent") }
9999
)
100100
)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import Combine
21
import ComposableArchitecture
2+
import ReactiveSwift
33
import XCTest
44

55
@testable import SwiftUICaseStudies
66

77
class LongLivingEffectsTests: XCTestCase {
88
func testReducer() {
99
// A passthrough subject to simulate the screenshot notification
10-
let screenshotTaken = PassthroughSubject<Void, Never>()
10+
let screenshotTaken = Signal<Void, Never>.pipe()
1111

1212
let store = TestStore(
1313
initialState: .init(),
1414
reducer: longLivingEffectsReducer,
1515
environment: .init(
16-
userDidTakeScreenshot: Effect(screenshotTaken)
16+
userDidTakeScreenshot: screenshotTaken.output.producer
1717
)
1818
)
1919

2020
store.assert(
2121
.send(.onAppear),
2222

2323
// Simulate a screenshot being taken
24-
.do { screenshotTaken.send() },
24+
.do { screenshotTaken.input.send(value: ()) },
2525
.receive(.userDidTakeScreenshotNotification) {
2626
$0.screenshotCount = 1
2727
},
@@ -30,7 +30,7 @@ class LongLivingEffectsTests: XCTestCase {
3030

3131
// Simulate a screenshot being taken to show not effects
3232
// are executed.
33-
.do { screenshotTaken.send() }
33+
.do { screenshotTaken.input.send(value: ()) }
3434
)
3535
}
3636
}

Examples/CaseStudies/SwiftUICaseStudiesTests/02-Effects-TimersTests.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
import ComposableArchitecture
2+
import ReactiveSwift
23
import XCTest
34

45
@testable import SwiftUICaseStudies
56

67
class TimersTests: XCTestCase {
7-
let scheduler = DispatchQueue.testScheduler
8+
let scheduler = TestScheduler()
89

910
func testStart() {
1011
let store = TestStore(
1112
initialState: TimersState(),
1213
reducer: timersReducer,
1314
environment: TimersEnvironment(
14-
mainQueue: self.scheduler.eraseToAnyScheduler()
15+
mainQueue: self.scheduler
1516
)
1617
)
1718

1819
store.assert(
1920
.send(.toggleTimerButtonTapped) {
2021
$0.isTimerActive = true
2122
},
22-
.do { self.scheduler.advance(by: 1) },
23+
.do { self.scheduler.advance(by: .seconds(1)) },
2324
.receive(.timerTicked) {
2425
$0.secondsElapsed = 1
2526
},
26-
.do { self.scheduler.advance(by: 5) },
27+
.do { self.scheduler.advance(by: .seconds(5)) },
2728
.receive(.timerTicked) {
2829
$0.secondsElapsed = 2
2930
},

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

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import Combine
21
import ComposableArchitecture
2+
import ReactiveSwift
33
import XCTest
44

55
@testable import SwiftUICaseStudies
66

77
class ReusableComponentsDownloadComponentTests: XCTestCase {
8-
let downloadSubject = PassthroughSubject<DownloadClient.Action, DownloadClient.Error>()
8+
let downloadSubject = Signal<DownloadClient.Action, DownloadClient.Error>.pipe()
99
let reducer = Reducer<
1010
DownloadComponentState<Int>, DownloadComponentAction, DownloadComponentEnvironment
1111
>
@@ -15,7 +15,7 @@ class ReusableComponentsDownloadComponentTests: XCTestCase {
1515
action: .self,
1616
environment: { $0 }
1717
)
18-
let scheduler = DispatchQueue.testScheduler
18+
let scheduler = TestScheduler()
1919

2020
func testDownloadFlow() {
2121
let store = TestStore(
@@ -28,9 +28,9 @@ class ReusableComponentsDownloadComponentTests: XCTestCase {
2828
reducer: reducer,
2929
environment: DownloadComponentEnvironment(
3030
downloadClient: .mock(
31-
download: { _, _ in self.downloadSubject.eraseToEffect() }
31+
download: { _, _ in self.downloadSubject.output.producer }
3232
),
33-
mainQueue: self.scheduler.eraseToAnyScheduler()
33+
mainQueue: self.scheduler
3434
)
3535
)
3636

@@ -39,18 +39,20 @@ class ReusableComponentsDownloadComponentTests: XCTestCase {
3939
$0.mode = .startingToDownload
4040
},
4141

42-
.do { self.downloadSubject.send(.updateProgress(0.2)) },
42+
.do { self.downloadSubject.input.send(value: .updateProgress(0.2)) },
4343
.do { self.scheduler.advance() },
4444
.receive(.downloadClient(.success(.updateProgress(0.2)))) {
4545
$0.mode = .downloading(progress: 0.2)
4646
},
4747

48-
.do { self.downloadSubject.send(.response(Data())) },
49-
.do { self.downloadSubject.send(completion: .finished) },
50-
.do { self.scheduler.advance(by: 1) },
48+
.do { self.downloadSubject.input.send(value: .response(Data())) },
49+
.do { self.scheduler.advance(by: .seconds(1)) },
5150
.receive(.downloadClient(.success(.response(Data())))) {
5251
$0.mode = .downloaded
53-
}
52+
},
53+
54+
.do { self.downloadSubject.input.sendCompleted() },
55+
.do { self.scheduler.run() }
5456
)
5557
}
5658

@@ -65,9 +67,9 @@ class ReusableComponentsDownloadComponentTests: XCTestCase {
6567
reducer: reducer,
6668
environment: DownloadComponentEnvironment(
6769
downloadClient: .mock(
68-
download: { _, _ in self.downloadSubject.eraseToEffect() }
70+
download: { _, _ in self.downloadSubject.output.producer }
6971
),
70-
mainQueue: self.scheduler.eraseToAnyScheduler()
72+
mainQueue: self.scheduler
7173
)
7274
)
7375

@@ -76,22 +78,22 @@ class ReusableComponentsDownloadComponentTests: XCTestCase {
7678
$0.mode = .startingToDownload
7779
},
7880

79-
.do { self.downloadSubject.send(.updateProgress(0.5)) },
81+
.do { self.downloadSubject.input.send(value: .updateProgress(0.5)) },
8082
.do { self.scheduler.advance() },
8183
.receive(.downloadClient(.success(.updateProgress(0.5)))) {
8284
$0.mode = .downloading(progress: 0.5)
8385
},
8486

85-
.do { self.downloadSubject.send(.updateProgress(0.6)) },
86-
.do { self.scheduler.advance(by: 0.5) },
87+
.do { self.downloadSubject.input.send(value: .updateProgress(0.6)) },
88+
.do { self.scheduler.advance(by: .milliseconds(500)) },
8789

88-
.do { self.downloadSubject.send(.updateProgress(0.7)) },
89-
.do { self.scheduler.advance(by: 0.5) },
90+
.do { self.downloadSubject.input.send(value: .updateProgress(0.7)) },
91+
.do { self.scheduler.advance(by: .milliseconds(500)) },
9092
.receive(.downloadClient(.success(.updateProgress(0.7)))) {
9193
$0.mode = .downloading(progress: 0.7)
9294
},
9395

94-
.do { self.downloadSubject.send(completion: .finished) },
96+
.do { self.downloadSubject.input.sendCompleted() },
9597
.do { self.scheduler.run() }
9698
)
9799
}
@@ -107,10 +109,10 @@ class ReusableComponentsDownloadComponentTests: XCTestCase {
107109
reducer: reducer,
108110
environment: DownloadComponentEnvironment(
109111
downloadClient: .mock(
110-
cancel: { _ in .fireAndForget { self.downloadSubject.send(completion: .finished) } },
111-
download: { _, _ in self.downloadSubject.eraseToEffect() }
112+
cancel: { _ in .fireAndForget { self.downloadSubject.input.sendCompleted() } },
113+
download: { _, _ in self.downloadSubject.output.producer }
112114
),
113-
mainQueue: self.scheduler.eraseToAnyScheduler()
115+
mainQueue: self.scheduler
114116
)
115117
)
116118

@@ -151,10 +153,10 @@ class ReusableComponentsDownloadComponentTests: XCTestCase {
151153
reducer: reducer,
152154
environment: DownloadComponentEnvironment(
153155
downloadClient: .mock(
154-
cancel: { _ in .fireAndForget { self.downloadSubject.send(completion: .finished) } },
155-
download: { _, _ in self.downloadSubject.eraseToEffect() }
156+
cancel: { _ in .fireAndForget { self.downloadSubject.input.sendCompleted() } },
157+
download: { _, _ in self.downloadSubject.output.producer }
156158
),
157-
mainQueue: self.scheduler.eraseToAnyScheduler()
159+
mainQueue: self.scheduler
158160
)
159161
)
160162

@@ -175,13 +177,15 @@ class ReusableComponentsDownloadComponentTests: XCTestCase {
175177
)
176178
},
177179

178-
.do { self.downloadSubject.send(.response(Data())) },
179-
.do { self.downloadSubject.send(completion: .finished) },
180-
.do { self.scheduler.advance(by: 1) },
180+
.do { self.downloadSubject.input.send(value: .response(Data())) },
181+
.do { self.scheduler.advance(by: .seconds(1)) },
181182
.receive(.downloadClient(.success(.response(Data())))) {
182183
$0.alert = nil
183184
$0.mode = .downloaded
184-
}
185+
},
186+
187+
.do { self.downloadSubject.input.sendCompleted() },
188+
.do { self.scheduler.run() }
185189
)
186190
}
187191

@@ -196,10 +200,10 @@ class ReusableComponentsDownloadComponentTests: XCTestCase {
196200
reducer: reducer,
197201
environment: DownloadComponentEnvironment(
198202
downloadClient: .mock(
199-
cancel: { _ in .fireAndForget { self.downloadSubject.send(completion: .finished) } },
200-
download: { _, _ in self.downloadSubject.eraseToEffect() }
203+
cancel: { _ in .fireAndForget { self.downloadSubject.input.sendCompleted() } },
204+
download: { _, _ in self.downloadSubject.output.producer }
201205
),
202-
mainQueue: self.scheduler.eraseToAnyScheduler()
206+
mainQueue: self.scheduler
203207
)
204208
)
205209

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import Combine
21
import ComposableArchitecture
2+
import ReactiveSwift
33
import XCTest
44

55
@testable import SwiftUICaseStudies
66

77
class ReusableComponentsFavoritingTests: XCTestCase {
8-
let scheduler = DispatchQueue.testScheduler
8+
let scheduler = TestScheduler()
99

1010
func testFavoriteButton() {
1111
let store = TestStore(
@@ -31,7 +31,7 @@ class ReusableComponentsFavoritingTests: XCTestCase {
3131
reducer: episodesReducer,
3232
environment: EpisodesEnvironment(
3333
favorite: { _, isFavorite in Effect.future { $0(.success(isFavorite)) } },
34-
mainQueue: self.scheduler.eraseToAnyScheduler()
34+
mainQueue: self.scheduler
3535
)
3636
)
3737

0 commit comments

Comments
 (0)