Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / communicate-dev / src / test / java / com / vayunmathur / communicate / signal / SignalSlice2RegistrationUiTest.kt

SignalSlice2RegistrationUiTest.kt66 lines · 2.5 KiBRaw
1package com.vayunmathur.communicate.signal
2
3import androidx.compose.ui.test.assertIsDisplayed
4import androidx.compose.ui.test.junit4.createComposeRule
5import androidx.compose.ui.test.onNodeWithText
6import androidx.compose.ui.test.performClick
7import com.vayunmathur.communicate.data.signal.registration.RegistrationHttpClient
8import kotlin.test.Test
9import kotlin.test.assertEquals
10import kotlin.test.assertTrue
11import org.junit.Rule
12import org.junit.runner.RunWith
13import org.robolectric.RobolectricTestRunner
14
15/**
16 * Wave 9 (w6 slice 2/6): registration UI constants — the captcha URL/scheme contract between
17 * [RegistrationHttpClient] and the captcha WebView — plus a Compose smoke test of the captcha
18 * redirect-token stripping rule (the pure string half of the WebView client).
19 */
20@RunWith(RobolectricTestRunner::class)
21class SignalSlice2RegistrationUiTest {
22
23 @get:Rule
24 val rule = createComposeRule()
25
26 @Test
27 fun captchaConstants_matchServerContract() {
28 assertEquals(
29 "https://signalcaptchas.org/registration/generate.html",
30 RegistrationHttpClient.CAPTCHA_URL,
31 )
32 assertEquals("signalcaptcha://", RegistrationHttpClient.SIGNAL_CAPTCHA_SCHEME)
33 }
34
35 @Test
36 fun captchaRedirect_stripsSchemeToToken() {
37 val url = "signalcaptcha://signal-hcaptcha.sitekey.registration.abc123"
38 assertTrue(url.startsWith(RegistrationHttpClient.SIGNAL_CAPTCHA_SCHEME))
39 val token = url.substring(RegistrationHttpClient.SIGNAL_CAPTCHA_SCHEME.length)
40 assertEquals("signal-hcaptcha.sitekey.registration.abc123", token)
41 // Non-captcha URLs are not tokens.
42 assertTrue(!"https://example.com/".startsWith(RegistrationHttpClient.SIGNAL_CAPTCHA_SCHEME))
43 }
44
45 @Test
46 fun captchaToken_composeRoundTrip() {
47 var received: String? = null
48 rule.setContent {
49 androidx.compose.material3.Button(
50 onClick = {
51 val url = "signalcaptcha://tok123"
52 if (url.startsWith(RegistrationHttpClient.SIGNAL_CAPTCHA_SCHEME)) {
53 received = url.substring(RegistrationHttpClient.SIGNAL_CAPTCHA_SCHEME.length)
54 }
55 },
56 ) {
57 androidx.compose.material3.Text("Solve captcha")
58 }
59 }
60 rule.onNodeWithText("Solve captcha").assertIsDisplayed()
61 rule.onNodeWithText("Solve captcha").performClick()
62 rule.runOnIdle {
63 assertEquals("tok123", received)
64 }
65 }
66}