Skip to content
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

Add testRender with CoroutineScope for SessionWorkflow #1141

Merged
merged 1 commit into from
Dec 13, 2023

Conversation

steve-the-edwards
Copy link
Contributor

Fixes #1138

@steve-the-edwards steve-the-edwards force-pushed the sedwards/test-render-session branch 2 times, most recently from a4dca45 to ada7b66 Compare December 11, 2023 22:59
@Suppress("UNCHECKED_CAST")
public fun <PropsT, OutputT, RenderingT> Workflow<PropsT, OutputT, RenderingT>.testRender(
props: PropsT
): RenderTester<PropsT, *, OutputT, RenderingT> {
val statefulWorkflow = asStatefulWorkflow() as StatefulWorkflow<PropsT, Any?, OutputT, RenderingT>
return statefulWorkflow.testRender(
props = props,
initialState = statefulWorkflow.initialState(props, null)
initialState = run {
require(this !is SessionWorkflow<PropsT, *, OutputT, RenderingT>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

*/
@OptIn(WorkflowExperimentalApi::class)
@Suppress("UNCHECKED_CAST")
public fun <PropsT, OutputT, RenderingT> Workflow<PropsT, OutputT, RenderingT>.testRender(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't you make this version an extension on SessionWorkflow and avoid the runtime check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ya I thought about that but then I thought about how in your tests you might not have the reified SessionWorkflow type? Maybe you were passing it around or dealign with it just as a Workflow? Maybe I was overthinking it though. Perhaps we could just make it an extension on SessionWorkflow 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so. I'm going to write a unit test against class RealFooWorkflow, not interface FooWorkflow.

Copy link
Contributor Author

@steve-the-edwards steve-the-edwards Dec 12, 2023

Choose a reason for hiding this comment

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

ya, I think you are right. I will change it.

  • testRender + CoroutineScope extension extends SessionWorkflow not Workflow

Base automatically changed from sedwards/more-session-docs to main December 12, 2023 22:40
@steve-the-edwards steve-the-edwards merged commit 785da30 into main Dec 13, 2023
29 of 32 checks passed
@steve-the-edwards steve-the-edwards deleted the sedwards/test-render-session branch December 13, 2023 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SessionWorkflow throws when trying to unit test it with RenderTester#testRender
2 participants