Skip to content

Commit

Permalink
Move userAgent substring generation from Bridge to Strada namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jayohms committed Aug 10, 2023
1 parent 3d3f42d commit 42a872c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
5 changes: 0 additions & 5 deletions strada/src/main/kotlin/dev/hotwire/strada/Bridge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ class Bridge internal constructor(webView: WebView) {
}
}

fun userAgentSubstring(componentFactories: List<BridgeComponentFactory<*,*>>): String {
val components = componentFactories.joinToString(" ") { it.name }
return "bridge-components: [$components]"
}

@VisibleForTesting
internal fun initialize(bridge: Bridge) {
instances.add(bridge)
Expand Down
5 changes: 5 additions & 0 deletions strada/src/main/kotlin/dev/hotwire/strada/Strada.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ package dev.hotwire.strada

object Strada {
val config: StradaConfig = StradaConfig()

fun userAgentSubstring(componentFactories: List<BridgeComponentFactory<*,*>>): String {
val components = componentFactories.joinToString(" ") { it.name }
return "bridge-components: [$components]"
}
}
11 changes: 0 additions & 11 deletions strada/src/test/kotlin/dev/hotwire/strada/BridgeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,4 @@ class BridgeTest {
fun sanitizeFunctionName() {
assertEquals(bridge.sanitizeFunctionName("replyWith()"), "replyWith")
}

@Test
fun userAgentSubstring() {
val factories = listOf(
BridgeComponentFactory("one", TestData::OneBridgeComponent),
BridgeComponentFactory("two", TestData::TwoBridgeComponent)
)

val userAgentSubstring = Bridge.userAgentSubstring(factories)
assertEquals(userAgentSubstring, "bridge-components: [one two]")
}
}
17 changes: 17 additions & 0 deletions strada/src/test/kotlin/dev/hotwire/strada/UserAgentTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.hotwire.strada

import org.junit.Assert.assertEquals
import org.junit.Test

class UserAgentTest {
@Test
fun userAgentSubstring() {
val factories = listOf(
BridgeComponentFactory("one", TestData::OneBridgeComponent),
BridgeComponentFactory("two", TestData::TwoBridgeComponent)
)

val userAgentSubstring = Strada.userAgentSubstring(factories)
assertEquals(userAgentSubstring, "bridge-components: [one two]")
}
}

0 comments on commit 42a872c

Please sign in to comment.