MAESTRO: validate JSON export content

This commit is contained in:
Mariusz Banach
2026-02-18 03:14:58 +01:00
parent 034a7f7d8c
commit 65f294de59
2 changed files with 15 additions and 3 deletions

View File

@@ -53,7 +53,7 @@ ReportContainer
- [x] Hop chain displays as a vertical visual flow with server details and connecting arrows
- [x] Security appliances show as badges; empty state handled gracefully
- [x] Search filters results in real-time across test name, header name, and analysis text
- [ ] Export JSON produces a valid JSON file containing all results
- [x] Export JSON produces a valid JSON file containing all results
- [ ] Export HTML produces a styled standalone page viewable in any browser
- [ ] All report components are keyboard accessible
- [ ] Linting passes (`npx eslint src/`, `npx prettier --check src/`)

View File

@@ -74,6 +74,7 @@ const report: AnalysisReport = {
let createObjectUrlSpy: ReturnType<typeof vi.spyOn> | null = null;
let revokeObjectUrlSpy: ReturnType<typeof vi.spyOn> | null = null;
let clickSpy: ReturnType<typeof vi.spyOn> | null = null;
let lastBlob: Blob | null = null;
const originalUrlStatics: UrlStatics = {
createObjectURL: (URL as unknown as UrlStatics).createObjectURL,
@@ -90,9 +91,13 @@ beforeEach(() => {
urlStatics.revokeObjectURL = () => undefined;
}
lastBlob = null;
createObjectUrlSpy = vi
.spyOn(URL, "createObjectURL")
.mockReturnValue("blob:report");
.mockImplementation((blob: Blob) => {
lastBlob = blob;
return "blob:report";
});
revokeObjectUrlSpy = vi.spyOn(URL, "revokeObjectURL").mockImplementation(() => {
return undefined;
});
@@ -119,7 +124,7 @@ afterEach(() => {
});
describe("ReportExport", () => {
it("triggers a JSON download", () => {
it("triggers a JSON download", async () => {
const { container } = render(<ReportExport report={report} />);
const jsonButton = getByTestId(container, "report-export-json");
@@ -130,6 +135,13 @@ describe("ReportExport", () => {
expect(createObjectUrlSpy).toHaveBeenCalled();
expect(clickSpy).toHaveBeenCalled();
expect(lastBlob).not.toBeNull();
expect(lastBlob?.type).toBe("application/json");
const text = await lastBlob?.text();
const parsed = JSON.parse(text ?? "{}") as AnalysisReport;
expect(parsed.results).toHaveLength(1);
expect(parsed.results[0]?.testId).toBe(101);
});
it("triggers an HTML download", () => {