Skip to content

Commit 59f5eec

Browse files
authored
Update docs/examples to leverage TestStore.send(\.path) (#2868)
1 parent b070b76 commit 59f5eec

File tree

53 files changed

+316
-191
lines changed

Some content is hidden

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

53 files changed

+316
-191
lines changed

ComposableArchitecture.xcworkspace/contents.xcworkspacedata

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-AlertsAndConfirmationDialogs.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ struct AlertAndConfirmationDialog {
3131
case confirmationDialog(PresentationAction<ConfirmationDialog>)
3232
case confirmationDialogButtonTapped
3333

34+
@CasePathable
3435
enum Alert {
3536
case incrementButtonTapped
3637
}
38+
@CasePathable
3739
enum ConfirmationDialog {
3840
case incrementButtonTapped
3941
case decrementButtonTapped

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-Animations.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct Animations {
3737
case setColor(Color)
3838
case tapped(CGPoint)
3939

40+
@CasePathable
4041
enum Alert: Sendable {
4142
case resetConfirmationButtonTapped
4243
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct DownloadComponent {
1515
case buttonTapped
1616
case downloadClient(Result<DownloadClient.Event, Error>)
1717

18+
@CasePathable
1819
enum Alert {
1920
case deleteButtonTapped
2021
case stopButtonTapped

Examples/CaseStudies/SwiftUICaseStudiesTests/01-GettingStarted-AlertsAndConfirmationDialogsTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ final class AlertsAndConfirmationDialogsTests: XCTestCase {
2424
TextState("This is an alert")
2525
}
2626
}
27-
await store.send(.alert(.presented(.incrementButtonTapped))) {
27+
await store.send(\.alert.incrementButtonTapped) {
2828
$0.alert = AlertState { TextState("Incremented!") }
2929
$0.count = 1
3030
}
31-
await store.send(.alert(.dismiss)) {
31+
await store.send(\.alert.dismiss) {
3232
$0.alert = nil
3333
}
3434
}
@@ -55,7 +55,7 @@ final class AlertsAndConfirmationDialogsTests: XCTestCase {
5555
TextState("This is a confirmation dialog.")
5656
}
5757
}
58-
await store.send(.confirmationDialog(.presented(.incrementButtonTapped))) {
58+
await store.send(\.confirmationDialog.incrementButtonTapped) {
5959
$0.alert = AlertState { TextState("Incremented!") }
6060
$0.confirmationDialog = nil
6161
$0.count = 1

Examples/CaseStudies/SwiftUICaseStudiesTests/01-GettingStarted-AnimationsTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ final class AnimationTests: XCTestCase {
9393
}
9494
}
9595

96-
await store.send(.alert(.presented(.resetConfirmationButtonTapped))) {
96+
await store.send(\.alert.resetConfirmationButtonTapped) {
9797
$0 = Animations.State()
9898
}
9999

Examples/CaseStudies/SwiftUICaseStudiesTests/01-GettingStarted-BindingBasicsTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ final class BindingFormTests: XCTestCase {
1010
BindingForm()
1111
}
1212

13-
await store.send(.set(\.sliderValue, 2)) {
13+
await store.send(\.sliderValue, 2) {
1414
$0.sliderValue = 2
1515
}
16-
await store.send(.set(\.stepCount, 1)) {
16+
await store.send(\.stepCount, 1) {
1717
$0.sliderValue = 1
1818
$0.stepCount = 1
1919
}
20-
await store.send(.set(\.text, "Blob")) {
20+
await store.send(\.text, "Blob") {
2121
$0.text = "Blob"
2222
}
23-
await store.send(.set(\.toggleIsOn, true)) {
23+
await store.send(\.toggleIsOn, true) {
2424
$0.toggleIsOn = true
2525
}
2626
await store.send(.resetButtonTapped) {

Examples/CaseStudies/SwiftUICaseStudiesTests/01-GettingStarted-SharedStateTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ final class SharedStateTests: XCTestCase {
2323
SharedState()
2424
}
2525

26-
await store.send(.counter(.incrementButtonTapped)) {
26+
await store.send(\.counter.incrementButtonTapped) {
2727
$0.counter.stats.increment()
2828
$0.profile.stats.increment()
2929
}
30-
await store.send(.counter(.decrementButtonTapped)) {
30+
await store.send(\.counter.decrementButtonTapped) {
3131
$0.counter.stats.decrement()
3232
$0.profile.stats.decrement()
3333
}
34-
await store.send(.profile(.resetStatsButtonTapped)) {
34+
await store.send(\.profile.resetStatsButtonTapped) {
3535
$0.counter.stats = Stats()
3636
$0.profile.stats = Stats()
3737
}
@@ -42,7 +42,7 @@ final class SharedStateTests: XCTestCase {
4242
SharedState()
4343
}
4444

45-
await store.send(.counter(.isPrimeButtonTapped)) {
45+
await store.send(\.counter.isPrimeButtonTapped) {
4646
$0.counter.alert = AlertState {
4747
TextState("👎 The number 0 is not prime :(")
4848
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class RecursionTests: XCTestCase {
1616
$0.rows.append(Nested.State(id: UUID(0)))
1717
}
1818

19-
await store.send(.rows(.element(id: UUID(0), action: .addRowButtonTapped))) {
19+
await store.send(\.rows[id: UUID(0)].addRowButtonTapped) {
2020
$0.rows[id: UUID(0)]?.rows.append(Nested.State(id: UUID(1)))
2121
}
2222
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ final class ReusableComponentsFavoritingTests: XCTestCase {
3434
)
3535
}
3636

37-
await store.send(.episodes(.element(id: episodes[0].id, action: .favorite(.buttonTapped)))) {
38-
$0.episodes[id: episodes[0].id]?.isFavorite = true
37+
await store.send(\.episodes[id: UUID(0)].favorite.buttonTapped) {
38+
$0.episodes[id: UUID(0)]?.isFavorite = true
3939
}
4040
await clock.advance(by: .seconds(1))
4141
await store.receive(\.episodes[id:episodes[0].id].favorite.response.success)
4242

43-
await store.send(.episodes(.element(id: episodes[1].id, action: .favorite(.buttonTapped)))) {
44-
$0.episodes[id: episodes[1].id]?.isFavorite = true
43+
await store.send(\.episodes[id:episodes[1].id].favorite.buttonTapped) {
44+
$0.episodes[id: UUID(1)]?.isFavorite = true
4545
}
46-
await store.send(.episodes(.element(id: episodes[1].id, action: .favorite(.buttonTapped)))) {
47-
$0.episodes[id: episodes[1].id]?.isFavorite = false
46+
await store.send(\.episodes[id:episodes[1].id].favorite.buttonTapped) {
47+
$0.episodes[id: UUID(1)]?.isFavorite = false
4848
}
4949
await clock.advance(by: .seconds(1))
5050
await store.receive(\.episodes[id:episodes[1].id].favorite.response.success)
@@ -62,19 +62,19 @@ final class ReusableComponentsFavoritingTests: XCTestCase {
6262
Episodes(favorite: { _, _ in throw FavoriteError() })
6363
}
6464

65-
await store.send(.episodes(.element(id: episodes[0].id, action: .favorite(.buttonTapped)))) {
66-
$0.episodes[id: episodes[0].id]?.isFavorite = true
65+
await store.send(\.episodes[id: UUID(0)].favorite.buttonTapped) {
66+
$0.episodes[id: UUID(0)]?.isFavorite = true
6767
}
6868

6969
await store.receive(\.episodes[id:episodes[0].id].favorite.response.failure) {
70-
$0.episodes[id: episodes[0].id]?.alert = AlertState {
70+
$0.episodes[id: UUID(0)]?.alert = AlertState {
7171
TextState("Favoriting failed.")
7272
}
7373
}
7474

75-
await store.send(.episodes(.element(id: episodes[0].id, action: .favorite(.alert(.dismiss))))) {
76-
$0.episodes[id: episodes[0].id]?.alert = nil
77-
$0.episodes[id: episodes[0].id]?.isFavorite = false
75+
await store.send(\.episodes[id: UUID(0)].favorite.alert.dismiss) {
76+
$0.episodes[id: UUID(0)]?.alert = nil
77+
$0.episodes[id: UUID(0)]?.isFavorite = false
7878
}
7979
}
8080
}

0 commit comments

Comments
 (0)