Skip to content

Commit

Permalink
rename: InsightsInterface to Insights
Browse files Browse the repository at this point in the history
  • Loading branch information
amanjeetsingh150 committed Nov 12, 2024
1 parent 75c8847 commit 159fe78
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import maestro.cli.DisableAnsiMixin
import maestro.cli.ShowHelpMixin
import maestro.cli.report.TestDebugReporter
import maestro.cli.session.MaestroSessionManager
import maestro.cli.view.green
import maestro.cli.view.yellow
import maestro.utils.Insights
import maestro.utils.CliInsights
import maestro.utils.chunkStringByWordCount
import picocli.CommandLine
import java.lang.StringBuilder
Expand Down Expand Up @@ -65,7 +64,7 @@ class PrintHierarchyCommand : Runnable {
deviceId = parent?.deviceId,
platform = parent?.platform,
) { session ->
Insights.onInsightsUpdated {
CliInsights.onInsightsUpdated {
val message = StringBuilder()
val level = it.level.toString().lowercase().replaceFirstChar(Char::uppercase)
message.append(level.yellow() + ": ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import maestro.orchestra.CompositeCommand
import maestro.orchestra.MaestroCommand
import maestro.orchestra.Orchestra
import maestro.orchestra.yaml.YamlCommandReader
import maestro.utils.Insights
import maestro.utils.CliInsights
import org.slf4j.LoggerFactory
import java.util.IdentityHashMap
import maestro.cli.util.ScreenshotUtils
Expand Down Expand Up @@ -92,7 +92,7 @@ object MaestroCommandRunner {

val orchestra = Orchestra(
maestro = maestro,
insights = Insights,
insights = CliInsights,
onCommandStart = { _, command ->
logger.info("${command.description()} RUNNING")
commandStatuses[command] = CommandStatus.RUNNING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import maestro.Maestro
import maestro.cli.device.Device
import maestro.cli.device.PickDeviceInteractor
import maestro.cli.device.Platform
import maestro.utils.Insights
import maestro.utils.CliInsights
import maestro.cli.util.ScreenReporter
import maestro.drivers.AndroidDriver
import maestro.drivers.IOSDriver
Expand Down Expand Up @@ -305,9 +305,9 @@ object MaestroSessionManager {
deviceId = deviceId,
xcTestDevice = xcTestDevice,
simctlIOSDevice = simctlIOSDevice,
insights = Insights
insights = CliInsights
),
insights = Insights
insights = CliInsights
)

return Maestro.ios(
Expand Down
2 changes: 1 addition & 1 deletion maestro-client/src/main/java/maestro/drivers/IOSDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import kotlin.collections.set

class IOSDriver(
private val iosDevice: IOSDevice,
private val insights: InsightsInterface = NoopInsights
private val insights: Insights = NoopInsights
) : Driver {

private var appId: String? = null
Expand Down
4 changes: 2 additions & 2 deletions maestro-ios/src/main/java/ios/LocalIOSDevice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.io.InputStream
import java.util.UUID
import hierarchy.ViewHierarchy
import maestro.utils.Insight
import maestro.utils.InsightsInterface
import maestro.utils.Insights
import maestro.utils.NoopInsights
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
Expand All @@ -18,7 +18,7 @@ class LocalIOSDevice(
override val deviceId: String?,
private val xcTestDevice: XCTestIOSDevice,
private val simctlIOSDevice: SimctlIOSDevice,
private val insights: InsightsInterface = NoopInsights
private val insights: Insights = NoopInsights
) : IOSDevice {

private val executor by lazy { Executors.newSingleThreadScheduledExecutor() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import maestro.orchestra.geo.Traveller
import maestro.orchestra.util.Env.evaluateScripts
import maestro.orchestra.yaml.YamlCommandReader
import maestro.utils.Insight
import maestro.utils.InsightsInterface
import maestro.utils.Insights
import maestro.utils.MaestroTimer
import maestro.utils.NoopInsights
import maestro.utils.StringUtils.toRegexSafe
Expand Down Expand Up @@ -77,7 +77,7 @@ class Orchestra(
private val lookupTimeoutMs: Long = 17000L,
private val optionalLookupTimeoutMs: Long = 7000L,
private val httpClient: OkHttpClient? = null,
private val insights: InsightsInterface = NoopInsights,
private val insights: Insights = NoopInsights,
private val onFlowStart: (List<MaestroCommand>) -> Unit = {},
private val onCommandStart: (Int, MaestroCommand) -> Unit = { _, _ -> },
private val onCommandComplete: (Int, MaestroCommand) -> Unit = { _, _ -> },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import kotlinx.coroutines.*
import maestro.studio.BannerMessage.*
import maestro.utils.Insight
import maestro.utils.Insights
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import maestro.utils.CliInsights

object InsightService {

Expand Down Expand Up @@ -41,7 +38,7 @@ object InsightService {
}

private fun registerInsightUpdateCallback() {
Insights.onInsightsUpdated {
CliInsights.onInsightsUpdated {
currentInsight = it
}
}
Expand Down
4 changes: 2 additions & 2 deletions maestro-utils/src/main/kotlin/Insight.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package maestro.utils

object Insights: InsightsInterface {
object CliInsights: Insights {

private var insight: Insight = Insight("", Insight.Level.NONE)
private val listeners = mutableListOf<(Insight) -> Unit>()

override fun report(insight: Insight) {
Insights.insight = insight
CliInsights.insight = insight
listeners.forEach { it.invoke(insight) }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package maestro.utils

interface InsightsInterface {
interface Insights {

fun report(insight: Insight)

Expand All @@ -9,7 +9,7 @@ interface InsightsInterface {
fun unregisterListener(callback: (Insight) -> Unit)
}

object NoopInsights: InsightsInterface {
object NoopInsights: Insights {

override fun report(insight: Insight) {
/* no-op */
Expand Down
18 changes: 9 additions & 9 deletions maestro-utils/src/test/kotlin/InsightTest.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import maestro.utils.Insight
import maestro.utils.Insights
import maestro.utils.CliInsights
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class InsightsTest {
class CliInsightsTest {

@Test
fun `report should update insight and notify listeners`() {
val insight = Insight("Test message", Insight.Level.INFO)
var notifiedInsight: Insight? = null

Insights.onInsightsUpdated { notifiedInsight = it }
Insights.report(insight)
CliInsights.onInsightsUpdated { notifiedInsight = it }
CliInsights.report(insight)

assertEquals(insight, notifiedInsight)
}
Expand All @@ -22,8 +22,8 @@ class InsightsTest {
val insight = Insight("Test message", Insight.Level.INFO)
var notified = false

Insights.onInsightsUpdated { notified = true }
Insights.report(insight)
CliInsights.onInsightsUpdated { notified = true }
CliInsights.report(insight)

assertTrue(notified)
}
Expand All @@ -34,9 +34,9 @@ class InsightsTest {
var notified = false
val listener: (Insight) -> Unit = { notified = true }

Insights.onInsightsUpdated(listener)
Insights.unregisterListener(listener)
Insights.report(insight)
CliInsights.onInsightsUpdated(listener)
CliInsights.unregisterListener(listener)
CliInsights.report(insight)

assertTrue(!notified)
}
Expand Down

0 comments on commit 159fe78

Please sign in to comment.