package com.tencent.qian.webview

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.tencent.qian.webview.scheme.SignResultParser
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Test
import org.junit.runner.RunWith

/**
 * Configurator 公开 API 的「smoke」级别测试。
 *
 * **完整 chained delegate / 二次 apply 不堆叠** 的真实测试需要 Robolectric WebView shadow
 * (Phase 1.5 跟进);本期先校验:
 * - [TencentQianWebView.canHandle] / [TencentQianWebView.sdkVersion] 表面 API
 * - [SignResultParser] 与 [TencentQianWebView.canHandle] 的判断一致性
 */
@RunWith(AndroidJUnit4::class)
class TencentQianWebViewApiTest {

    @Test fun canHandle_recognizes_qianapp_scheme() {
        assertEquals(true, TencentQianWebView.canHandle(android.net.Uri.parse("qianapp://x")))
        assertEquals(false, TencentQianWebView.canHandle(android.net.Uri.parse("https://x.com")))
        assertEquals(false, TencentQianWebView.canHandle(null))
    }

    @Test fun sdkVersion_is_non_empty() {
        val v = TencentQianWebView.sdkVersion()
        assertNotNull(v)
        assert(v.isNotEmpty())
    }

    @Test fun canHandle_aligns_with_parser() {
        val url = "qianapp://callback/sign?action=sign&result=success"
        assertEquals(true, TencentQianWebView.canHandle(android.net.Uri.parse(url)))
        assertEquals(true, SignResultParser.isQianAppScheme(url))
    }
}
