package cn.yunzhixue.ability.center.examsprint.infrastructure.report.rendering.achievement;

import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import static org.assertj.core.api.Assertions.assertThat;

class AchievementExamSprintReportTemplateCompatibilityTest {

    private static final String REPORT_FONT_STACK = "'MiSans VF', MiSans, ReportFont, sans-serif";

    @Test
    void templateUsesRealBundledFontFamilyBeforeAliases() throws Exception {
        String normalizedTemplate = normalizeWhitespace(loadTemplate());

        assertThat(normalizedTemplate)
                .contains("font-family: " + REPORT_FONT_STACK)
                .doesNotContain("font-family: MiSans, ReportFont, sans-serif");
    }

    private String loadTemplate() throws Exception {
        ClassPathResource resource = new ClassPathResource("templates/achievement-exam-sprint-report-template.html");
        try (InputStream inputStream = resource.getInputStream()) {
            return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
        }
    }

    private String normalizeWhitespace(String value) {
        return value.replaceAll("\\s+", " ").trim();
    }
}
