Skip to content

Commit 03c421b

Browse files
committed
WorkflowTesting changes to support GUWT
1 parent cbe26ae commit 03c421b

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

WorkflowTesting/Sources/RenderExpectations.swift

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import Workflow
18+
import XCTest
1819

1920
/// A set of expectations for use with the `WorkflowRenderTester`. All of the expectations must be fulfilled
2021
/// for a `render` test to pass.
@@ -105,8 +106,8 @@ public struct ExpectedWorker {
105106
}
106107

107108
public struct ExpectedSideEffect<WorkflowType: Workflow> {
108-
let key: AnyHashable
109-
let action: ((RenderContext<WorkflowType>) -> Void)?
109+
public let key: AnyHashable
110+
public let action: ((RenderContext<WorkflowType>) -> Void)?
110111
}
111112

112113
extension ExpectedSideEffect {
@@ -123,15 +124,44 @@ extension ExpectedSideEffect {
123124
}
124125

125126
public struct ExpectedWorkflow {
126-
let workflowType: Any.Type
127-
let key: String
128127
let rendering: Any
129128
let output: Any?
129+
let doesMatch: (_ childWorkflow: Any, _ childKey: String) -> Bool
130+
let notFoundAssertion: (_ file: StaticString, _ line: UInt) -> Void
131+
132+
public init<WorkflowType: Workflow>(
133+
type: WorkflowType.Type,
134+
key: String = "",
135+
rendering: WorkflowType.Rendering,
136+
output: WorkflowType.Output? = nil
137+
) {
138+
self.rendering = rendering
139+
self.output = output
140+
141+
self.doesMatch = { child, childKey in
142+
guard child is WorkflowType,
143+
key == childKey
144+
else {
145+
return false
146+
}
147+
148+
return true
149+
}
130150

131-
public init<WorkflowType: Workflow>(type: WorkflowType.Type, key: String = "", rendering: WorkflowType.Rendering, output: WorkflowType.Output? = nil) {
132-
self.workflowType = type
133-
self.key = key
151+
self.notFoundAssertion = { file, line in
152+
XCTFail("Expected child workflow of type: \(type) key: \(key)", file: file, line: line)
153+
}
154+
}
155+
156+
public init(
157+
rendering: Any,
158+
output: Any?,
159+
doesMatch: @escaping (_ childWorkflow: Any, _ childKey: String) -> Bool,
160+
notFoundAssertion: @escaping (_ file: StaticString, _ line: UInt) -> Void
161+
) {
134162
self.rendering = rendering
135163
self.output = output
164+
self.doesMatch = doesMatch
165+
self.notFoundAssertion = notFoundAssertion
136166
}
137167
}

WorkflowTesting/Sources/WorkflowRenderTester.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249

250250
func render<Child, Action>(workflow: Child, key: String, outputMap: @escaping (Child.Output) -> Action) -> Child.Rendering where Child: Workflow, Action: WorkflowAction, RenderTestContext<T>.WorkflowType == Action.WorkflowType {
251251
guard let workflowIndex = expectations.expectedWorkflows.firstIndex(where: { expectedWorkflow -> Bool in
252-
type(of: workflow) == expectedWorkflow.workflowType && key == expectedWorkflow.key
252+
expectedWorkflow.doesMatch(workflow, key)
253253
}) else {
254254
XCTFail("Unexpected child workflow of type \(workflow.self)", file: file, line: line)
255255
fatalError()
@@ -337,7 +337,7 @@
337337

338338
if !expectations.expectedWorkflows.isEmpty {
339339
for expectedWorkflow in expectations.expectedWorkflows {
340-
XCTFail("Expected child workflow of type: \(expectedWorkflow.workflowType) key: \(expectedWorkflow.key)", file: file, line: line)
340+
expectedWorkflow.notFoundAssertion(file, line)
341341
}
342342
}
343343

0 commit comments

Comments
 (0)