2024-07-28 09:02:17 -03:00
|
|
|
package com.geeksville.mesh
|
2021-03-19 17:42:26 +08:00
|
|
|
|
|
|
|
|
import android.net.Uri
|
2024-07-28 09:02:17 -03:00
|
|
|
import com.geeksville.mesh.model.getChannelUrl
|
|
|
|
|
import com.geeksville.mesh.model.primaryChannel
|
|
|
|
|
import com.geeksville.mesh.model.shouldAddChannels
|
|
|
|
|
import com.geeksville.mesh.model.toChannelSet
|
|
|
|
|
import dagger.hilt.android.testing.HiltAndroidRule
|
|
|
|
|
import dagger.hilt.android.testing.HiltAndroidTest
|
2021-03-19 17:42:26 +08:00
|
|
|
import org.junit.Assert
|
2024-07-28 09:02:17 -03:00
|
|
|
import org.junit.Before
|
|
|
|
|
import org.junit.Rule
|
2021-03-19 17:42:26 +08:00
|
|
|
import org.junit.Test
|
|
|
|
|
|
2024-07-28 09:02:17 -03:00
|
|
|
@HiltAndroidTest
|
2021-03-19 17:42:26 +08:00
|
|
|
class ChannelSetTest {
|
2024-07-28 04:50:54 -07:00
|
|
|
|
2024-07-28 09:02:17 -03:00
|
|
|
@get:Rule
|
|
|
|
|
var hiltRule = HiltAndroidRule(this)
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
fun init() {
|
|
|
|
|
hiltRule.inject()
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-19 17:42:26 +08:00
|
|
|
/** make sure we match the python and device code behavior */
|
|
|
|
|
@Test
|
|
|
|
|
fun matchPython() {
|
2023-07-18 22:28:16 -03:00
|
|
|
val url = Uri.parse("https://meshtastic.org/e/#CgMSAQESBggBQANIAQ")
|
2023-10-07 08:22:12 -03:00
|
|
|
val cs = url.toChannelSet()
|
2022-05-30 17:43:05 -03:00
|
|
|
Assert.assertEquals("LongFast", cs.primaryChannel!!.name)
|
|
|
|
|
Assert.assertEquals(url, cs.getChannelUrl(false))
|
2021-03-19 17:42:26 +08:00
|
|
|
}
|
2024-07-28 04:50:54 -07:00
|
|
|
|
|
|
|
|
/** validate against the host or path in a case-insensitive way */
|
|
|
|
|
@Test
|
|
|
|
|
fun parseCaseInsensitive() {
|
|
|
|
|
var url = Uri.parse("HTTPS://MESHTASTIC.ORG/E/#CgMSAQESBggBQANIAQ")
|
|
|
|
|
Assert.assertEquals("LongFast", url.toChannelSet().primaryChannel!!.name)
|
|
|
|
|
|
|
|
|
|
url = Uri.parse("HTTPS://mEsHtAsTiC.OrG/e/#CgMSAQESBggBQANIAQ")
|
|
|
|
|
Assert.assertEquals("LongFast", url.toChannelSet().primaryChannel!!.name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** properly parse channel config when `?add=true` is in the fragment */
|
|
|
|
|
@Test
|
|
|
|
|
fun handleAddInFragment() {
|
|
|
|
|
val url = Uri.parse("https://meshtastic.org/e/#CgMSAQESBggBQANIAQ?add=true")
|
|
|
|
|
val cs = url.toChannelSet()
|
|
|
|
|
val shouldAdd = url.shouldAddChannels()
|
|
|
|
|
Assert.assertEquals("LongFast", cs.primaryChannel!!.name)
|
|
|
|
|
Assert.assertTrue(shouldAdd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** properly parse channel config when `?add=true` is in the query parameters */
|
|
|
|
|
@Test
|
|
|
|
|
fun handleAddInQueryParams() {
|
|
|
|
|
val url = Uri.parse("https://meshtastic.org/e/?add=true#CgMSAQESBggBQANIAQ")
|
|
|
|
|
val cs = url.toChannelSet()
|
|
|
|
|
val shouldAdd = url.shouldAddChannels()
|
|
|
|
|
Assert.assertEquals("LongFast", cs.primaryChannel!!.name)
|
|
|
|
|
Assert.assertTrue(shouldAdd)
|
|
|
|
|
}
|
2022-02-15 23:50:27 -03:00
|
|
|
}
|