Files
appRobotHoming/test/calculateAction.01_Fetch.test.js
2026-03-30 20:33:15 +02:00

52 lines
1.5 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @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* DOMMock 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/);
});
});