Skip to content

Commit

Permalink
Merge pull request #57 from square/dhaval/workflowAssertActionFix
Browse files Browse the repository at this point in the history
Fixing RenderTester assert(action:)
  • Loading branch information
dhavalshreyas authored Aug 25, 2020
2 parents cccd720 + 542fd03 commit 0b65bcf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Workflow/Sources/AnyWorkflow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Parent>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> AnyWorkflowAction<Parent>) -> Rendering {
internal func render<Parent, Action>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> Action) -> Rendering where Action: WorkflowAction, Action.WorkflowType == Parent {
return storage.render(context: context, key: key, outputMap: outputMap)
}
}
Expand All @@ -84,7 +84,7 @@ extension AnyWorkflow {
///
/// This type is never used directly.
fileprivate class AnyStorage {
func render<Parent>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> AnyWorkflowAction<Parent>) -> Rendering {
func render<Parent, Action>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> Action) -> Rendering where Action: WorkflowAction, Action.WorkflowType == Parent {
fatalError()
}

Expand Down Expand Up @@ -119,8 +119,8 @@ extension AnyWorkflow {
return T.self
}

override func render<Parent>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> AnyWorkflowAction<Parent>) -> Rendering {
let outputMap: (T.Output) -> AnyWorkflowAction<Parent> = { [outputTransform] output in
override func render<Parent, Action>(context: RenderContext<Parent>, 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)
Expand Down
4 changes: 2 additions & 2 deletions Workflow/Sources/AnyWorkflowConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ extension AnyWorkflowConvertible {
///
/// - Returns: The `Rendering` generated by the workflow.
public func rendered<Parent>(in context: RenderContext<Parent>, 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<Parent, Action>(in context: RenderContext<Parent>, 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<Parent>(in context: RenderContext<Parent>, key: String = "") -> Rendering where Output == AnyWorkflowAction<Parent> {
Expand Down
13 changes: 13 additions & 0 deletions WorkflowTesting/Tests/WorkflowRenderTesterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 0b65bcf

Please sign in to comment.