Skip to content

WorkflowTesting changes to support GUWT #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions WorkflowTesting/Sources/RenderExpectations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import Workflow
import XCTest

/// A set of expectations for use with the `WorkflowRenderTester`. All of the expectations must be fulfilled
/// for a `render` test to pass.
Expand Down Expand Up @@ -123,15 +124,44 @@ extension ExpectedSideEffect {
}

public struct ExpectedWorkflow {
let workflowType: Any.Type
let key: String
let rendering: Any
let output: Any?
let doesMatch: (_ childWorkflow: Any, _ childKey: String) -> Bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds strange to me. Can we call this matches instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing this one, in favor of #15

let notFoundAssertion: (_ file: StaticString, _ line: UInt) -> Void

public init<WorkflowType: Workflow>(
type: WorkflowType.Type,
key: String = "",
rendering: WorkflowType.Rendering,
output: WorkflowType.Output? = nil
) {
self.rendering = rendering
self.output = output

self.doesMatch = { child, childKey in
guard child is WorkflowType,
key == childKey
else {
return false
}

return true
}

public init<WorkflowType: Workflow>(type: WorkflowType.Type, key: String = "", rendering: WorkflowType.Rendering, output: WorkflowType.Output? = nil) {
self.workflowType = type
self.key = key
self.notFoundAssertion = { file, line in
XCTFail("Expected child workflow of type: \(type) key: \(key)", file: file, line: line)
}
}

public init(
rendering: Any,
output: Any?,
doesMatch: @escaping (_ childWorkflow: Any, _ childKey: String) -> Bool,
notFoundAssertion: @escaping (_ file: StaticString, _ line: UInt) -> Void
) {
self.rendering = rendering
self.output = output
self.doesMatch = doesMatch
self.notFoundAssertion = notFoundAssertion
}
}
4 changes: 2 additions & 2 deletions WorkflowTesting/Sources/WorkflowRenderTester.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@

func render<Child, Action>(workflow: Child, key: String, outputMap: @escaping (Child.Output) -> Action) -> Child.Rendering where Child: Workflow, Action: WorkflowAction, RenderTestContext<T>.WorkflowType == Action.WorkflowType {
guard let workflowIndex = expectations.expectedWorkflows.firstIndex(where: { expectedWorkflow -> Bool in
type(of: workflow) == expectedWorkflow.workflowType && key == expectedWorkflow.key
expectedWorkflow.doesMatch(workflow, key)
}) else {
XCTFail("Unexpected child workflow of type \(workflow.self)", file: file, line: line)
fatalError()
Expand Down Expand Up @@ -337,7 +337,7 @@

if !expectations.expectedWorkflows.isEmpty {
for expectedWorkflow in expectations.expectedWorkflows {
XCTFail("Expected child workflow of type: \(expectedWorkflow.workflowType) key: \(expectedWorkflow.key)", file: file, line: line)
expectedWorkflow.notFoundAssertion(file, line)
}
}

Expand Down