@@ -161,9 +161,12 @@ class WorkflowHostingControllerTests: XCTestCase {
161
161
}
162
162
163
163
func test_environment_bridging( ) throws {
164
- struct TestKey : ViewEnvironmentKey {
164
+ struct WorkflowHostKeyKey : ViewEnvironmentKey {
165
165
static var defaultValue : Int = 0
166
166
}
167
+ struct ScreenKey : ViewEnvironmentKey {
168
+ static var defaultValue : Bool = false
169
+ }
167
170
168
171
var changedEnvironments : [ ViewEnvironment ] = [ ]
169
172
let firstWorkflow = EnvironmentObservingWorkflow (
@@ -173,16 +176,20 @@ class WorkflowHostingControllerTests: XCTestCase {
173
176
}
174
177
)
175
178
let container = WorkflowHostingController (
176
- workflow: firstWorkflow,
177
- customizeEnvironment: { $0 [ TestKey . self] = 1 }
179
+ workflow: firstWorkflow
180
+ . mapRendering {
181
+ $0. adaptedEnvironment ( key: ScreenKey . self, value: true )
182
+ } ,
183
+ customizeEnvironment: { $0 [ WorkflowHostKeyKey . self] = 1 }
178
184
)
179
185
180
186
// Expect a `setNeedsEnvironmentUpdate()` in the `ViewControllerDescription`'s build method and the
181
187
// `container`'s initializer.
182
188
XCTAssertEqual ( changedEnvironments. count, 1 )
183
189
do {
184
190
let environment = try XCTUnwrap ( changedEnvironments. last)
185
- XCTAssertEqual ( environment [ TestKey . self] , 1 )
191
+ XCTAssertEqual ( environment [ WorkflowHostKeyKey . self] , 1 )
192
+ XCTAssertEqual ( environment [ ScreenKey . self] , true )
186
193
}
187
194
188
195
// Test ancestor propagation
@@ -200,18 +207,20 @@ class WorkflowHostingControllerTests: XCTestCase {
200
207
do {
201
208
let environment = try XCTUnwrap ( changedEnvironments. last)
202
209
XCTAssertEqual ( environment [ AncestorKey . self] , " 1 " )
203
- XCTAssertEqual ( environment [ TestKey . self] , 1 )
210
+ XCTAssertEqual ( environment [ WorkflowHostKeyKey . self] , 1 )
211
+ XCTAssertEqual ( environment [ ScreenKey . self] , true )
204
212
}
205
213
206
214
// Test an environment update. This does not implicitly trigger an environment update in this VC.
207
215
ancestorVC. customizeEnvironment = { $0 [ AncestorKey . self] = " 2 " }
208
216
// Updating customizeEnvironment on the WorkflowHostingController should trigger an environment update
209
- container. customizeEnvironment = { $0 [ TestKey . self] = 2 }
217
+ container. customizeEnvironment = { $0 [ WorkflowHostKeyKey . self] = 2 }
210
218
XCTAssertEqual ( changedEnvironments. count, 3 )
211
219
do {
212
220
let environment = try XCTUnwrap ( changedEnvironments. last)
213
221
XCTAssertEqual ( environment [ AncestorKey . self] , " 2 " )
214
- XCTAssertEqual ( environment [ TestKey . self] , 2 )
222
+ XCTAssertEqual ( environment [ WorkflowHostKeyKey . self] , 2 )
223
+ XCTAssertEqual ( environment [ ScreenKey . self] , true )
215
224
}
216
225
}
217
226
}
0 commit comments