Skip to content

Commit

Permalink
make WorkflowTesting compile
Browse files Browse the repository at this point in the history
  • Loading branch information
square-tomb committed Dec 15, 2023
1 parent c98e54a commit c9fcd66
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion WorkflowTesting/Sources/Internal/AppliedAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import XCTest
struct AppliedAction<WorkflowType: Workflow> {
let erasedAction: Any

init<ActionType: WorkflowAction>(_ action: ActionType) where ActionType.WorkflowType == WorkflowType {
init<ActionType: WorkflowActionCore>(_ action: ActionType) where ActionType.WorkflowType == WorkflowType {
self.erasedAction = action
}

Expand Down
11 changes: 7 additions & 4 deletions WorkflowTesting/Sources/Internal/RenderTester+TestContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,26 @@ extension RenderTester {
let file: StaticString
let line: UInt

private let workflow: WorkflowType
private var usedWorkflowKeys: Set<WorkflowKey> = []

internal init(
workflow: WorkflowType,
state: WorkflowType.State,
expectedWorkflows: [AnyExpectedWorkflow],
expectedSideEffects: [AnyHashable: ExpectedSideEffect<WorkflowType>],
file: StaticString,
line: UInt
) {
self.workflow = workflow
self.state = state
self.expectedWorkflows = expectedWorkflows
self.expectedSideEffects = expectedSideEffects
self.file = file
self.line = line
}

func render<Child, Action>(workflow: Child, key: String, outputMap: @escaping (Child.Output) -> Action) -> Child.Rendering where Child: Workflow, Action: WorkflowAction, Action.WorkflowType == WorkflowType {
func render<Child, Action>(workflow: Child, key: String, outputMap: @escaping (Child.Output) -> Action) -> Child.Rendering where Child: Workflow, Action: WorkflowActionCore, Action.WorkflowType == WorkflowType {
let matchingTypes = expectedWorkflows.compactMap { $0 as? ExpectedWorkflow<Child> }
guard let expectedWorkflow = matchingTypes.first(where: { $0.key == key }) else {
let sameTypeDifferentKeys = matchingTypes.map { $0.key }
Expand Down Expand Up @@ -90,7 +93,7 @@ extension RenderTester {
return expectedWorkflow.rendering
}

func makeSink<ActionType>(of actionType: ActionType.Type) -> Sink<ActionType> where ActionType: WorkflowAction, ActionType.WorkflowType == WorkflowType {
func makeSink<ActionType>(of actionType: ActionType.Type) -> Sink<ActionType> where ActionType: WorkflowActionCore, ActionType.WorkflowType == WorkflowType {
return Sink<ActionType> { action in
self.apply(action: action)
}
Expand All @@ -116,10 +119,10 @@ extension RenderTester {
}
}

private func apply<ActionType>(action: ActionType) where ActionType: WorkflowAction, ActionType.WorkflowType == WorkflowType {
private func apply<ActionType>(action: ActionType) where ActionType: WorkflowActionCore, ActionType.WorkflowType == WorkflowType {
XCTAssertNil(appliedAction, "Received multiple actions in a single render test", file: file, line: line)
appliedAction = AppliedAction(action)
let output = action.apply(toState: &state)
let output = action.apply(toState: &state, workflow: workflow)

if let output = output {
XCTAssertNil(producedOutput, "Received multiple outputs in a single render test", file: file, line: line)
Expand Down
1 change: 1 addition & 0 deletions WorkflowTesting/Sources/WorkflowRenderTester.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ public struct RenderTester<WorkflowType: Workflow> {
assertions: (WorkflowType.Rendering) throws -> Void
) rethrows -> RenderTesterResult<WorkflowType> {
let contextImplementation = TestContext(
workflow: workflow,
state: state,
expectedWorkflows: expectedWorkflows,
expectedSideEffects: expectedSideEffects,
Expand Down

0 comments on commit c9fcd66

Please sign in to comment.