mirror of
https://github.com/mgeeky/decode-spam-headers.git
synced 2026-02-22 05:23:31 +01:00
MAESTRO: improve standalone HTML export
This commit is contained in:
@@ -136,7 +136,7 @@ describe("ReportExport", () => {
|
||||
expect(createObjectUrlSpy).toHaveBeenCalled();
|
||||
expect(clickSpy).toHaveBeenCalled();
|
||||
expect(lastBlob).not.toBeNull();
|
||||
expect(lastBlob?.type).toBe("application/json");
|
||||
expect(lastBlob?.type).toBe("application/json;charset=utf-8");
|
||||
|
||||
const text = await lastBlob?.text();
|
||||
const parsed = JSON.parse(text ?? "{}") as AnalysisReport;
|
||||
@@ -144,7 +144,7 @@ describe("ReportExport", () => {
|
||||
expect(parsed.results[0]?.testId).toBe(101);
|
||||
});
|
||||
|
||||
it("triggers an HTML download", () => {
|
||||
it("triggers an HTML download with styled markup", async () => {
|
||||
const { container } = render(<ReportExport report={report} />);
|
||||
|
||||
const htmlButton = getByTestId(container, "report-export-html");
|
||||
@@ -155,5 +155,13 @@ describe("ReportExport", () => {
|
||||
|
||||
expect(createObjectUrlSpy).toHaveBeenCalled();
|
||||
expect(clickSpy).toHaveBeenCalled();
|
||||
expect(lastBlob?.type).toBe("text/html;charset=utf-8");
|
||||
|
||||
const text = await lastBlob?.text();
|
||||
expect(text).toContain("<!doctype html>");
|
||||
expect(text).toContain("<style>");
|
||||
expect(text).toContain("Email Header Analysis Report");
|
||||
expect(text).toContain("Summary");
|
||||
expect(text).toContain("SpamAssassin Rule Hits");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -147,6 +147,7 @@ const buildHtmlReport = (report: AnalysisReport): string => {
|
||||
background: var(--background);
|
||||
color: var(--text);
|
||||
font-family: "Geist", "Segoe UI", system-ui, sans-serif;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
main {
|
||||
@@ -162,6 +163,11 @@ const buildHtmlReport = (report: AnalysisReport): string => {
|
||||
margin: 0 0 4px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 18px;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
@@ -427,16 +433,20 @@ const downloadBlob = (content: string, mimeType: string, fileName: string) => {
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
anchor.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
window.setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
};
|
||||
|
||||
export default function ReportExport({ report }: ReportExportProps) {
|
||||
const handleJsonExport = () => {
|
||||
downloadBlob(JSON.stringify(report, null, 2), "application/json", "analysis-report.json");
|
||||
downloadBlob(
|
||||
JSON.stringify(report, null, 2),
|
||||
"application/json;charset=utf-8",
|
||||
"analysis-report.json",
|
||||
);
|
||||
};
|
||||
|
||||
const handleHtmlExport = () => {
|
||||
downloadBlob(buildHtmlReport(report), "text/html", "analysis-report.html");
|
||||
downloadBlob(buildHtmlReport(report), "text/html;charset=utf-8", "analysis-report.html");
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user