Skip to content

Commit 949f919

Browse files
committed
fix more tests
1 parent 5fb03fa commit 949f919

File tree

8 files changed

+59
-58
lines changed

8 files changed

+59
-58
lines changed

Samples/TicTacToe/Tests/AuthenticationWorkflowTests.swift

+22-21
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ class AuthenticationWorkflowTests: XCTestCase {
2727
func test_action_back() {
2828
AuthenticationWorkflow
2929
.Action
30-
.tester(withState: .twoFactor(intermediateSession: "test", authenticationError: nil))
30+
.tester(
31+
workflow: workflow,
32+
state: .twoFactor(intermediateSession: "session", authenticationError: nil)
33+
)
3134
.send(action: .back)
3235
.assert(state: .emailPassword)
3336
}
3437

3538
func test_action_login() {
3639
AuthenticationWorkflow
3740
.Action
38-
.tester(withState: .emailPassword)
41+
.tester(workflow: workflow)
3942
.send(action: .login(email: "[email protected]", password: "password"))
4043
.verifyState { state in
4144
if case .authorizingEmailPassword(let email, let password) = state {
@@ -50,7 +53,7 @@ class AuthenticationWorkflowTests: XCTestCase {
5053
func test_action_verifySecondFactor() {
5154
AuthenticationWorkflow
5255
.Action
53-
.tester(withState: .emailPassword)
56+
.tester(workflow: workflow)
5457
.send(
5558
action: .verifySecondFactor(
5659
intermediateSession: "intermediateSession",
@@ -70,7 +73,7 @@ class AuthenticationWorkflowTests: XCTestCase {
7073
func test_action_authenticationSucceeded() {
7174
AuthenticationWorkflow
7275
.Action
73-
.tester(withState: .emailPassword)
76+
.tester(workflow: workflow)
7477
.send(
7578
action: .authenticationSucceeded(
7679
response: AuthenticationService.AuthenticationResponse(
@@ -90,7 +93,7 @@ class AuthenticationWorkflowTests: XCTestCase {
9093

9194
AuthenticationWorkflow
9295
.Action
93-
.tester(withState: .emailPassword)
96+
.tester(workflow: workflow)
9497
.send(
9598
action: .authenticationSucceeded(
9699
response: AuthenticationService.AuthenticationResponse(
@@ -112,10 +115,8 @@ class AuthenticationWorkflowTests: XCTestCase {
112115
AuthenticationWorkflow
113116
.Action
114117
.tester(
115-
withState: .authorizingEmailPassword(
116-
117-
password: "password"
118-
)
118+
workflow: workflow,
119+
state: .authorizingEmailPassword(email: "[email protected]", password: "password")
119120
)
120121
.send(
121122
action: .authenticationError(AuthenticationService.AuthenticationError.invalidUserPassword)
@@ -136,10 +137,8 @@ class AuthenticationWorkflowTests: XCTestCase {
136137
AuthenticationWorkflow
137138
.Action
138139
.tester(
139-
withState: .authorizingEmailPassword(
140-
141-
password: "password"
142-
)
140+
workflow: workflow,
141+
state: .authorizingEmailPassword(email: "[email protected]", password: "password")
143142
)
144143
.send(
145144
action: .authenticationError(AuthenticationService.AuthenticationError.invalidUserPassword)
@@ -156,10 +155,8 @@ class AuthenticationWorkflowTests: XCTestCase {
156155
AuthenticationWorkflow
157156
.Action
158157
.tester(
159-
withState: .authorizingTwoFactor(
160-
twoFactorCode: "twoFactorCode",
161-
intermediateSession: "intermediateSession"
162-
)
158+
workflow: workflow,
159+
state: .authorizingTwoFactor(twoFactorCode: "123456", intermediateSession: "session")
163160
)
164161
.send(
165162
action: .authenticationError(AuthenticationService.AuthenticationError.invalidTwoFactor)
@@ -178,7 +175,7 @@ class AuthenticationWorkflowTests: XCTestCase {
178175
// MARK: Render Tests
179176

180177
func test_render_initial() {
181-
AuthenticationWorkflow(authenticationService: AuthenticationService())
178+
workflow
182179
.renderTester(initialState: .emailPassword)
183180
.expectWorkflow(
184181
type: LoginWorkflow.self,
@@ -200,7 +197,7 @@ class AuthenticationWorkflowTests: XCTestCase {
200197
func test_render_AuthorizingEmailPasswordWorker() {
201198
let authenticationService = AuthenticationService()
202199

203-
AuthenticationWorkflow(authenticationService: authenticationService)
200+
workflow
204201
.renderTester(
205202
initialState: .authorizingEmailPassword(
206203
@@ -234,7 +231,7 @@ class AuthenticationWorkflowTests: XCTestCase {
234231
func test_render_authorizingTwoFactorWorker() {
235232
let authenticationService = AuthenticationService()
236233

237-
AuthenticationWorkflow(authenticationService: authenticationService)
234+
workflow
238235
.renderTester(
239236
initialState: .authorizingTwoFactor(
240237
twoFactorCode: "twoFactorCode",
@@ -268,7 +265,7 @@ class AuthenticationWorkflowTests: XCTestCase {
268265
func test_render_authenticationErrorAlert() {
269266
let authenticationService = AuthenticationService()
270267

271-
AuthenticationWorkflow(authenticationService: authenticationService)
268+
workflow
272269
.renderTester(
273270
initialState: .authenticationErrorAlert(error: AuthenticationService.AuthenticationError.invalidUserPassword)
274271
)
@@ -288,3 +285,7 @@ class AuthenticationWorkflowTests: XCTestCase {
288285
}
289286
}
290287
}
288+
289+
private let workflow = AuthenticationWorkflow(
290+
authenticationService: AuthenticationService()
291+
)

Samples/TicTacToe/Tests/ConfirmQuitWorkflowTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ class ConfirmQuitWorkflowTests: XCTestCase {
2626
func test_action_cancel() {
2727
ConfirmQuitWorkflow
2828
.Action
29-
.tester(withState: ConfirmQuitWorkflow.State(step: .confirmOnce))
29+
.tester(workflow: ConfirmQuitWorkflow())
3030
.send(action: .cancel)
3131
.assert(output: .cancel)
3232
}
3333

3434
func test_action_quit() {
3535
ConfirmQuitWorkflow
3636
.Action
37-
.tester(withState: ConfirmQuitWorkflow.State(step: .confirmOnce))
37+
.tester(workflow: ConfirmQuitWorkflow())
3838
.send(action: .quit)
3939
.assert(output: .quit)
4040
}
4141

4242
func test_action_confirm() {
4343
ConfirmQuitWorkflow
4444
.Action
45-
.tester(withState: ConfirmQuitWorkflow.State(step: .confirmOnce))
45+
.tester(workflow: ConfirmQuitWorkflow())
4646
.send(action: .confirm)
4747
.verifyState { state in
4848
XCTAssertEqual(state.step, .confirmTwice)

Samples/TicTacToe/Tests/LoginWorkflowTests.swift

+6-12
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ class LoginWorkflowTests: XCTestCase {
2727
LoginWorkflow
2828
.Action
2929
.tester(
30-
withState: LoginWorkflow.State(
31-
32-
password: "password"
33-
)
30+
workflow: LoginWorkflow(),
31+
state: LoginWorkflow.State(email: "[email protected]", password: "password")
3432
)
3533
.send(action: .emailUpdated("[email protected]"))
3634
.assertNoOutput()
@@ -44,10 +42,8 @@ class LoginWorkflowTests: XCTestCase {
4442
LoginWorkflow
4543
.Action
4644
.tester(
47-
withState: LoginWorkflow.State(
48-
49-
password: "password"
50-
)
45+
workflow: LoginWorkflow(),
46+
state: LoginWorkflow.State(email: "[email protected]", password: "password")
5147
)
5248
.send(action: .passwordUpdated("drowssap"))
5349
.assertNoOutput()
@@ -61,10 +57,8 @@ class LoginWorkflowTests: XCTestCase {
6157
LoginWorkflow
6258
.Action
6359
.tester(
64-
withState: LoginWorkflow.State(
65-
66-
password: "password"
67-
)
60+
workflow: LoginWorkflow(),
61+
state: LoginWorkflow.State(email: "[email protected]", password: "password")
6862
)
6963
.send(action: .login)
7064
.verifyOutput { output in

Samples/TicTacToe/Tests/MainWorkflowTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class MainWorkflowTests: XCTestCase {
2828
func test_action_authenticated() {
2929
MainWorkflow
3030
.Action
31-
.tester(withState: .authenticating)
31+
.tester(workflow: MainWorkflow(), state: .authenticating)
3232
.send(action: .authenticated(sessionToken: "token"))
3333
.verifyState { state in
3434
if case MainWorkflow.State.runningGame(let token) = state {
@@ -42,7 +42,7 @@ class MainWorkflowTests: XCTestCase {
4242
func test_action_logout() {
4343
MainWorkflow
4444
.Action
45-
.tester(withState: .runningGame(sessionToken: "token"))
45+
.tester(workflow: MainWorkflow(), state: .runningGame(sessionToken: "token"))
4646
.send(action: .logout)
4747
.assert(state: .authenticating)
4848
}

Samples/TicTacToe/Tests/RunGameWorkflowTests.swift

+4-12
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ class RunGameWorkflowTests: XCTestCase {
2525
// MARK: Action Tests
2626

2727
func test_action_updatePlayers() {
28-
let initalState = RunGameWorkflow.State(playerX: "X", playerO: "O", step: .newGame)
29-
3028
RunGameWorkflow
3129
.Action
32-
.tester(withState: initalState)
30+
.tester(workflow: RunGameWorkflow())
3331
.send(action: .updatePlayerX(""))
3432
.assertNoOutput()
3533
.verifyState { state in
@@ -47,15 +45,9 @@ class RunGameWorkflowTests: XCTestCase {
4745
}
4846

4947
func test_action_startGame() {
50-
let initialState = RunGameWorkflow.State(
51-
playerX: "X",
52-
playerO: "O",
53-
step: .newGame
54-
)
55-
5648
RunGameWorkflow
5749
.Action
58-
.tester(withState: initialState)
50+
.tester(workflow: RunGameWorkflow())
5951
.send(action: .startGame)
6052
.assertNoOutput()
6153
.verifyState { state in
@@ -74,7 +66,7 @@ class RunGameWorkflowTests: XCTestCase {
7466

7567
RunGameWorkflow
7668
.Action
77-
.tester(withState: playingState)
69+
.tester(workflow: RunGameWorkflow(), state: playingState)
7870
.send(action: .back)
7971
.assertNoOutput()
8072
.verifyState { state in
@@ -93,7 +85,7 @@ class RunGameWorkflowTests: XCTestCase {
9385

9486
RunGameWorkflow
9587
.Action
96-
.tester(withState: playingState)
88+
.tester(workflow: RunGameWorkflow(), state: playingState)
9789
.send(action: .confirmQuit)
9890
.assertNoOutput()
9991
.verifyState { state in

Samples/TicTacToe/Tests/TakeTurnsWorkflowTests.swift

+20-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ class TakeTurnsWorkflowTests: XCTestCase {
3838

3939
TakeTurnsWorkflow
4040
.Action
41-
.tester(withState: emptyBoardState)
41+
.tester(
42+
workflow: workflow,
43+
state: emptyBoardState
44+
)
4245
.send(action: .selected(row: 0, col: 0))
4346
// This workflow has no outputs.
4447
.assertNoOutput()
@@ -128,7 +131,10 @@ class TakeTurnsWorkflowTests: XCTestCase {
128131

129132
TakeTurnsWorkflow
130133
.Action
131-
.tester(withState: boardState)
134+
.tester(
135+
workflow: workflow,
136+
state: boardState
137+
)
132138
.send(action: .selected(row: 2, col: 2))
133139
// This workflow has no outputs.
134140
.assertNoOutput()
@@ -176,7 +182,10 @@ class TakeTurnsWorkflowTests: XCTestCase {
176182

177183
TakeTurnsWorkflow
178184
.Action
179-
.tester(withState: boardState)
185+
.tester(
186+
workflow: workflow,
187+
state: boardState
188+
)
180189
.send(action: .selected(row: 1, col: 0))
181190
// This workflow has no outputs.
182191
.assertNoOutput()
@@ -206,7 +215,7 @@ class TakeTurnsWorkflowTests: XCTestCase {
206215
gameState: .ongoing(turn: .x)
207216
)
208217

209-
TakeTurnsWorkflow(playerX: "X", playerO: "O")
218+
workflow
210219
.renderTester(initialState: emptyBoardState)
211220
.render { screen in
212221

@@ -234,7 +243,7 @@ class TakeTurnsWorkflowTests: XCTestCase {
234243
gameState: .ongoing(turn: .x)
235244
)
236245

237-
TakeTurnsWorkflow(playerX: "X", playerO: "O")
246+
workflow
238247
.renderTester(initialState: emptyBoardState)
239248
.render { screen in
240249
// Select a tile
@@ -269,7 +278,7 @@ class TakeTurnsWorkflowTests: XCTestCase {
269278
gameState: .win(.o)
270279
)
271280

272-
TakeTurnsWorkflow(playerX: "X", playerO: "O")
281+
workflow
273282
.renderTester(initialState: boardState)
274283
.render { screen in
275284

@@ -289,3 +298,8 @@ class TakeTurnsWorkflowTests: XCTestCase {
289298
.assertNoAction()
290299
}
291300
}
301+
302+
private let workflow = TakeTurnsWorkflow(
303+
playerX: "X",
304+
playerO: "O"
305+
)

Samples/WorkflowCombineSampleApp/WorkflowCombineSampleAppUnitTests/DemoWorkflowTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DemoWorkflowTests: XCTestCase {
1717

1818
DemoWorkflow
1919
.Action
20-
.tester(withState: .init(date: Date())) // the initial date itself does not matter
20+
.tester(workflow: DemoWorkflow())
2121
.send(action: .init(publishedDate: expectedDate))
2222
.assert(state: .init(date: expectedDate))
2323
}

WorkflowUI/Tests/WorkflowHostingControllerTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ fileprivate struct SubscribingWorkflow: Workflow {
297297
func render(state: State, context: RenderContext<Self>) -> TestScreen {
298298
subscription
299299
.mapOutput { output in
300-
AnyWorkflowAction { state in
300+
AnyWorkflowAction { state, _ in
301301
state = output
302302
return output
303303
}

0 commit comments

Comments
 (0)