-
Notifications
You must be signed in to change notification settings - Fork 47
Introduce new RenderTester API #15
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
Conversation
7cafd8a
to
72bc77a
Compare
I like the equatable overloads for state and output, filed for Kotlin as square/workflow-kotlin#63 |
65c6a2e
to
45ad7fa
Compare
This is really cool! I was worried about having to overload the same |
let rendering: ExpectedWorkflowType.Rendering | ||
let output: ExpectedWorkflowType.Output? | ||
|
||
init(key: String, rendering: ExpectedWorkflowType.Rendering, output: ExpectedWorkflowType.Output?) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will need something like in: https://github.com/square/workflow-swift/pull/11/files#diff-d274c3ab6b1b700864fdd0b96d30b731R129
to support custom matching for Worker
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we? We don’t actually want to reproduce/change the matching behavior since the RenderContext won’t have additional matching logic for Workers. I’d pictured something like this:
extension RenderTester {
public func expect<ExpectedWorkerType: Worker>(
worker expectedWorker: ExpectedWorkerType,
key: String = "",
producingOutput output: ExpectedWorkerType.Output? = nil
) -> RenderTester<WorkflowType> {
return self.expectWorkflow(
type: WorkerWorkflow<ExpectedWorkerType>,
key: key,
producingRendering: (),
producingOutput: output,
assertions: { actualWorker in
XCTAssert(expectedWorker.isEquivalent(to: actualWorker))
}
)
}
}
(though I do think I should update assertions
to give the file and line so we can correctly place the error where it should be)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, that's right, fantastic!
A slight change, we'll get the Workflow
here.
extension RenderTester {
public func expect<ExpectedWorkerType: Worker>(
worker expectedWorker: ExpectedWorkerType,
key: String = "",
producingOutput output: ExpectedWorkerType.Output? = nil
) -> RenderTester<WorkflowType> {
return self.expectWorkflow(
type: WorkerWorkflow<ExpectedWorkerType>,
key: key,
producingRendering: (),
producingOutput: output,
assertions: { actualWorkflow in
XCTAssert(actualWorkflow.worker.isEquivalent(to: expectedWorker))
}
)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right, yep!
After noting “though I do think I should update I also fixed the fact that |
import Workflow | ||
import XCTest | ||
|
||
struct AppliedAction<WorkflowType: Workflow> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be wrapped in an #if DEBUG
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think so if the comment about @testable import
being the issue was correct (since this file does a standard import)
This makes it a little more clear when mutations are happening, and makes it less weird that we mutate a shared thing while also passing it along (e.g. it’s now clear that the _only_ way to correctly use the render tester is to use the tester that results from each call as you go)
142c102
to
d459a9c
Compare
Per #16 and square/workflow#702, introduce a new RenderTester API shaped like the following:
The
expect
methods come in the following shapes:expectWorkflow(workflowType: WorkflowType.Type, key: String, producingRendering: WorkflowType.Rendering, producingOutput: WorkflowType.Output?, assertions: ((WorkflowType) -> Void)?)
expect(worker: WorkerType, producingOutput: WorkerType.Output?)
expectSideEffect(key: AnyHashable, producingAction: ActionType?)
The
verify
methods come in the following:verifyAction(assertions: (Action) -> Void)
verify(action: Action)
(when Equatable)verifyNoAction()
verifyOutput(assertions: (Output) -> Void)
verify(output: Output)
(when Equatable)verifyNoOutput()
verifyState(assertions: (State) -> Void)
verify(state: State)
(when Equatable)This also deprecates, but keeps around, the old API (you’ll see some type erasure and contortions in this PR to reimplement the old API on top of the new one).
Checklist
UI TestsSnapshot Tests (iOS only)