Update docs/examples to leverage TestStore.send(\.path) (#2868)

This commit is contained in:
Stephen Celis
2024-02-28 17:57:35 -08:00
committed by GitHub
parent b070b765e1
commit 59f5eec0ff
53 changed files with 316 additions and 191 deletions

View File

@@ -27,6 +27,7 @@ struct RecordMeeting {
case speechFailure
case speechResult(SpeechRecognitionResult)
@CasePathable
enum Alert {
case confirmDiscard
case confirmSave

View File

@@ -8,6 +8,7 @@ struct SyncUpDetail {
case alert(AlertState<Alert>)
case edit(SyncUpForm)
@CasePathable
enum Alert {
case confirmDeletion
case continueWithoutRecording

View File

@@ -8,6 +8,7 @@ struct SyncUpsList {
case add(SyncUpForm)
case alert(AlertState<Alert>)
@CasePathable
enum Alert {
case confirmLoadMockData
}

View File

@@ -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
}
@@ -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"
}
@@ -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(

View File

@@ -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
}
@@ -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
}
@@ -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
}
@@ -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
}
@@ -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
}

View File

@@ -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)
@@ -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
}
@@ -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"
}
@@ -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)

View File

@@ -25,7 +25,7 @@ final class SyncUpsListTests: XCTestCase {
}
syncUp.title = "Engineering"
await store.send(.destination(.presented(.add(.set(\.syncUp, syncUp))))) {
await store.send(\.destination.add.syncUp, syncUp) {
$0.$destination[case: \.add]?.syncUp.title = "Engineering"
}
@@ -87,7 +87,7 @@ final class SyncUpsListTests: XCTestCase {
XCTAssertEqual(store.state.destination, .alert(.dataFailedToLoad))
await store.send(.destination(.presented(.alert(.confirmLoadMockData)))) {
await store.send(\.destination.alert.confirmLoadMockData) {
$0.destination = nil
$0.syncUps = [
.mock,