1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package social.grain
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import social.grain.support.appContext
import social.grain.support.testJson
import 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)
}
}