52 lines
1.5 KiB
JavaScript
Executable File
52 lines
1.5 KiB
JavaScript
Executable File
/**
|
||
* @jest-environment jsdom
|
||
*/
|
||
|
||
const fs = require('fs');
|
||
const path = require('path');
|
||
|
||
describe("calculate() Snapshot-Test Fetch", () => {
|
||
|
||
let calculate;
|
||
|
||
beforeEach(() => {
|
||
// DOM vorbereiten
|
||
document.body.innerHTML = `
|
||
<textarea id="analysis-log"></textarea>
|
||
`;
|
||
|
||
// Fetch mocken, aber so, dass die CSV real geladen wird
|
||
global.fetch = jest.fn(async () => {
|
||
const csvPath = path.join(
|
||
__dirname,
|
||
"./snapshots/snapshot_video0_1774805028717_two_cam.csv"
|
||
);
|
||
|
||
const csvContent = fs.readFileSync(csvPath, "utf8");
|
||
|
||
return {
|
||
ok: true,
|
||
headers: {
|
||
get: () => "text/csv"
|
||
},
|
||
text: async () => csvContent
|
||
};
|
||
});
|
||
|
||
// Modul *nach* DOM‑Mock laden!
|
||
({ calculate } = require("../public/calculateActions.js"));
|
||
});
|
||
|
||
test("calculate() lädt Snapshot über fetch()", async () => {
|
||
|
||
await calculate(); // 👉 Aufruf, fetch wird getriggert
|
||
|
||
// Nur erster Check: wurde fetch überhaupt aufgerufen?
|
||
expect(global.fetch).toHaveBeenCalledWith("/api/latest-snapshot");
|
||
|
||
// Und die Log-Ausgabe wurde befüllt?
|
||
const logValue = document.getElementById("analysis-log").value;
|
||
expect(logValue).toMatch(/Starte Berechnung/);
|
||
});
|
||
|
||
}); |