diff --git a/test/calculateAction.02_FetchDifferentCSV.test.js b/test/calculateAction.02_FetchDifferentCSV.test.js index 120907f..b295918 100755 --- a/test/calculateAction.02_FetchDifferentCSV.test.js +++ b/test/calculateAction.02_FetchDifferentCSV.test.js @@ -89,7 +89,8 @@ describe("calculate() Snapshot Tests", () => { var valueDeg = result.features["forearm.angleZ"].valueDeg - //expect(valueDeg).toBeCloseTo(0, 10); // Erwartet ca. -137.28° mit 1 Dezimalstelle Genauigkeit + // expect(valueDeg).toBeCloseTo(7.4595, 1); // Erwartet ca. -137.28° mit 1 Dezimalstelle Genauigkeit + //expect(logValue).toMatch(/Starte Berechnung/); //expect(logValue).toMatch(/CSV-Daten geladen/); }); diff --git a/test/calculateAction.03_EasyCSV.test.js b/test/calculateAction.03_EasyCSV.test.js new file mode 100644 index 0000000..64fa65e --- /dev/null +++ b/test/calculateAction.03_EasyCSV.test.js @@ -0,0 +1,53 @@ +/** + * @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 = ` + + `; + + // 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 1775406055428 wird korrekt geladen", async () => { + + snapshotFile = "snapshot_video0_1775406055428_two_cam.csv"; + + var result = await calculate(); + + expect(global.fetch).toHaveBeenCalledWith("/api/latest-snapshot"); + + //console.log("Berechnungsergebnis:", result.features["forearm.angleZ"].valueDeg); + const r = result.features["forearm.angleZ"].valueDeg + expect(r).toBeCloseTo(131.3436, 1); + }); +}); \ No newline at end of file diff --git a/test/snapshots/snapshot_video0_1775406055428.jpg b/test/snapshots/snapshot_video0_1775406055428.jpg new file mode 100644 index 0000000..1d070bc Binary files /dev/null and b/test/snapshots/snapshot_video0_1775406055428.jpg differ diff --git a/test/snapshots/snapshot_video0_1775406055428_two_cam.csv b/test/snapshots/snapshot_video0_1775406055428_two_cam.csv new file mode 100644 index 0000000..4cf4328 --- /dev/null +++ b/test/snapshots/snapshot_video0_1775406055428_two_cam.csv @@ -0,0 +1,20 @@ +id,x_mm,y_mm,z_mm,roll_deg,pitch_deg,yaw_deg,seen_by +camera 0,20.57,-610.52,589.07,-122.982,0.983,-21.216 +camera 1,285.64,-323.91,1175.28,-163.532,-2.871,-2.320 +197,294.33,-107.10,42.66,24.178,87.583,-153.262,1 +198,322.36,-51.62,105.51,-4.006,2.569,0.264,3 +200,253.83,-32.23,119.85,1.613,0.280,1.853,3 +201,229.66,88.35,77.42,54.528,62.860,30.165,1 +204,255.24,119.60,126.69,0.415,2.861,0.328,3 +205,853.43,-61.26,-149.90,20.853,-37.717,-9.272,2 +207,847.45,33.87,-129.33,1.040,-7.604,-2.451,2 +208,506.94,-73.83,-90.70,22.575,-11.879,-0.931,2 +210,-2.98,-0.29,-1.22,-1.583,0.163,0.432,3 +211,199.83,-0.12,-0.03,0.528,1.427,-0.276,3 +215,199.72,-90.28,-0.47,-0.349,-0.487,-0.415,3 +217,593.42,4.85,-8.36,115.523,-38.198,-61.266,3 +218,392.41,-89.81,171.69,-56.876,7.958,168.535,3 +219,397.44,-21.62,249.19,-58.657,26.538,137.623,3 +222,411.95,-166.81,94.12,-51.900,-3.795,-176.339,3 +229,324.14,-141.95,110.20,-4.029,2.223,0.193,3 +243,341.92,-141.96,39.90,89.294,1.545,1.379,1 diff --git a/test/snapshots/snapshot_video0_1775406055428_two_cam.json b/test/snapshots/snapshot_video0_1775406055428_two_cam.json new file mode 100644 index 0000000..e3f6398 --- /dev/null +++ b/test/snapshots/snapshot_video0_1775406055428_two_cam.json @@ -0,0 +1,266 @@ +{ + "metadata": { + "timestamp": "2026-04-05 16:20:55", + "reference_markers": [ + 210, + 211, + 215 + ], + "dict": "DICT_4X4_250", + "marker_size_mm": 25.0, + "rms_refs_px_cam1": 3.254055063488035, + "rms_refs_px_cam2": 2.329978520523634, + "description": "Two-camera joint optimization with triangulation" + }, + "cameras": [ + { + "id": "camera1", + "position_mm": [ + 20.567992853963712, + -610.5178800181857, + 589.0698645481658 + ], + "orientation_deg": { + "roll": -122.98164282878035, + "pitch": 0.9825995865612873, + "yaw": -21.215599879804127 + } + }, + { + "id": "camera2", + "position_mm": [ + 285.63593460306214, + -323.91360133208565, + 1175.2847066246202 + ], + "orientation_deg": { + "roll": -163.5318691962207, + "pitch": -2.8712676709036873, + "yaw": -2.319894538293139 + } + } + ], + "markers": [ + { + "id": 197, + "position_mm": [ + 294.33174809359764, + -107.09776686381556, + 42.657521092593576 + ], + "orientation_deg": { + "roll": 24.177685786502696, + "pitch": 87.58261710989703, + "yaw": -153.26161785260203 + } + }, + { + "id": 198, + "position_mm": [ + 322.35528564453125, + -51.62440872192383, + 105.50933074951172 + ], + "orientation_deg": { + "roll": -4.0056133311584, + "pitch": 2.5694651141051086, + "yaw": 0.2642697205016838 + } + }, + { + "id": 200, + "position_mm": [ + 253.8253936767578, + -32.23002624511719, + 119.85144805908203 + ], + "orientation_deg": { + "roll": 1.6127513507983577, + "pitch": 0.28021370340515495, + "yaw": 1.8527495496984367 + } + }, + { + "id": 201, + "position_mm": [ + 229.66471968685903, + 88.34733189894173, + 77.41605123374995 + ], + "orientation_deg": { + "roll": 54.52810378585272, + "pitch": 62.8599359935973, + "yaw": 30.165344197733074 + } + }, + { + "id": 204, + "position_mm": [ + 255.2445831298828, + 119.60195922851562, + 126.68728637695312 + ], + "orientation_deg": { + "roll": 0.4145305769690522, + "pitch": 2.860736864204838, + "yaw": 0.32845819664980447 + } + }, + { + "id": 205, + "position_mm": [ + 853.431005136878, + -61.25721442245891, + -149.89679670473998 + ], + "orientation_deg": { + "roll": 20.852865291435734, + "pitch": -37.71692833356208, + "yaw": -9.272061737418596 + } + }, + { + "id": 207, + "position_mm": [ + 847.4521233610369, + 33.873936675138275, + -129.32930925154884 + ], + "orientation_deg": { + "roll": 1.0401371636363885, + "pitch": -7.6044864818447975, + "yaw": -2.450876228459906 + } + }, + { + "id": 208, + "position_mm": [ + 506.93763250636556, + -73.82927207192274, + -90.70161319207948 + ], + "orientation_deg": { + "roll": 22.574697007159163, + "pitch": -11.878815029635385, + "yaw": -0.930861116435157 + } + }, + { + "id": 210, + "position_mm": [ + -2.9841384887695312, + -0.2894434630870819, + -1.2217036485671997 + ], + "orientation_deg": { + "roll": -1.5829030552869041, + "pitch": 0.16287337882520173, + "yaw": 0.4319764191460346 + } + }, + { + "id": 211, + "position_mm": [ + 199.83383178710938, + -0.11946921795606613, + -0.029889743775129318 + ], + "orientation_deg": { + "roll": 0.5280528898583173, + "pitch": 1.42715303979363, + "yaw": -0.2762037188762131 + } + }, + { + "id": 215, + "position_mm": [ + 199.71726989746094, + -90.28231048583984, + -0.47207993268966675 + ], + "orientation_deg": { + "roll": -0.34887731639439074, + "pitch": -0.4866200044208423, + "yaw": -0.4154891149763061 + } + }, + { + "id": 217, + "position_mm": [ + 593.4248657226562, + 4.84699010848999, + -8.357927322387695 + ], + "orientation_deg": { + "roll": 115.52338058003483, + "pitch": -38.1982958889267, + "yaw": -61.26648945435826 + } + }, + { + "id": 218, + "position_mm": [ + 392.41168212890625, + -89.81021881103516, + 171.6865997314453 + ], + "orientation_deg": { + "roll": -56.87609794413502, + "pitch": 7.9576512305228695, + "yaw": 168.53487924220425 + } + }, + { + "id": 219, + "position_mm": [ + 397.4364013671875, + -21.623811721801758, + 249.1935577392578 + ], + "orientation_deg": { + "roll": -58.65730680858089, + "pitch": 26.538451116793357, + "yaw": 137.6231555522311 + } + }, + { + "id": 222, + "position_mm": [ + 411.9534606933594, + -166.8076629638672, + 94.11588287353516 + ], + "orientation_deg": { + "roll": -51.89961208258986, + "pitch": -3.794728013253899, + "yaw": -176.3389557230221 + } + }, + { + "id": 229, + "position_mm": [ + 324.13897705078125, + -141.9525909423828, + 110.19646453857422 + ], + "orientation_deg": { + "roll": -4.029478015347812, + "pitch": 2.2227848455796204, + "yaw": 0.19265697941371004 + } + }, + { + "id": 243, + "position_mm": [ + 341.92465540725135, + -141.9580916788701, + 39.89962774242517 + ], + "orientation_deg": { + "roll": 89.29427272560588, + "pitch": 1.545160298154013, + "yaw": 1.3793023005400504 + } + } + ] +} \ No newline at end of file diff --git a/test/snapshots/snapshot_video0_1775406055428_two_cam_annotated.jpg b/test/snapshots/snapshot_video0_1775406055428_two_cam_annotated.jpg new file mode 100644 index 0000000..ebf02b5 Binary files /dev/null and b/test/snapshots/snapshot_video0_1775406055428_two_cam_annotated.jpg differ diff --git a/test/snapshots/snapshot_video0_1775406055428_two_cam_overlay.png b/test/snapshots/snapshot_video0_1775406055428_two_cam_overlay.png new file mode 100644 index 0000000..9b7af29 Binary files /dev/null and b/test/snapshots/snapshot_video0_1775406055428_two_cam_overlay.png differ diff --git a/test/snapshots/snapshot_video1_1775406055428.jpg b/test/snapshots/snapshot_video1_1775406055428.jpg new file mode 100644 index 0000000..bfb9668 Binary files /dev/null and b/test/snapshots/snapshot_video1_1775406055428.jpg differ diff --git a/test/snapshots/snapshot_video1_1775406055428_two_cam_annotated.jpg b/test/snapshots/snapshot_video1_1775406055428_two_cam_annotated.jpg new file mode 100644 index 0000000..85f7203 Binary files /dev/null and b/test/snapshots/snapshot_video1_1775406055428_two_cam_annotated.jpg differ diff --git a/test/snapshots/snapshot_video1_1775406055428_two_cam_overlay.png b/test/snapshots/snapshot_video1_1775406055428_two_cam_overlay.png new file mode 100644 index 0000000..a5cb0a8 Binary files /dev/null and b/test/snapshots/snapshot_video1_1775406055428_two_cam_overlay.png differ