Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162package social.grain
import androidx.test.ext.junit.runners.AndroidJUnit4import kotlinx.serialization.json.jsonArrayimport kotlinx.serialization.json.jsonObjectimport kotlinx.serialization.json.jsonPrimitiveimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertFalseimport org.junit.Assert.assertTrueimport org.junit.Testimport org.junit.runner.RunWithimport social.grain.support.appContextimport social.grain.support.testJsonimport social.grain.ui.components.MapSupport
/** * The generated style assets, as the app will read them. * * tools/basemap writes these and they are committed, so the thing to pin is * that what was committed still points where it should: a regenerate against * a changed theme package that dropped the tile source or the glyphs would * otherwise ship a blank map. */@RunWith(AndroidJUnit4::class)class BasemapStyleTest {
private fun style(theme: String) = appContext.assets.open("basemap/$theme.json") .bufferedReader() .use { testJson.parseToJsonElement(it.readText()).jsonObject }
@Test fun bothThemesDrawGrainsOwnTilesWithLabels() { for (theme in listOf("light", "dark")) { val style = style(theme) assertEquals(8, style["version"]?.jsonPrimitive?.content?.toInt())
val source = style["sources"]!!.jsonObject["protomaps"]!!.jsonObject assertEquals("vector", source["type"]?.jsonPrimitive?.content) assertEquals( "https://tiles.grain.social/planet/{z}/{x}/{y}.mvt", source["tiles"]!!.jsonArray.single().jsonPrimitive.content, ) assertTrue(source["attribution"]?.jsonPrimitive?.content!!.contains("OpenStreetMap"))
// MapLibre Native draws no text without a glyph endpoint. assertTrue(style["glyphs"]?.jsonPrimitive?.content!!.contains("{fontstack}"))
val layers = style["layers"]!!.jsonArray assertTrue(layers.size > 50) assertTrue(layers.any { it.jsonObject["type"]?.jsonPrimitive?.content == "symbol" }) assertTrue(layers.all { it.jsonObject["source"]?.jsonPrimitive?.content in setOf(null, "protomaps") }) } }
@Test fun theRendererIsNotAvailableOffADevice() { // What the screens rely on to leave the map out here, rather than // crash trying to load a native library the host doesn't have. assertFalse(MapSupport.isAvailable) }}