42 lines
1.4 KiB
Kotlin
42 lines
1.4 KiB
Kotlin
package top.yeij.hearth.webview
|
|
|
|
import org.junit.Assert.assertTrue
|
|
import org.junit.Test
|
|
import top.yeij.hearth.card.CardRepository
|
|
import top.yeij.hearth.cache.CacheManager
|
|
import top.yeij.hearth.webapp.HttpClient
|
|
import java.io.File
|
|
|
|
class JsBridgeTest {
|
|
@Test
|
|
fun getDeviceInfo_returnsJsonWithDarkMode() {
|
|
val bridge = JsBridge(deviceWidthPx = 800, deviceHeightPx = 480, density = 2.0f, darkMode = true)
|
|
val json = bridge.getDeviceInfo()
|
|
assertTrue(json.contains("\"widthPx\":800"))
|
|
assertTrue(json.contains("\"darkMode\":true"))
|
|
}
|
|
|
|
@Test
|
|
fun fetchCards_withoutRepository_returnsEmptyArray() {
|
|
val bridge = JsBridge(deviceWidthPx = 800, deviceHeightPx = 480, density = 2.0f, darkMode = true)
|
|
assertTrue(bridge.fetchCards() == "[]")
|
|
}
|
|
|
|
@Test
|
|
fun fetchCards_withRepository_returnsBuiltinTimeCard() {
|
|
val dir = File(System.getProperty("java.io.tmpdir"), "jb-cards")
|
|
val repo = CardRepository(
|
|
object : HttpClient { override fun get(url: String): String? = null },
|
|
CacheManager(dir),
|
|
"http://fake",
|
|
)
|
|
val bridge = JsBridge(
|
|
deviceWidthPx = 800, deviceHeightPx = 480, density = 2.0f, darkMode = true,
|
|
cardRepository = repo,
|
|
)
|
|
val json = bridge.fetchCards()
|
|
assertTrue(json.contains("\"id\":\"time\""))
|
|
dir.deleteRecursively()
|
|
}
|
|
}
|