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

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

import java.io.InputStream;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.ruoyi.web.modules.industryservice.support.LargeLivestockFarmerExcelParser.ParsedRow;

@DisplayName("LargeLivestockFarmerExcelParser")
class LargeLivestockFarmerExcelParserTest
{
    @Test
    @DisplayName("官方导入模板无示例数据行时可解析为空列表")
    void parseOfficialTemplateEmptyData() throws Exception
    {
        try (InputStream in = getClass().getClassLoader()
                .getResourceAsStream(LargeLivestockFarmerExcelParser.TEMPLATE_CLASSPATH))
        {
            assertNotNull(in, "classpath 模板不存在");
            List<ParsedRow> rows = LargeLivestockFarmerExcelParser.parse(in);
            assertTrue(rows.isEmpty());
        }
    }

    @Test
    @DisplayName("识别表头行（乡镇名称+村居名称）且 HEADER_SPAN=3")
    void detectHeaderRow() throws Exception
    {
        try (InputStream in = getClass().getClassLoader()
                .getResourceAsStream(LargeLivestockFarmerExcelParser.TEMPLATE_CLASSPATH);
                org.apache.poi.ss.usermodel.Workbook wb = org.apache.poi.ss.usermodel.WorkbookFactory.create(in))
        {
            org.apache.poi.ss.usermodel.Sheet sheet = LargeLivestockFarmerExcelParser.resolveSheet(wb);
            assertEquals("养殖大户数据填报", sheet.getSheetName());
            int header = LargeLivestockFarmerExcelParser.detectHeaderRow(sheet);
            assertEquals(2, header);
            assertEquals(3, LargeLivestockFarmerExcelParser.HEADER_SPAN);
        }
    }
}
