@@ -49,67 +49,15 @@ import kotlin.time.Duration.Companion.milliseconds
4949 * The default [RuntimeConfig] will be the one specified via [JvmTestRuntimeConfigTools].
5050 */
5151@OptIn(ExperimentalCoroutinesApi ::class )
52- public fun <PropsT , OutputT , RenderingT > Workflow <PropsT , OutputT , RenderingT >.renderForTest (
52+ public fun <PropsT , StateT , OutputT , RenderingT >
53+ StatefulWorkflow <PropsT , StateT , OutputT , RenderingT >.renderForTest (
5354 props : StateFlow <PropsT >,
54- testParams : WorkflowTestParams <Nothing > = WorkflowTestParams (),
55+ testParams : WorkflowTestParams <StateT > = WorkflowTestParams (),
5556 coroutineContext : CoroutineContext = UnconfinedTestDispatcher (),
56- interceptors : List <WorkflowInterceptor > = emptyList(),
5757 onOutput : suspend (OutputT ) -> Unit = {},
5858 testTimeout : Long = WORKFLOW_TEST_DEFAULT_TIMEOUT_MS ,
5959 testCase : suspend WorkflowTurbine <RenderingT , OutputT >.() -> Unit
60- ) = asStatefulWorkflow().renderForTest(
61- props,
62- testParams,
63- coroutineContext,
64- onOutput,
65- testTimeout,
66- testCase
67- )
68-
69- /* *
70- * Version of [renderForTest] that does not require props. For Workflows that have [Unit]
71- * props type.
72- */
73- @OptIn(ExperimentalCoroutinesApi ::class )
74- public fun <OutputT , RenderingT > Workflow <Unit , OutputT , RenderingT >.renderForTest (
75- coroutineContext : CoroutineContext = UnconfinedTestDispatcher (),
76- testParams : WorkflowTestParams <Nothing > = WorkflowTestParams (),
77- interceptors : List <WorkflowInterceptor > = emptyList(),
78- onOutput : suspend (OutputT ) -> Unit = {},
79- testTimeout : Long = WORKFLOW_TEST_DEFAULT_TIMEOUT_MS ,
80- testCase : suspend WorkflowTurbine <RenderingT , OutputT >.() -> Unit
81- ): Unit = renderForTest(
82- props = MutableStateFlow (Unit ).asStateFlow(),
83- testParams = testParams,
84- coroutineContext = coroutineContext,
85- interceptors = interceptors,
86- onOutput = onOutput,
87- testTimeout = testTimeout,
88- testCase = testCase
89- )
90-
91- /* *
92- * Version of [renderForTest] for a [StatefulWorkflow]
93- * that accepts [WorkflowTestParams] for configuring the test,
94- * including starting from a specific state or snapshot.
95- *
96- * @param props StateFlow of props to send to the workflow.
97- * @param testParams Test configuration parameters. See [WorkflowTestParams] for details.
98- * @param coroutineContext Optional [CoroutineContext] to use for the test.
99- * @param onOutput Callback for workflow outputs.
100- * @param testTimeout Maximum time to wait for workflow operations in milliseconds.
101- * @param testCase The test code to run with access to the [WorkflowTurbine].
102- */
103- @OptIn(ExperimentalCoroutinesApi ::class )
104- public fun <PropsT , StateT , OutputT , RenderingT >
105- StatefulWorkflow <PropsT , StateT , OutputT , RenderingT >.renderForTest (
106- props : StateFlow <PropsT >,
107- testParams : WorkflowTestParams <StateT > = WorkflowTestParams (),
108- coroutineContext : CoroutineContext = UnconfinedTestDispatcher (),
109- onOutput : suspend (OutputT ) -> Unit = {},
110- testTimeout : Long = WORKFLOW_TEST_DEFAULT_TIMEOUT_MS ,
111- testCase : suspend WorkflowTurbine <RenderingT , OutputT >.() -> Unit
112- ) {
60+ ) {
11361 val workflow: Workflow <PropsT , OutputT , RenderingT > = this
11462
11563 // Determine the initial snapshot based on startFrom mode
@@ -189,22 +137,75 @@ public fun <PropsT, StateT, OutputT, RenderingT>
189137}
190138
191139/* *
192- * Version of [renderForTest] for a [StatefulWorkflow]
193- * that accepts [WorkflowTestParams] and doesn't require props.
194- * For Workflows that have [Unit] props type.
140+ * Version of [renderForTest] that does not require props. For [StatefulWorkflow]s that have [Unit]
141+ * props type.
195142 */
196143@OptIn(ExperimentalCoroutinesApi ::class )
197144public fun <StateT , OutputT , RenderingT >
198145 StatefulWorkflow <Unit , StateT , OutputT , RenderingT >.renderForTest (
199- testParams : WorkflowTestParams <StateT > = WorkflowTestParams (),
200- coroutineContext : CoroutineContext = UnconfinedTestDispatcher (),
201- onOutput : suspend (OutputT ) -> Unit = {},
202- testTimeout : Long = WORKFLOW_TEST_DEFAULT_TIMEOUT_MS ,
203- testCase : suspend WorkflowTurbine <RenderingT , OutputT >.() -> Unit
204- ): Unit = renderForTest(
146+ testParams : WorkflowTestParams <StateT > = WorkflowTestParams (),
147+ coroutineContext : CoroutineContext = UnconfinedTestDispatcher (),
148+ onOutput : suspend (OutputT ) -> Unit = {},
149+ testTimeout : Long = WORKFLOW_TEST_DEFAULT_TIMEOUT_MS ,
150+ testCase : suspend WorkflowTurbine <RenderingT , OutputT >.() -> Unit
151+ ): Unit = renderForTest(
152+ props = MutableStateFlow (Unit ).asStateFlow(),
153+ testParams = testParams,
154+ coroutineContext = coroutineContext,
155+ onOutput = onOutput,
156+ testTimeout = testTimeout,
157+ testCase = testCase
158+ )
159+
160+ /* *
161+ * Version of [renderForTest] for any [Workflow]
162+ * that accepts [WorkflowTestParams] for configuring the test,
163+ * including starting from a specific state or snapshot.
164+ *
165+ * @param props StateFlow of props to send to the workflow.
166+ * @param testParams Test configuration parameters. See [WorkflowTestParams] for details.
167+ * @param coroutineContext Optional [CoroutineContext] to use for the test.
168+ * @param onOutput Callback for workflow outputs.
169+ * @param testTimeout Maximum time to wait for workflow operations in milliseconds.
170+ * @param testCase The test code to run with access to the [WorkflowTurbine].
171+ */
172+ @OptIn(ExperimentalCoroutinesApi ::class )
173+ public fun <PropsT , OutputT , RenderingT > Workflow <PropsT , OutputT , RenderingT >.renderForTestForStartWith (
174+ props : StateFlow <PropsT >,
175+ testParams : WorkflowTestParams <Nothing > = WorkflowTestParams (),
176+ coroutineContext : CoroutineContext = UnconfinedTestDispatcher (),
177+ interceptors : List <WorkflowInterceptor > = emptyList(),
178+ onOutput : suspend (OutputT ) -> Unit = {},
179+ testTimeout : Long = WORKFLOW_TEST_DEFAULT_TIMEOUT_MS ,
180+ testCase : suspend WorkflowTurbine <RenderingT , OutputT >.() -> Unit
181+ ) = asStatefulWorkflow().renderForTest(
182+ props,
183+ testParams,
184+ coroutineContext,
185+ onOutput,
186+ testTimeout,
187+ testCase
188+ )
189+
190+
191+ /* *
192+ * Version of [renderForTest] for any [Workflow]
193+ * that accepts [WorkflowTestParams] and doesn't require props.
194+ * For Workflows that have [Unit] props type.
195+ */
196+ @OptIn(ExperimentalCoroutinesApi ::class )
197+ public fun <OutputT , RenderingT > Workflow <Unit , OutputT , RenderingT >.renderForTestForStartWith (
198+ coroutineContext : CoroutineContext = UnconfinedTestDispatcher (),
199+ testParams : WorkflowTestParams <Nothing > = WorkflowTestParams (),
200+ interceptors : List <WorkflowInterceptor > = emptyList(),
201+ onOutput : suspend (OutputT ) -> Unit = {},
202+ testTimeout : Long = WORKFLOW_TEST_DEFAULT_TIMEOUT_MS ,
203+ testCase : suspend WorkflowTurbine <RenderingT , OutputT >.() -> Unit
204+ ): Unit = renderForTestForStartWith(
205205 props = MutableStateFlow (Unit ).asStateFlow(),
206206 testParams = testParams,
207207 coroutineContext = coroutineContext,
208+ interceptors = interceptors,
208209 onOutput = onOutput,
209210 testTimeout = testTimeout,
210211 testCase = testCase
0 commit comments