package com.njcn.gather.aireport.testreport.component;

import com.njcn.gather.aireport.testreport.pojo.constant.TestReportConst;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.util.Arrays;
import java.util.List;

class TestReportLedgerTemplateServiceTest {

    @Test
    void shouldBuildTemplateWithRequiredSheets() throws Exception {
        TestReportLedgerTemplateService service = new TestReportLedgerTemplateService();

        byte[] content = service.buildTemplate();

        try (XSSFWorkbook workbook = new XSSFWorkbook(new ByteArrayInputStream(content))) {
            Assertions.assertNotNull(workbook.getSheet(TestReportConst.LEDGER_GUIDE_SHEET_NAME));
            Assertions.assertNotNull(workbook.getSheet(TestReportConst.LEDGER_POINT_SHEET_NAME));
            Assertions.assertNotNull(workbook.getSheet(TestReportConst.LEDGER_DEVICE_SHEET_NAME));
            Assertions.assertNotNull(workbook.getSheet(TestReportConst.LEDGER_CLIENT_SHEET_NAME));
            List<String> expectedHeaders = Arrays.asList(
                    "分组号", "变电站", "监测点名称", "检测设备编号", "委托单位名称", "Excel附件名称", "Word附件名称");
            for (int i = 0; i < expectedHeaders.size(); i++) {
                Assertions.assertEquals(expectedHeaders.get(i),
                        workbook.getSheet(TestReportConst.LEDGER_POINT_SHEET_NAME).getRow(0).getCell(i).getStringCellValue());
            }
            Assertions.assertNull(workbook.getSheet(TestReportConst.LEDGER_POINT_SHEET_NAME).getRow(0).getCell(expectedHeaders.size()));
        }
    }
}
