Skip to content

Commit 0b65bcf

Browse files
Merge pull request #57 from square/dhaval/workflowAssertActionFix
Fixing RenderTester assert(action:)
2 parents cccd720 + 542fd03 commit 0b65bcf

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

Workflow/Sources/AnyWorkflow.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ extension AnyWorkflow {
7474
/// That type information *is* present in our storage object, however, so we
7575
/// pass the context down to that storage object which will ultimately call
7676
/// through to `context.render(workflow:key:reducer:)`.
77-
internal func render<Parent>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> AnyWorkflowAction<Parent>) -> Rendering {
77+
internal func render<Parent, Action>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> Action) -> Rendering where Action: WorkflowAction, Action.WorkflowType == Parent {
7878
return storage.render(context: context, key: key, outputMap: outputMap)
7979
}
8080
}
@@ -84,7 +84,7 @@ extension AnyWorkflow {
8484
///
8585
/// This type is never used directly.
8686
fileprivate class AnyStorage {
87-
func render<Parent>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> AnyWorkflowAction<Parent>) -> Rendering {
87+
func render<Parent, Action>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> Action) -> Rendering where Action: WorkflowAction, Action.WorkflowType == Parent {
8888
fatalError()
8989
}
9090

@@ -119,8 +119,8 @@ extension AnyWorkflow {
119119
return T.self
120120
}
121121

122-
override func render<Parent>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> AnyWorkflowAction<Parent>) -> Rendering {
123-
let outputMap: (T.Output) -> AnyWorkflowAction<Parent> = { [outputTransform] output in
122+
override func render<Parent, Action>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> Action) -> Rendering where Action: WorkflowAction, Action.WorkflowType == Parent {
123+
let outputMap: (T.Output) -> Action = { [outputTransform] output in
124124
outputMap(outputTransform(output))
125125
}
126126
let rendering = context.render(workflow: workflow, key: key, outputMap: outputMap)

Workflow/Sources/AnyWorkflowConvertible.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ extension AnyWorkflowConvertible {
3838
///
3939
/// - Returns: The `Rendering` generated by the workflow.
4040
public func rendered<Parent>(in context: RenderContext<Parent>, key: String = "") -> Rendering where Output: WorkflowAction, Output.WorkflowType == Parent {
41-
return asAnyWorkflow().render(context: context, key: key, outputMap: { AnyWorkflowAction($0) })
41+
return asAnyWorkflow().render(context: context, key: key, outputMap: { $0 })
4242
}
4343

4444
public func rendered<Parent, Action>(in context: RenderContext<Parent>, key: String = "", outputMap: @escaping (Output) -> Action) -> Rendering where Action: WorkflowAction, Action.WorkflowType == Parent {
45-
return asAnyWorkflow().render(context: context, key: key, outputMap: { AnyWorkflowAction(outputMap($0)) })
45+
return asAnyWorkflow().render(context: context, key: key, outputMap: { outputMap($0) })
4646
}
4747

4848
public func rendered<Parent>(in context: RenderContext<Parent>, key: String = "") -> Rendering where Output == AnyWorkflowAction<Parent> {

WorkflowTesting/Tests/WorkflowRenderTesterTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ final class WorkflowRenderTesterTests: XCTestCase {
9898
.assertNoAction()
9999
}
100100

101+
func test_childWorkflowAction() {
102+
ParentWorkflow(initialText: "hello")
103+
.renderTester()
104+
.expectWorkflow(
105+
type: ChildWorkflow.self,
106+
producingRendering: "olleh",
107+
producingOutput: ChildWorkflow.Output.success
108+
)
109+
.render { rendering in
110+
XCTAssertEqual("olleh", rendering)
111+
}.assert(action: ParentWorkflow.Action.childSuccess)
112+
}
113+
101114
func test_childWorkflowOutput() {
102115
// Test that a child emitting an output is handled as an action by the parent
103116
ParentWorkflow(initialText: "hello")

0 commit comments

Comments
 (0)