Files
filebrowser/frontend/src/utils/__tests__/dicom-diagnostics.test.ts
T

41 lines
1.4 KiB
TypeScript

import { afterEach, expect, it, vi } from "vitest";
import {
dicomLimitExceeded,
logDicomSeries,
logDicomVolumeEstimate,
} from "../dicom-diagnostics";
afterEach(() => vi.restoreAllMocks());
it("reports source bytes separately from the 768-slice decoded estimate", () => {
const info = vi.spyOn(console, "info").mockImplementation(() => {});
const files = Array.from({ length: 768 }, () => ({
name: "private.dcm",
source: "/private?token=secret",
size: 2 * 1024 * 1024,
}));
expect(logDicomSeries(files).sourceBytes).toBe(1.5 * 1024 ** 3);
expect(logDicomVolumeEstimate(512, 512, 768)).toBe(0.75 * 1024 ** 3);
expect(info.mock.calls[0][1]).toMatchObject({
fileCount: 768,
sourceBytes: 1610612736,
});
expect(info.mock.calls[1][1]).toMatchObject({
dimensions: [512, 512, 768],
decodedBytes: 805306368,
});
expect(JSON.stringify(info.mock.calls)).not.toMatch(/private|secret/);
});
it("logs the precise failing limit before preserving the existing error code", () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
expect(() =>
dicomLimitExceeded(
"total source bytes (directory listing)",
1610612736,
1073741824
)
).toThrow("DICOM_VOLUME_LIMIT");
expect(warn).toHaveBeenCalledWith(
expect.stringContaining("total source bytes"),
expect.objectContaining({ actual: 1610612736, limit: 1073741824 })
);
});