From 542fd0377c32b957b5e09bb103a803badf058175 Mon Sep 17 00:00:00 2001 From: Dhaval Shreyas Date: Tue, 25 Aug 2020 15:17:38 -0700 Subject: [PATCH] Fixing RenderTester assert(action:) --- Workflow/Sources/AnyWorkflow.swift | 8 ++++---- Workflow/Sources/AnyWorkflowConvertible.swift | 4 ++-- .../Tests/WorkflowRenderTesterTests.swift | 13 +++++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Workflow/Sources/AnyWorkflow.swift b/Workflow/Sources/AnyWorkflow.swift index 00ee08dc2..a8bf6b9b0 100644 --- a/Workflow/Sources/AnyWorkflow.swift +++ b/Workflow/Sources/AnyWorkflow.swift @@ -74,7 +74,7 @@ extension AnyWorkflow { /// That type information *is* present in our storage object, however, so we /// pass the context down to that storage object which will ultimately call /// through to `context.render(workflow:key:reducer:)`. - internal func render(context: RenderContext, key: String, outputMap: @escaping (Output) -> AnyWorkflowAction) -> Rendering { + internal func render(context: RenderContext, key: String, outputMap: @escaping (Output) -> Action) -> Rendering where Action: WorkflowAction, Action.WorkflowType == Parent { return storage.render(context: context, key: key, outputMap: outputMap) } } @@ -84,7 +84,7 @@ extension AnyWorkflow { /// /// This type is never used directly. fileprivate class AnyStorage { - func render(context: RenderContext, key: String, outputMap: @escaping (Output) -> AnyWorkflowAction) -> Rendering { + func render(context: RenderContext, key: String, outputMap: @escaping (Output) -> Action) -> Rendering where Action: WorkflowAction, Action.WorkflowType == Parent { fatalError() } @@ -119,8 +119,8 @@ extension AnyWorkflow { return T.self } - override func render(context: RenderContext, key: String, outputMap: @escaping (Output) -> AnyWorkflowAction) -> Rendering { - let outputMap: (T.Output) -> AnyWorkflowAction = { [outputTransform] output in + override func render(context: RenderContext, key: String, outputMap: @escaping (Output) -> Action) -> Rendering where Action: WorkflowAction, Action.WorkflowType == Parent { + let outputMap: (T.Output) -> Action = { [outputTransform] output in outputMap(outputTransform(output)) } let rendering = context.render(workflow: workflow, key: key, outputMap: outputMap) diff --git a/Workflow/Sources/AnyWorkflowConvertible.swift b/Workflow/Sources/AnyWorkflowConvertible.swift index 7198f4795..e72a3bc50 100644 --- a/Workflow/Sources/AnyWorkflowConvertible.swift +++ b/Workflow/Sources/AnyWorkflowConvertible.swift @@ -38,11 +38,11 @@ extension AnyWorkflowConvertible { /// /// - Returns: The `Rendering` generated by the workflow. public func rendered(in context: RenderContext, key: String = "") -> Rendering where Output: WorkflowAction, Output.WorkflowType == Parent { - return asAnyWorkflow().render(context: context, key: key, outputMap: { AnyWorkflowAction($0) }) + return asAnyWorkflow().render(context: context, key: key, outputMap: { $0 }) } public func rendered(in context: RenderContext, key: String = "", outputMap: @escaping (Output) -> Action) -> Rendering where Action: WorkflowAction, Action.WorkflowType == Parent { - return asAnyWorkflow().render(context: context, key: key, outputMap: { AnyWorkflowAction(outputMap($0)) }) + return asAnyWorkflow().render(context: context, key: key, outputMap: { outputMap($0) }) } public func rendered(in context: RenderContext, key: String = "") -> Rendering where Output == AnyWorkflowAction { diff --git a/WorkflowTesting/Tests/WorkflowRenderTesterTests.swift b/WorkflowTesting/Tests/WorkflowRenderTesterTests.swift index fcd792b3a..0e11b0ca0 100644 --- a/WorkflowTesting/Tests/WorkflowRenderTesterTests.swift +++ b/WorkflowTesting/Tests/WorkflowRenderTesterTests.swift @@ -98,6 +98,19 @@ final class WorkflowRenderTesterTests: XCTestCase { .assertNoAction() } + func test_childWorkflowAction() { + ParentWorkflow(initialText: "hello") + .renderTester() + .expectWorkflow( + type: ChildWorkflow.self, + producingRendering: "olleh", + producingOutput: ChildWorkflow.Output.success + ) + .render { rendering in + XCTAssertEqual("olleh", rendering) + }.assert(action: ParentWorkflow.Action.childSuccess) + } + func test_childWorkflowOutput() { // Test that a child emitting an output is handled as an action by the parent ParentWorkflow(initialText: "hello")