Tests
This commit is contained in:
69
test/calculateAction.02_FetchDifferentCSV.test.js
Executable file
69
test/calculateAction.02_FetchDifferentCSV.test.js
Executable file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
describe("calculate() Snapshot Tests", () => {
|
||||
|
||||
let calculate;
|
||||
let snapshotFile;
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
// Standard: irgendeine Datei setzen, falls Test nichts setzt
|
||||
snapshotFile = "snapshot_default.csv";
|
||||
|
||||
// DOM erzeugen
|
||||
document.body.innerHTML = `
|
||||
<textarea id="analysis-log"></textarea>
|
||||
`;
|
||||
|
||||
// Fetch dynamisch mocken
|
||||
global.fetch = jest.fn(async () => {
|
||||
|
||||
const csvPath = path.join(__dirname, "snapshots", snapshotFile);
|
||||
const csvContent = fs.readFileSync(csvPath, "utf8");
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
headers: { get: () => "text/csv" },
|
||||
text: async () => csvContent
|
||||
};
|
||||
});
|
||||
|
||||
// Modul erst JETZT laden (DOM existiert)
|
||||
({ calculate } = require("../public/calculateActions.js"));
|
||||
});
|
||||
|
||||
// ✅ Beispiel 1: Die Datei aus deiner Frage
|
||||
test("Snapshot 1774805028717 wird korrekt geladen", async () => {
|
||||
|
||||
snapshotFile = "snapshot_video0_1774805028717_two_cam.csv";
|
||||
|
||||
await calculate();
|
||||
|
||||
expect(global.fetch).toHaveBeenCalledWith("/api/latest-snapshot");
|
||||
|
||||
const logValue = document.getElementById("analysis-log").value;
|
||||
expect(logValue).toMatch(/Starte Berechnung/);
|
||||
expect(logValue).toMatch(/CSV-Daten geladen/);
|
||||
});
|
||||
|
||||
|
||||
test("Snapshot 1774805028717 wird korrekt geladen", async () => {
|
||||
|
||||
snapshotFile = "snapshot_video0_1774805686335_two_cam.csv";
|
||||
|
||||
await calculate();
|
||||
|
||||
expect(global.fetch).toHaveBeenCalledWith("/api/latest-snapshot");
|
||||
|
||||
const logValue = document.getElementById("analysis-log").value;
|
||||
console.log("Log Value:", logValue);
|
||||
//expect(logValue).toMatch(/Starte Berechnung/);
|
||||
//expect(logValue).toMatch(/CSV-Daten geladen/);
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user