From c9fcd6678e18ac2c644a830e74c1276b345da0da Mon Sep 17 00:00:00 2001 From: Tom Brow Date: Fri, 15 Dec 2023 10:57:06 -0600 Subject: [PATCH] make WorkflowTesting compile --- WorkflowTesting/Sources/Internal/AppliedAction.swift | 2 +- .../Sources/Internal/RenderTester+TestContext.swift | 11 +++++++---- WorkflowTesting/Sources/WorkflowRenderTester.swift | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/WorkflowTesting/Sources/Internal/AppliedAction.swift b/WorkflowTesting/Sources/Internal/AppliedAction.swift index 950464cbd..1cf9a1793 100644 --- a/WorkflowTesting/Sources/Internal/AppliedAction.swift +++ b/WorkflowTesting/Sources/Internal/AppliedAction.swift @@ -20,7 +20,7 @@ import XCTest struct AppliedAction { let erasedAction: Any - init(_ action: ActionType) where ActionType.WorkflowType == WorkflowType { + init(_ action: ActionType) where ActionType.WorkflowType == WorkflowType { self.erasedAction = action } diff --git a/WorkflowTesting/Sources/Internal/RenderTester+TestContext.swift b/WorkflowTesting/Sources/Internal/RenderTester+TestContext.swift index 0e86f6e8f..d14afa828 100644 --- a/WorkflowTesting/Sources/Internal/RenderTester+TestContext.swift +++ b/WorkflowTesting/Sources/Internal/RenderTester+TestContext.swift @@ -29,15 +29,18 @@ extension RenderTester { let file: StaticString let line: UInt + private let workflow: WorkflowType private var usedWorkflowKeys: Set = [] internal init( + workflow: WorkflowType, state: WorkflowType.State, expectedWorkflows: [AnyExpectedWorkflow], expectedSideEffects: [AnyHashable: ExpectedSideEffect], file: StaticString, line: UInt ) { + self.workflow = workflow self.state = state self.expectedWorkflows = expectedWorkflows self.expectedSideEffects = expectedSideEffects @@ -45,7 +48,7 @@ extension RenderTester { self.line = line } - func render(workflow: Child, key: String, outputMap: @escaping (Child.Output) -> Action) -> Child.Rendering where Child: Workflow, Action: WorkflowAction, Action.WorkflowType == WorkflowType { + func render(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 } guard let expectedWorkflow = matchingTypes.first(where: { $0.key == key }) else { let sameTypeDifferentKeys = matchingTypes.map { $0.key } @@ -90,7 +93,7 @@ extension RenderTester { return expectedWorkflow.rendering } - func makeSink(of actionType: ActionType.Type) -> Sink where ActionType: WorkflowAction, ActionType.WorkflowType == WorkflowType { + func makeSink(of actionType: ActionType.Type) -> Sink where ActionType: WorkflowActionCore, ActionType.WorkflowType == WorkflowType { return Sink { action in self.apply(action: action) } @@ -116,10 +119,10 @@ extension RenderTester { } } - private func apply(action: ActionType) where ActionType: WorkflowAction, ActionType.WorkflowType == WorkflowType { + private func apply(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) diff --git a/WorkflowTesting/Sources/WorkflowRenderTester.swift b/WorkflowTesting/Sources/WorkflowRenderTester.swift index d4a418df0..9156e921d 100644 --- a/WorkflowTesting/Sources/WorkflowRenderTester.swift +++ b/WorkflowTesting/Sources/WorkflowRenderTester.swift @@ -261,6 +261,7 @@ public struct RenderTester { assertions: (WorkflowType.Rendering) throws -> Void ) rethrows -> RenderTesterResult { let contextImplementation = TestContext( + workflow: workflow, state: state, expectedWorkflows: expectedWorkflows, expectedSideEffects: expectedSideEffects,