15
15
*/
16
16
17
17
import Workflow
18
+ import XCTest
18
19
19
20
/// A set of expectations for use with the `WorkflowRenderTester`. All of the expectations must be fulfilled
20
21
/// for a `render` test to pass.
@@ -105,8 +106,8 @@ public struct ExpectedWorker {
105
106
}
106
107
107
108
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 ) ?
110
111
}
111
112
112
113
extension ExpectedSideEffect {
@@ -123,15 +124,44 @@ extension ExpectedSideEffect {
123
124
}
124
125
125
126
public struct ExpectedWorkflow {
126
- let workflowType : Any . Type
127
- let key : String
128
127
let rendering : Any
129
128
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
+ }
130
150
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
+ ) {
134
162
self . rendering = rendering
135
163
self . output = output
164
+ self . doesMatch = doesMatch
165
+ self . notFoundAssertion = notFoundAssertion
136
166
}
137
167
}
0 commit comments