mirror of
https://github.com/pointfreeco/swift-composable-architecture.git
synced 2025-12-24 12:14:25 +01:00
Update docs/examples to leverage TestStore.send(\.path) (#2868)
This commit is contained in:
@@ -63,7 +63,7 @@ public struct Game: Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
public enum Player: Equatable {
|
||||
public enum Player: Equatable, Sendable {
|
||||
case o
|
||||
case x
|
||||
|
||||
|
||||
@@ -44,3 +44,4 @@ extension Three: RandomAccessCollection {}
|
||||
|
||||
extension Three: Equatable where Element: Equatable {}
|
||||
extension Three: Hashable where Element: Hashable {}
|
||||
extension Three: Sendable where Element: Sendable {}
|
||||
|
||||
@@ -25,6 +25,7 @@ public struct Login: Sendable {
|
||||
|
||||
public enum Alert: Equatable, Sendable {}
|
||||
|
||||
@CasePathable
|
||||
public enum View: BindableAction, Sendable {
|
||||
case binding(BindingAction<State>)
|
||||
case loginButtonTapped
|
||||
|
||||
@@ -25,6 +25,7 @@ public struct TwoFactor: Sendable {
|
||||
|
||||
public enum Alert: Equatable, Sendable {}
|
||||
|
||||
@CasePathable
|
||||
public enum View: BindableAction, Sendable {
|
||||
case binding(BindingAction<State>)
|
||||
case submitButtonTapped
|
||||
|
||||
@@ -17,18 +17,18 @@ final class AppCoreTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
await store.send(.login(.view(.set(\.email, "blob@pointfree.co")))) {
|
||||
await store.send(\.login.view.email, "blob@pointfree.co") {
|
||||
$0.modify(\.login) {
|
||||
$0.email = "blob@pointfree.co"
|
||||
}
|
||||
}
|
||||
await store.send(.login(.view(.set(\.password, "bl0bbl0b")))) {
|
||||
await store.send(\.login.view.password, "bl0bbl0b") {
|
||||
$0.modify(\.login) {
|
||||
$0.password = "bl0bbl0b"
|
||||
$0.isFormValid = true
|
||||
}
|
||||
}
|
||||
await store.send(.login(.view(.loginButtonTapped))) {
|
||||
await store.send(\.login.view.loginButtonTapped) {
|
||||
$0.modify(\.login) {
|
||||
$0.isLoginRequestInFlight = true
|
||||
}
|
||||
@@ -36,12 +36,12 @@ final class AppCoreTests: XCTestCase {
|
||||
await store.receive(\.login.loginResponse.success) {
|
||||
$0 = .newGame(NewGame.State())
|
||||
}
|
||||
await store.send(.newGame(.set(\.oPlayerName, "Blob Sr."))) {
|
||||
await store.send(\.newGame.oPlayerName, "Blob Sr.") {
|
||||
$0.modify(\.newGame) {
|
||||
$0.oPlayerName = "Blob Sr."
|
||||
}
|
||||
}
|
||||
await store.send(.newGame(.logoutButtonTapped)) {
|
||||
await store.send(\.newGame.logoutButtonTapped) {
|
||||
$0 = .login(Login.State())
|
||||
}
|
||||
}
|
||||
@@ -58,20 +58,20 @@ final class AppCoreTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
await store.send(.login(.view(.set(\.email, "blob@pointfree.co")))) {
|
||||
await store.send(\.login.view.email, "blob@pointfree.co") {
|
||||
$0.modify(\.login) {
|
||||
$0.email = "blob@pointfree.co"
|
||||
}
|
||||
}
|
||||
|
||||
await store.send(.login(.view(.set(\.password, "bl0bbl0b")))) {
|
||||
await store.send(\.login.view.password, "bl0bbl0b") {
|
||||
$0.modify(\.login) {
|
||||
$0.password = "bl0bbl0b"
|
||||
$0.isFormValid = true
|
||||
}
|
||||
}
|
||||
|
||||
await store.send(.login(.view(.loginButtonTapped))) {
|
||||
await store.send(\.login.view.loginButtonTapped) {
|
||||
$0.modify(\.login) {
|
||||
$0.isLoginRequestInFlight = true
|
||||
}
|
||||
@@ -83,14 +83,14 @@ final class AppCoreTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
await store.send(.login(.twoFactor(.presented(.view(.set(\.code, "1234")))))) {
|
||||
await store.send(\.login.twoFactor.view.code, "1234") {
|
||||
$0.modify(\.login) {
|
||||
$0.twoFactor?.code = "1234"
|
||||
$0.twoFactor?.isFormValid = true
|
||||
}
|
||||
}
|
||||
|
||||
await store.send(.login(.twoFactor(.presented(.view(.submitButtonTapped))))) {
|
||||
await store.send(\.login.twoFactor.view.submitButtonTapped) {
|
||||
$0.modify(\.login) {
|
||||
$0.twoFactor?.isTwoFactorRequestInFlight = true
|
||||
}
|
||||
|
||||
@@ -18,25 +18,25 @@ final class LoginCoreTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
await store.send(.view(.set(\.email, "2fa@pointfree.co"))) {
|
||||
await store.send(\.view.email, "2fa@pointfree.co") {
|
||||
$0.email = "2fa@pointfree.co"
|
||||
}
|
||||
await store.send(.view(.set(\.password, "password"))) {
|
||||
await store.send(\.view.password, "password") {
|
||||
$0.password = "password"
|
||||
$0.isFormValid = true
|
||||
}
|
||||
let twoFactorPresentationTask = await store.send(.view(.loginButtonTapped)) {
|
||||
let twoFactorPresentationTask = await store.send(\.view.loginButtonTapped) {
|
||||
$0.isLoginRequestInFlight = true
|
||||
}
|
||||
await store.receive(\.loginResponse.success) {
|
||||
$0.isLoginRequestInFlight = false
|
||||
$0.twoFactor = TwoFactor.State(token: "deadbeefdeadbeef")
|
||||
}
|
||||
await store.send(.twoFactor(.presented(.view(.set(\.code, "1234"))))) {
|
||||
await store.send(\.twoFactor.view.code, "1234") {
|
||||
$0.twoFactor?.code = "1234"
|
||||
$0.twoFactor?.isFormValid = true
|
||||
}
|
||||
await store.send(.twoFactor(.presented(.view(.submitButtonTapped)))) {
|
||||
await store.send(\.twoFactor.view.submitButtonTapped) {
|
||||
$0.twoFactor?.isTwoFactorRequestInFlight = true
|
||||
}
|
||||
await store.receive(\.twoFactor.twoFactorResponse.success) {
|
||||
@@ -58,28 +58,28 @@ final class LoginCoreTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
await store.send(.view(.set(\.email, "2fa@pointfree.co"))) {
|
||||
await store.send(\.view.email, "2fa@pointfree.co") {
|
||||
$0.email = "2fa@pointfree.co"
|
||||
}
|
||||
await store.send(.view(.set(\.password, "password"))) {
|
||||
await store.send(\.view.password, "password") {
|
||||
$0.password = "password"
|
||||
$0.isFormValid = true
|
||||
}
|
||||
await store.send(.view(.loginButtonTapped)) {
|
||||
await store.send(\.view.loginButtonTapped) {
|
||||
$0.isLoginRequestInFlight = true
|
||||
}
|
||||
await store.receive(\.loginResponse.success) {
|
||||
$0.isLoginRequestInFlight = false
|
||||
$0.twoFactor = TwoFactor.State(token: "deadbeefdeadbeef")
|
||||
}
|
||||
await store.send(.twoFactor(.presented(.view(.set(\.code, "1234"))))) {
|
||||
await store.send(\.twoFactor.view.code, "1234") {
|
||||
$0.twoFactor?.code = "1234"
|
||||
$0.twoFactor?.isFormValid = true
|
||||
}
|
||||
await store.send(.twoFactor(.presented(.view(.submitButtonTapped)))) {
|
||||
await store.send(\.twoFactor.view.submitButtonTapped) {
|
||||
$0.twoFactor?.isTwoFactorRequestInFlight = true
|
||||
}
|
||||
await store.send(.twoFactor(.dismiss)) {
|
||||
await store.send(\.twoFactor.dismiss) {
|
||||
$0.twoFactor = nil
|
||||
}
|
||||
await store.finish()
|
||||
|
||||
@@ -10,27 +10,27 @@ final class NewGameCoreTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testFlow_NewGame_Integration() async {
|
||||
await self.store.send(.set(\.oPlayerName, "Blob Sr.")) {
|
||||
await self.store.send(\.oPlayerName, "Blob Sr.") {
|
||||
$0.oPlayerName = "Blob Sr."
|
||||
}
|
||||
await self.store.send(.set(\.xPlayerName, "Blob Jr.")) {
|
||||
await self.store.send(\.xPlayerName, "Blob Jr.") {
|
||||
$0.xPlayerName = "Blob Jr."
|
||||
}
|
||||
await self.store.send(.letsPlayButtonTapped) {
|
||||
$0.game = Game.State(oPlayerName: "Blob Sr.", xPlayerName: "Blob Jr.")
|
||||
}
|
||||
await self.store.send(.game(.presented(.cellTapped(row: 0, column: 0)))) {
|
||||
await self.store.send(\.game.cellTapped, (row: 0, column: 0)) {
|
||||
$0.game!.board[0][0] = .x
|
||||
$0.game!.currentPlayer = .o
|
||||
}
|
||||
await self.store.send(.game(.presented(.quitButtonTapped)))
|
||||
await self.store.send(\.game.quitButtonTapped)
|
||||
await self.store.receive(\.game.dismiss) {
|
||||
$0.game = nil
|
||||
}
|
||||
await self.store.send(.letsPlayButtonTapped) {
|
||||
$0.game = Game.State(oPlayerName: "Blob Sr.", xPlayerName: "Blob Jr.")
|
||||
}
|
||||
await self.store.send(.game(.dismiss)) {
|
||||
await self.store.send(\.game.dismiss) {
|
||||
$0.game = nil
|
||||
}
|
||||
await self.store.send(.logoutButtonTapped)
|
||||
|
||||
@@ -14,20 +14,20 @@ final class TwoFactorCoreTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
await store.send(.view(.set(\.code, "1"))) {
|
||||
await store.send(\.view.code, "1") {
|
||||
$0.code = "1"
|
||||
}
|
||||
await store.send(.view(.set(\.code, "12"))) {
|
||||
await store.send(\.view.code, "12") {
|
||||
$0.code = "12"
|
||||
}
|
||||
await store.send(.view(.set(\.code, "123"))) {
|
||||
await store.send(\.view.code, "123") {
|
||||
$0.code = "123"
|
||||
}
|
||||
await store.send(.view(.set(\.code, "1234"))) {
|
||||
await store.send(\.view.code, "1234") {
|
||||
$0.code = "1234"
|
||||
$0.isFormValid = true
|
||||
}
|
||||
await store.send(.view(.submitButtonTapped)) {
|
||||
await store.send(\.view.submitButtonTapped) {
|
||||
$0.isTwoFactorRequestInFlight = true
|
||||
}
|
||||
await store.receive(\.twoFactorResponse.success) {
|
||||
@@ -44,11 +44,11 @@ final class TwoFactorCoreTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
await store.send(.view(.set(\.code, "1234"))) {
|
||||
await store.send(\.view.code, "1234") {
|
||||
$0.code = "1234"
|
||||
$0.isFormValid = true
|
||||
}
|
||||
await store.send(.view(.submitButtonTapped)) {
|
||||
await store.send(\.view.submitButtonTapped) {
|
||||
$0.isTwoFactorRequestInFlight = true
|
||||
}
|
||||
await store.receive(\.twoFactorResponse.failure) {
|
||||
@@ -57,7 +57,7 @@ final class TwoFactorCoreTests: XCTestCase {
|
||||
}
|
||||
$0.isTwoFactorRequestInFlight = false
|
||||
}
|
||||
await store.send(.alert(.dismiss)) {
|
||||
await store.send(\.alert.dismiss) {
|
||||
$0.alert = nil
|
||||
}
|
||||
await store.finish()
|
||||
|
||||
Reference in New Issue
Block a user