Skip to content

Commit

Permalink
Added tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrigankmg committed Feb 13, 2025
1 parent a6aa843 commit ba73e53
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import io.mockk.junit5.MockKExtension
import io.mockk.mockkObject
import io.mockk.slot
import io.mockk.verify
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.TestTemplate
import org.junit.jupiter.api.extension.ExtendWith
Expand Down Expand Up @@ -45,6 +48,43 @@ internal class MetricsPluginTest : PlayerTest() {
player.inProgressState!!.transition("next")
verify { renderEndHandler wasNot Called }
}

@TestTemplate
fun `should trigger onFlowBegin hook`() {
var onFlowBeginTapped = false
plugin?.hooks?.onFlowBegin?.tap("test") { _ ->
onFlowBeginTapped = true
}
player.start(simpleFlowString)
assertTrue(onFlowBeginTapped)
}

@TestTemplate
fun `should trigger onFlowEnd hook`() = runBlockingTest {
var onFlowEndTapped = false
plugin?.hooks?.onFlowEnd?.tap("test") { _ ->
onFlowEndTapped = true
}

val flow = player.start(simpleFlowString)
player.inProgressState!!.transition("Next")
val result = flow.await()

assertEquals("DONE", result.endState.outcome)
assertTrue(onFlowEndTapped)
}

@TestTemplate
fun `should trigger onRenderEnd hook`() {
var onRenderEndTapped = false
plugin?.hooks?.onRenderEnd?.tap("test") { _, _, _ ->
onRenderEndTapped = true
}
player.start(simpleFlowString)
assertFalse(onRenderEndTapped)
plugin?.renderEnd()
assertTrue(onRenderEndTapped)
}
}

@ExtendWith(MockKExtension::class)
Expand Down

0 comments on commit ba73e53

Please sign in to comment.