Test mit Jest

Das AI generierte mocking ignorieren, und sauber, wie davor.
This commit is contained in:
chk
2026-05-12 20:40:21 +02:00
parent ba2cc8f6ec
commit 3fa1f76413
6 changed files with 96 additions and 79 deletions

View File

@@ -1,41 +0,0 @@
const fs = require('fs');
const path = require('path');
const { calculate } = require('../public/calculateAngles.cjs');
/* -------------------------
Tests
------------------------- */
describe('calculateAngles.calculate', () => {
test('berechnet X-Durchschnitt für Base / Arm1 / Joint1', async () => {
//const markersPath = path.resolve('./test/snapshots/snapshot_video0_1774805028717_two_cam.json');
const markersPath = path.resolve('./test/snapshots/snapshot_video0_1775406055428_two_cam.json');
const robotPath = path.resolve('./public/robot.json');
const foundMarkers = JSON.parse(fs.readFileSync(markersPath, 'utf8'));
const jsonRobot = JSON.parse(fs.readFileSync(robotPath, 'utf8'));
const result = await calculate(foundMarkers, jsonRobot);
expect(result.status).toBe('ok');
expect(result.result).toBeDefined();
});
});
describe('calculateAngles.y', () => {
test('berechnet y-Durchschnitt für Base / Arm1 / Joint1', async () => {
const markersPath = path.resolve('./test/snapshots/snapshot_video0_1778407171886_two_cam.json');
const robotPath = path.resolve('./public/robot.json');
const foundMarkers = JSON.parse(fs.readFileSync(markersPath, 'utf8'));
const jsonRobot = JSON.parse(fs.readFileSync(robotPath, 'utf8'));
const result = await calculate(foundMarkers, jsonRobot);
expect(result.status).toBe('ok');
expect(result.result).toBeDefined();
});
});

View File

@@ -0,0 +1,50 @@
/**
* @jest-environment jsdom
*/
const fs = require("fs");
const path = require("path");
describe("calculate() row223 Ellbow-Rotation Tests", () => {
let calculate;
let optimizeRobot;
beforeEach(() => {
// DOM erzeugen
document.body.innerHTML = `<textarea id="analysis-log"></textarea>`;
// Fetch mocken - wird pro Test konfiguriert
global.fetch = jest.fn();
// Modul erst JETZT laden (DOM existiert)
({ calculate, optimizeRobot} = require("../public/calculateAngles.js"));
});
test('berechnet y-Durchschnitt für Base / Arm1 / Joint1', async () => {
const markersPath = path.resolve('./test/snapshots/snapshot_video0_1778407171886_two_cam.json');
const robotPath = path.resolve('./public/robot.json');
const foundMarkers = JSON.parse(fs.readFileSync(markersPath, 'utf8'));
const jsonRobot = JSON.parse(fs.readFileSync(robotPath, 'utf8'));
const result = await calculate(foundMarkers, jsonRobot);
expect(result.status).toBe('ok');
expect(result.result).toBeDefined();
});
test('berechnet X-Durchschnitt für Base / Arm1 / Joint1', async () => {
const markersPath = path.resolve('./test/snapshots/snapshot_video0_1775406055428_two_cam.json');
const robotPath = path.resolve('./public/robot.json');
const foundMarkers = JSON.parse(fs.readFileSync(markersPath, 'utf8'));
const jsonRobot = JSON.parse(fs.readFileSync(robotPath, 'utf8'));
const result = await calculate(foundMarkers, jsonRobot);
expect(result.status).toBe('ok');
expect(result.result).toBeDefined();
});
});

View File

@@ -1,14 +1,27 @@
const fs = require('fs');
const path = require('path');
const { calculate, optimizeRobot } = require('../public/calculateAngles.cjs');
/**
* @jest-environment jsdom
*/
const fs = require("fs");
const path = require("path");
describe("calculate() row223 Ellbow-Rotation Tests", () => {
let calculate;
let optimizeRobot;
beforeEach(() => {
// DOM erzeugen
document.body.innerHTML = `<textarea id="analysis-log"></textarea>`;
// Fetch mocken - wird pro Test konfiguriert
global.fetch = jest.fn();
// Modul erst JETZT laden (DOM existiert)
({ calculate, optimizeRobot} = require("../public/calculateAngles.js"));
});
/* -------------------------
Tests
------------------------- */
describe('optimizeRobot.', () => {
test('berechnet X-Durchschnitt für Base / Arm1 / Joint1', async () => {
//const markersPath1 = path.resolve('./test/snapshots/snapshot_video0_1777958128576_two_cam.json');
const markersPath1 = path.resolve('./test/snapshots/snapshot_video0_1778406635059_two_cam.json');
@@ -28,7 +41,7 @@ describe('optimizeRobot.', () => {
const result = await optimizeRobot(list, jsonRobot);
//expect(result.status).toBe('ok');
//expect(result.result).toBeDefined();
expect(result.status).toBe('ok');
expect(result.result).toBeDefined();
});
});