Skip to content

Commit

Permalink
Fixed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sakuntala-motukuri committed Aug 5, 2024
1 parent f220d09 commit 554861f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import com.intuit.hooks.AsyncParallelBailHook
import com.intuit.hooks.BailResult
import com.intuit.hooks.HookContext
import com.intuit.playerui.core.bridge.Node
import com.intuit.playerui.core.bridge.NodeWrapper
import com.intuit.playerui.core.bridge.serialization.serializers.NodeWrapperSerializer
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable

Expand All @@ -32,4 +30,4 @@ public class NodeAsyncParallelBailHook1<T1, R : Any>(override val node: Node, se
internal class Serializer<T1, R : Any>(private val serializer1: KSerializer<T1>, `_`: KSerializer<R>) : NodeWrapperSerializer<NodeAsyncParallelBailHook1<T1, R>>({
NodeAsyncParallelBailHook1(it, serializer1)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ import com.intuit.hooks.HookContext
import com.intuit.playerui.core.bridge.Invokable
import com.intuit.playerui.core.bridge.Node
import com.intuit.playerui.core.bridge.NodeWrapper
import com.intuit.playerui.core.bridge.Promise
import com.intuit.playerui.core.bridge.getInvokable
import com.intuit.playerui.core.utils.InternalPlayerApi
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.capturedKClass
import com.intuit.playerui.core.bridge.Promise

/** Contains common logic for configuring a [NodeHook] to tap any JS hook */
internal interface NodeHook<R> : NodeWrapper {

@OptIn(ExperimentalSerializationApi::class)
fun init(vararg serializers: KSerializer<*>) {
println("NodeHook initialized with node: $node")
node.getInvokable<Any?>("tap")?.invoke(
mapOf("name" to "name", "context" to true),
Invokable { args ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import com.intuit.playerui.core.player.state.PlayerFlowState
import com.intuit.playerui.utils.normalizeStackTraceElements
import com.intuit.playerui.utils.test.PromiseUtils
import com.intuit.playerui.utils.test.RuntimeTest
import com.intuit.player.jvm.utils.test.runBlockingTest
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
Expand Down Expand Up @@ -219,4 +221,27 @@ internal class PromiseTest : RuntimeTest(), PromiseUtils {
assertEquals(exception.message, caught.message)
assertEquals(exception.stackTrace.normalizeStackTraceElements(), caught.stackTrace.normalizeStackTraceElements())
}

@TestTemplate
fun testPromiseConstructor() = runBlockingTest {
runtime.execute(
"""
class TestClass {
name = 'foo';
constructor(promise) {
promise.then((value) => {
this.name = value;
});
};
}""",
)
val promise = runtime.Promise<String> { jsRes, _ ->
val result = "bar"
jsRes(result)
}
runtime.add("myPromise", promise)
val value = runtime.execute("new TestClass(myPromise)") as Node
promise.toCompletable(String.serializer()).await()
assertEquals("bar", value["name"])
}
}
5 changes: 0 additions & 5 deletions plugins/async-node/jvm/deps.bzl
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
maven = [
"com.intuit.player:core-bridge:1.0.0",
]

main_exports = [
"//jvm/core",
]

main_deps = main_exports + [
"//jvm:kotlin_serialization",
"//plugins/set-time-out/jvm:set-time-out",
]

main_resources = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ internal class AsyncNodePluginTest : PlayerTest() {
player.start(asyncNodeFlowSimple)
}
Assertions.assertTrue(count == 2)
Assertions.assertTrue((update?.get("actions") as List<*>).size == 3)
Assertions.assertEquals(3, update?.getList("actions")?.size)
}

@TestTemplate
Expand All @@ -153,9 +153,11 @@ internal class AsyncNodePluginTest : PlayerTest() {
2 -> {
Assertions.assertEquals(1, (asset?.get("actions") as List<*>).size)
}

3 -> {
Assertions.assertEquals(2, (asset?.get("actions") as List<*>).size)
}

4 -> {
Assertions.assertEquals(4, (asset?.get("actions") as List<*>).size)
}
Expand All @@ -180,6 +182,7 @@ internal class AsyncNodePluginTest : PlayerTest() {
),
),
)

2 -> BailResult.Bail(
listOf(
mapOf(
Expand All @@ -195,6 +198,7 @@ internal class AsyncNodePluginTest : PlayerTest() {
),
),
)

else -> BailResult.Bail(
listOf(
mapOf(
Expand Down

0 comments on commit 554861f

Please sign in to comment.