Skip to content

Commit 21936dc

Browse files
committed
Test adapted environment support in WorkflowHostingControllerTests
1 parent 088f5c3 commit 21936dc

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

WorkflowUI/Tests/WorkflowHostingControllerTests.swift

+16-7
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,12 @@ class WorkflowHostingControllerTests: XCTestCase {
161161
}
162162

163163
func test_environment_bridging() throws {
164-
struct TestKey: ViewEnvironmentKey {
164+
struct WorkflowHostKeyKey: ViewEnvironmentKey {
165165
static var defaultValue: Int = 0
166166
}
167+
struct ScreenKey: ViewEnvironmentKey {
168+
static var defaultValue: Bool = false
169+
}
167170

168171
var changedEnvironments: [ViewEnvironment] = []
169172
let firstWorkflow = EnvironmentObservingWorkflow(
@@ -173,16 +176,20 @@ class WorkflowHostingControllerTests: XCTestCase {
173176
}
174177
)
175178
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 }
178184
)
179185

180186
// Expect a `setNeedsEnvironmentUpdate()` in the `ViewControllerDescription`'s build method and the
181187
// `container`'s initializer.
182188
XCTAssertEqual(changedEnvironments.count, 1)
183189
do {
184190
let environment = try XCTUnwrap(changedEnvironments.last)
185-
XCTAssertEqual(environment[TestKey.self], 1)
191+
XCTAssertEqual(environment[WorkflowHostKeyKey.self], 1)
192+
XCTAssertEqual(environment[ScreenKey.self], true)
186193
}
187194

188195
// Test ancestor propagation
@@ -200,18 +207,20 @@ class WorkflowHostingControllerTests: XCTestCase {
200207
do {
201208
let environment = try XCTUnwrap(changedEnvironments.last)
202209
XCTAssertEqual(environment[AncestorKey.self], "1")
203-
XCTAssertEqual(environment[TestKey.self], 1)
210+
XCTAssertEqual(environment[WorkflowHostKeyKey.self], 1)
211+
XCTAssertEqual(environment[ScreenKey.self], true)
204212
}
205213

206214
// Test an environment update. This does not implicitly trigger an environment update in this VC.
207215
ancestorVC.customizeEnvironment = { $0[AncestorKey.self] = "2" }
208216
// Updating customizeEnvironment on the WorkflowHostingController should trigger an environment update
209-
container.customizeEnvironment = { $0[TestKey.self] = 2 }
217+
container.customizeEnvironment = { $0[WorkflowHostKeyKey.self] = 2 }
210218
XCTAssertEqual(changedEnvironments.count, 3)
211219
do {
212220
let environment = try XCTUnwrap(changedEnvironments.last)
213221
XCTAssertEqual(environment[AncestorKey.self], "2")
214-
XCTAssertEqual(environment[TestKey.self], 2)
222+
XCTAssertEqual(environment[WorkflowHostKeyKey.self], 2)
223+
XCTAssertEqual(environment[ScreenKey.self], true)
215224
}
216225
}
217226
}

0 commit comments

Comments
 (0)