package com.ruoyi.web.modules.diagnosis.support;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.ruoyi.common.utils.ip.Ip2RegionUtils;

@DisplayName("ConsultAskerIpRegionResolver")
class ConsultAskerIpRegionResolverTest
{
    @Test
    @DisplayName("区县名格式化")
    void formatDistrictLabel()
    {
        assertEquals("巴青区", ConsultAskerIpRegionResolver.formatDistrictLabel("巴青县"));
        assertEquals("城关区", ConsultAskerIpRegionResolver.formatDistrictLabel("城关区"));
        assertEquals("那曲市", ConsultAskerIpRegionResolver.formatDistrictLabel("那曲市"));
        assertEquals("未知区", ConsultAskerIpRegionResolver.formatDistrictLabel(""));
    }

    @Test
    @DisplayName("ip2region 区县名提取")
    void extractDistrictNameFromIp2Region()
    {
        assertEquals("深圳市", Ip2RegionUtils.extractDistrictName("中国|广东省|深圳市|电信|CN"));
        assertEquals("Brisbane", Ip2RegionUtils.extractDistrictName("Australia|Queensland|Brisbane|0|AU"));
    }

    @Test
    @DisplayName("ip2region 离线查询")
    void searchRegionOffline()
    {
        String region = Ip2RegionUtils.searchRegion("114.114.114.114");
        assertNotNull(region);
    }
}
