feat: support add=true in QR codes (#1151)

This commit is contained in:
AddisonTustin 2024-07-28 04:50:54 -07:00 committed by GitHub
parent cc5543f4c9
commit e4c6000a10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 105 additions and 18 deletions

View file

@ -5,6 +5,7 @@ import org.junit.Assert
import org.junit.Test
class ChannelSetTest {
/** make sure we match the python and device code behavior */
@Test
fun matchPython() {
@ -13,4 +14,34 @@ class ChannelSetTest {
Assert.assertEquals("LongFast", cs.primaryChannel!!.name)
Assert.assertEquals(url, cs.getChannelUrl(false))
}
/** 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)
}
}