// test/02_build_scene_json.test.js const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); describe('Build Scene JSON Script', () => { const scriptPath = 'programs/02_build_scene_json.py'; const timestamp = 1778819665744; const screenshotDir = path.join(__dirname, 'data', 'screenShots'); const detectionFiles = [ 'snapshot_video0_1778819665744_aruco_detection.json', 'snapshot_video1_1778819665744_aruco_detection.json', ]; beforeEach(() => { detectionFiles.forEach((file) => { const src = path.join(screenshotDir, file); if (!fs.existsSync(src)) { throw new Error(`Missing test fixture detection file: ${src}`); } }); }); afterEach(() => { // Keep the generated scene JSON in the screenshot directory for real-world behavior. }); test('should exist and be executable', () => { expect(fs.existsSync(scriptPath)).toBe(true); }); test('should build scene JSON with timestamp parameter', () => { const cmd = `python ${scriptPath} -timestamp ${timestamp} -dir "${screenshotDir}"`; try { execSync(cmd, { stdio: 'inherit' }); } catch (error) { throw new Error(`Failed to build scene JSON: ${error.message}`); } const expectedJsonFile = path.join(screenshotDir, `scene_${timestamp}.json`); expect(fs.existsSync(expectedJsonFile)).toBe(true); const jsonData = JSON.parse(fs.readFileSync(expectedJsonFile, 'utf8')); expect(jsonData).toBeDefined(); expect(typeof jsonData).toBe('object'); expect(jsonData.cameras).toBeDefined(); expect(Object.keys(jsonData.cameras).sort()).toEqual(['0', '1']); }); test('should handle timestamp parameter correctly', () => { // Überprüfe, ob der Timestamp korrekt verarbeitet wird expect(timestamp).toBe(1778819665744); }); });