package com.njcn.gather.report.pojo.constant;

import org.junit.Test;

import static org.junit.Assert.*;

public class ItemAnchorConstantTest {

    @Test
    public void resolveItemScriptCode_normal() {
        assertEquals("V", ItemAnchorConstant.resolveItemScriptCode("item_V"));
        assertEquals("FREQ", ItemAnchorConstant.resolveItemScriptCode("ITEM_FREQ")); // 前缀大小写不敏感
    }

    @Test
    public void resolveItemScriptCode_nonAnchor() {
        assertNull(ItemAnchorConstant.resolveItemScriptCode("_GoBack"));
        assertNull(ItemAnchorConstant.resolveItemScriptCode("data_line"));
        assertNull(ItemAnchorConstant.resolveItemScriptCode("sect_V"));
        assertNull(ItemAnchorConstant.resolveItemScriptCode(null));
        assertNull(ItemAnchorConstant.resolveItemScriptCode("item_")); // 空 code 视为非法
    }

    /** F3：白名单外的 item_ 书签（如作者手工遗留的 item_1）不得解析成功，否则老模板会整体误入新路径 */
    @Test
    public void resolveItemScriptCode_unknownCode_rejected() {
        assertNull(ItemAnchorConstant.resolveItemScriptCode("item_1"));
        assertNull(ItemAnchorConstant.resolveItemScriptCode("item_XYZ"));
        assertNull(ItemAnchorConstant.resolveItemScriptCode("item_HSV")); // TIME 里有但云南模板白名单没有
    }

    /** F3：白名单命中时大小写归一为规范大写（scriptMap / 模板 H5 分组 key 均为大写） */
    @Test
    public void resolveItemScriptCode_caseNormalized() {
        assertEquals("HV", ItemAnchorConstant.resolveItemScriptCode("item_hv"));
        assertEquals("IMBV", ItemAnchorConstant.resolveItemScriptCode("Item_imbv"));
    }

    @Test
    public void grpChildren_mapping() {
        assertEquals(java.util.Arrays.asList("V", "I", "P", "ANGLE"), ItemAnchorConstant.GRP_CHILDREN.get("GRP_FUND"));
        assertEquals(java.util.Arrays.asList("IMBV", "IMBA"), ItemAnchorConstant.GRP_CHILDREN.get("GRP_UNB"));
        assertEquals(java.util.Arrays.asList("HV", "HI", "HP"), ItemAnchorConstant.GRP_CHILDREN.get("GRP_HARM"));
    }
}
