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
package social.grain
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.serialization.json.jsonPrimitive
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import org.junit.runner.RunWith
import social.grain.data.location.Coordinate
import social.grain.feature.explore.LocationPin
import social.grain.feature.explore.pinBounds
import social.grain.feature.explore.placeFeatures
import social.grain.ui.components.localityOf
/** The pins as the map wants them: GeoJSON points, and a box around them. */
@RunWith(AndroidJUnit4::class)
class PlaceFeaturesTest {
private val lisbon = LocationPin("Lisbon, PT", "85390cb7fffffff", 3, Coordinate(38.72, -9.14))
private val porto = LocationPin("Porto, PT", "853913d3fffffff", 1, Coordinate(41.15, -8.61))
@Test
fun eachPinBecomesAPointCarryingWhatATapNeeds() {
val features = placeFeatures(listOf(lisbon, porto))
assertEquals(2, features.features.size)
val first = features.features.first()
assertEquals(-9.14, first.geometry.longitude, 1e-9)
assertEquals(38.72, first.geometry.latitude, 1e-9)
assertEquals("Lisbon, PT", first.properties["name"]?.jsonPrimitive?.content)
assertEquals("85390cb7fffffff", first.properties["h3"]?.jsonPrimitive?.content)
assertEquals("3", first.properties["count"]?.jsonPrimitive?.content)
}
@Test
fun theBoundsFrameEveryPin() {
val bounds = pinBounds(listOf(lisbon, porto))!!
assertEquals(-9.14, bounds.west, 1e-9)
assertEquals(38.72, bounds.south, 1e-9)
assertEquals(-8.61, bounds.east, 1e-9)
assertEquals(41.15, bounds.north, 1e-9)
}
@Test
fun theMapLabelIsTheLocalityAlone() {
assertEquals("Nazaré", localityOf("Nazaré, Leiria, PT"))
assertEquals("Lisbon", localityOf("Lisbon, PT"))
assertEquals("Portugal", localityOf("Portugal"))
assertEquals(", PT", localityOf(", PT"))
}
@Test
fun nothingToFrameIsNoBoundsRatherThanAnEmptyBox() {
assertNull(pinBounds(emptyList()))
}
}