package com.tencent.qian.webview;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import android.net.Uri;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.tencent.qian.webview.scheme.SignResultParser;

import org.junit.Test;
import org.junit.runner.RunWith;

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

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

    @Test
    public void sdkVersion_is_non_empty() {
        String v = TencentQianWebView.sdkVersion();
        assertNotNull(v);
        assertTrue(v.length() > 0);
    }

    @Test
    public void canHandle_aligns_with_parser() {
        String url = "qianapp://callback/sign?action=sign&result=success";
        assertEquals(true, TencentQianWebView.canHandle(Uri.parse(url)));
        assertEquals(true, SignResultParser.isQianAppScheme(url));
    }
}
