Skip to content

Commit

Permalink
Update docs/examples to leverage TestStore.send(\.path) (pointfreec…
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis authored Feb 29, 2024
1 parent b070b76 commit 59f5eec
Show file tree
Hide file tree
Showing 53 changed files with 316 additions and 191 deletions.
3 changes: 3 additions & 0 deletions ComposableArchitecture.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ struct AlertAndConfirmationDialog {
case confirmationDialog(PresentationAction<ConfirmationDialog>)
case confirmationDialogButtonTapped

@CasePathable
enum Alert {
case incrementButtonTapped
}
@CasePathable
enum ConfirmationDialog {
case incrementButtonTapped
case decrementButtonTapped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct Animations {
case setColor(Color)
case tapped(CGPoint)

@CasePathable
enum Alert: Sendable {
case resetConfirmationButtonTapped
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct DownloadComponent {
case buttonTapped
case downloadClient(Result<DownloadClient.Event, Error>)

@CasePathable
enum Alert {
case deleteButtonTapped
case stopButtonTapped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ final class AlertsAndConfirmationDialogsTests: XCTestCase {
TextState("This is an alert")
}
}
await store.send(.alert(.presented(.incrementButtonTapped))) {
await store.send(\.alert.incrementButtonTapped) {
$0.alert = AlertState { TextState("Incremented!") }
$0.count = 1
}
await store.send(.alert(.dismiss)) {
await store.send(\.alert.dismiss) {
$0.alert = nil
}
}
Expand All @@ -55,7 +55,7 @@ final class AlertsAndConfirmationDialogsTests: XCTestCase {
TextState("This is a confirmation dialog.")
}
}
await store.send(.confirmationDialog(.presented(.incrementButtonTapped))) {
await store.send(\.confirmationDialog.incrementButtonTapped) {
$0.alert = AlertState { TextState("Incremented!") }
$0.confirmationDialog = nil
$0.count = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ final class AnimationTests: XCTestCase {
}
}

await store.send(.alert(.presented(.resetConfirmationButtonTapped))) {
await store.send(\.alert.resetConfirmationButtonTapped) {
$0 = Animations.State()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ final class BindingFormTests: XCTestCase {
BindingForm()
}

await store.send(.set(\.sliderValue, 2)) {
await store.send(\.sliderValue, 2) {
$0.sliderValue = 2
}
await store.send(.set(\.stepCount, 1)) {
await store.send(\.stepCount, 1) {
$0.sliderValue = 1
$0.stepCount = 1
}
await store.send(.set(\.text, "Blob")) {
await store.send(\.text, "Blob") {
$0.text = "Blob"
}
await store.send(.set(\.toggleIsOn, true)) {
await store.send(\.toggleIsOn, true) {
$0.toggleIsOn = true
}
await store.send(.resetButtonTapped) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ final class SharedStateTests: XCTestCase {
SharedState()
}

await store.send(.counter(.incrementButtonTapped)) {
await store.send(\.counter.incrementButtonTapped) {
$0.counter.stats.increment()
$0.profile.stats.increment()
}
await store.send(.counter(.decrementButtonTapped)) {
await store.send(\.counter.decrementButtonTapped) {
$0.counter.stats.decrement()
$0.profile.stats.decrement()
}
await store.send(.profile(.resetStatsButtonTapped)) {
await store.send(\.profile.resetStatsButtonTapped) {
$0.counter.stats = Stats()
$0.profile.stats = Stats()
}
Expand All @@ -42,7 +42,7 @@ final class SharedStateTests: XCTestCase {
SharedState()
}

await store.send(.counter(.isPrimeButtonTapped)) {
await store.send(\.counter.isPrimeButtonTapped) {
$0.counter.alert = AlertState {
TextState("👎 The number 0 is not prime :(")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class RecursionTests: XCTestCase {
$0.rows.append(Nested.State(id: UUID(0)))
}

await store.send(.rows(.element(id: UUID(0), action: .addRowButtonTapped))) {
await store.send(\.rows[id: UUID(0)].addRowButtonTapped) {
$0.rows[id: UUID(0)]?.rows.append(Nested.State(id: UUID(1)))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ final class ReusableComponentsFavoritingTests: XCTestCase {
)
}

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

await store.send(.episodes(.element(id: episodes[1].id, action: .favorite(.buttonTapped)))) {
$0.episodes[id: episodes[1].id]?.isFavorite = true
await store.send(\.episodes[id:episodes[1].id].favorite.buttonTapped) {
$0.episodes[id: UUID(1)]?.isFavorite = true
}
await store.send(.episodes(.element(id: episodes[1].id, action: .favorite(.buttonTapped)))) {
$0.episodes[id: episodes[1].id]?.isFavorite = false
await store.send(\.episodes[id:episodes[1].id].favorite.buttonTapped) {
$0.episodes[id: UUID(1)]?.isFavorite = false
}
await clock.advance(by: .seconds(1))
await store.receive(\.episodes[id:episodes[1].id].favorite.response.success)
Expand All @@ -62,19 +62,19 @@ final class ReusableComponentsFavoritingTests: XCTestCase {
Episodes(favorite: { _, _ in throw FavoriteError() })
}

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

await store.receive(\.episodes[id:episodes[0].id].favorite.response.failure) {
$0.episodes[id: episodes[0].id]?.alert = AlertState {
$0.episodes[id: UUID(0)]?.alert = AlertState {
TextState("Favoriting failed.")
}
}

await store.send(.episodes(.element(id: episodes[0].id, action: .favorite(.alert(.dismiss))))) {
$0.episodes[id: episodes[0].id]?.alert = nil
$0.episodes[id: episodes[0].id]?.isFavorite = false
await store.send(\.episodes[id: UUID(0)].favorite.alert.dismiss) {
$0.episodes[id: UUID(0)]?.alert = nil
$0.episodes[id: UUID(0)]?.isFavorite = false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class ReusableComponentsDownloadComponentTests: XCTestCase {
}
}

await store.send(.alert(.presented(.stopButtonTapped))) {
await store.send(\.alert.stopButtonTapped) {
$0.alert = nil
$0.mode = .notDownloaded
}
Expand Down Expand Up @@ -143,7 +143,7 @@ final class ReusableComponentsDownloadComponentTests: XCTestCase {
}
}

await store.send(.alert(.presented(.deleteButtonTapped))) {
await store.send(\.alert.deleteButtonTapped) {
$0.alert = nil
$0.mode = .notDownloaded
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ final class UIKitCaseStudiesTests: XCTestCase {
CounterList()
}

await store.send(.counters(.element(id: firstState.id, action: .incrementButtonTapped))) {
await store.send(\.counters[id: firstState.id].incrementButtonTapped) {
$0.counters[id: firstState.id]?.count = 1
}
await store.send(.counters(.element(id: firstState.id, action: .decrementButtonTapped))) {
await store.send(\.counters[id: firstState.id].decrementButtonTapped) {
$0.counters[id: firstState.id]?.count = 0
}

await store.send(.counters(.element(id: secondState.id, action: .incrementButtonTapped))) {
await store.send(\.counters[id: secondState.id].incrementButtonTapped) {
$0.counters[id: secondState.id]?.count = 1
}
await store.send(.counters(.element(id: secondState.id, action: .decrementButtonTapped))) {
await store.send(\.counters[id: secondState.id].decrementButtonTapped) {
$0.counters[id: secondState.id]?.count = 0
}

await store.send(.counters(.element(id: thirdState.id, action: .incrementButtonTapped))) {
await store.send(\.counters[id: thirdState.id].incrementButtonTapped) {
$0.counters[id: thirdState.id]?.count = 1
}
await store.send(.counters(.element(id: thirdState.id, action: .decrementButtonTapped))) {
await store.send(\.counters[id: thirdState.id].decrementButtonTapped) {
$0.counters[id: thirdState.id]?.count = 0
}
}
Expand Down
1 change: 1 addition & 0 deletions Examples/SyncUps/SyncUps/RecordMeeting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct RecordMeeting {
case speechFailure
case speechResult(SpeechRecognitionResult)

@CasePathable
enum Alert {
case confirmDiscard
case confirmSave
Expand Down
1 change: 1 addition & 0 deletions Examples/SyncUps/SyncUps/SyncUpDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct SyncUpDetail {
case alert(AlertState<Alert>)
case edit(SyncUpForm)

@CasePathable
enum Alert {
case confirmDeletion
case continueWithoutRecording
Expand Down
1 change: 1 addition & 0 deletions Examples/SyncUps/SyncUps/SyncUpsList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct SyncUpsList {
case add(SyncUpForm)
case alert(AlertState<Alert>)

@CasePathable
enum Alert {
case confirmLoadMockData
}
Expand Down
25 changes: 8 additions & 17 deletions Examples/SyncUps/SyncUpsTests/AppFeatureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ final class AppFeatureTests: XCTestCase {
)
}

await store.send(.path(.push(id: 0, state: .detail(SyncUpDetail.State(syncUp: syncUp))))) {
await store.send(\.path.push, (id: 0, .detail(SyncUpDetail.State(syncUp: syncUp)))) {
$0.path[id: 0] = .detail(SyncUpDetail.State(syncUp: syncUp))
}

await store.send(.path(.element(id: 0, action: .detail(.deleteButtonTapped)))) {
await store.send(\.path[id:0].detail.deleteButtonTapped) {
$0.path[id: 0, case: \.detail]?.destination = .alert(.deleteSyncUp)
}

await store.send(
.path(.element(id: 0, action: .detail(.destination(.presented(.alert(.confirmDeletion))))))
) {
await store.send(\.path[id:0].detail.destination.alert.confirmDeletion) {
$0.path[id: 0, case: \.detail]?.destination = nil
}

Expand Down Expand Up @@ -56,29 +54,22 @@ final class AppFeatureTests: XCTestCase {
}
}

await store.send(.path(.push(id: 0, state: .detail(SyncUpDetail.State(syncUp: syncUp))))) {
await store.send(\.path.push, (id: 0, .detail(SyncUpDetail.State(syncUp: syncUp)))) {
$0.path[id: 0] = .detail(SyncUpDetail.State(syncUp: syncUp))
}

await store.send(.path(.element(id: 0, action: .detail(.editButtonTapped)))) {
await store.send(\.path[id:0].detail.editButtonTapped) {
$0.path[id: 0, case: \.detail]?.destination = .edit(
SyncUpForm.State(syncUp: syncUp)
)
}

syncUp.title = "Blob"
await store.send(
.path(
.element(
id: 0,
action: .detail(.destination(.presented(.edit(.set(\.syncUp, syncUp)))))
)
)
) {
await store.send(\.path[id:0].detail.destination.edit.syncUp, syncUp) {
$0.path[id: 0, case: \.detail]?.$destination[case: \.edit]?.syncUp.title = "Blob"
}

await store.send(.path(.element(id: 0, action: .detail(.doneEditingButtonTapped)))) {
await store.send(\.path[id:0].detail.doneEditingButtonTapped) {
$0.path[id: 0, case: \.detail]?.destination = nil
$0.path[id: 0, case: \.detail]?.syncUp.title = "Blob"
}
Expand Down Expand Up @@ -134,7 +125,7 @@ final class AppFeatureTests: XCTestCase {
}
store.exhaustivity = .off

await store.send(.path(.element(id: 1, action: .record(.onTask))))
await store.send(\.path[id:1].record.onTask)
await store.receive(\.path[id:1].record.delegate.save) {
$0.path[id: 0, case: \.detail]?.syncUp.meetings = [
Meeting(
Expand Down
10 changes: 5 additions & 5 deletions Examples/SyncUps/SyncUpsTests/RecordMeetingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ final class RecordMeetingTests: XCTestCase {
await store.receive(\.timerTick)
await store.receive(\.timerTick)

await store.send(.alert(.presented(.confirmSave))) {
await store.send(\.alert.confirmSave) {
$0.alert = nil
}

Expand Down Expand Up @@ -188,7 +188,7 @@ final class RecordMeetingTests: XCTestCase {
$0.alert = .endMeeting(isDiscardable: true)
}

await store.send(.alert(.presented(.confirmDiscard))) {
await store.send(\.alert.confirmDiscard) {
$0.alert = nil
}

Expand Down Expand Up @@ -236,7 +236,7 @@ final class RecordMeetingTests: XCTestCase {
$0.alert = .endMeeting(isDiscardable: false)
}

await store.send(.alert(.presented(.confirmSave))) {
await store.send(\.alert.confirmSave) {
$0.alert = nil
}

Expand Down Expand Up @@ -292,7 +292,7 @@ final class RecordMeetingTests: XCTestCase {
$0.transcript = "I completed the project ❌"
}

await store.send(.alert(.dismiss)) {
await store.send(\.alert.dismiss) {
$0.alert = nil
}

Expand Down Expand Up @@ -336,7 +336,7 @@ final class RecordMeetingTests: XCTestCase {
$0.alert = .speechRecognizerFailed
}

await store.send(.alert(.presented(.confirmDiscard))) {
await store.send(\.alert.confirmDiscard) {
$0.alert = nil
}

Expand Down
8 changes: 4 additions & 4 deletions Examples/SyncUps/SyncUpsTests/SyncUpDetailTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class SyncUpDetailTests: XCTestCase {
$0.speechClient.authorizationStatus = { .denied }
}

await store.send(.destination(.presented(.alert(.openSettings)))) {
await store.send(\.destination.alert.openSettings) {
$0.destination = nil
}
XCTAssertEqual(settingsOpened.value, true)
Expand All @@ -64,7 +64,7 @@ final class SyncUpDetailTests: XCTestCase {
$0.speechClient.authorizationStatus = { .denied }
}

await store.send(.destination(.presented(.alert(.continueWithoutRecording)))) {
await store.send(\.destination.alert.continueWithoutRecording) {
$0.destination = nil
}

Expand Down Expand Up @@ -96,7 +96,7 @@ final class SyncUpDetailTests: XCTestCase {
}

syncUp.title = "Blob's Meeting"
await store.send(.destination(.presented(.edit(.set(\.syncUp, syncUp))))) {
await store.send(\.destination.edit.syncUp, syncUp) {
$0.$destination[case: \.edit]?.syncUp.title = "Blob's Meeting"
}

Expand Down Expand Up @@ -124,7 +124,7 @@ final class SyncUpDetailTests: XCTestCase {
await store.send(.deleteButtonTapped) {
$0.destination = .alert(.deleteSyncUp)
}
await store.send(.destination(.presented(.alert(.confirmDeletion)))) {
await store.send(\.destination.alert.confirmDeletion) {
$0.destination = nil
}
await store.receive(\.delegate.deleteSyncUp)
Expand Down
Loading

0 comments on commit 59f5eec

Please sign in to comment.