/** * #122: lo zoom delle tre viste del wizard (immagine, DXF, Prova) e' nel componente . * Qui si prova cio' che resta nel wizard (dimensioni dal detail di viewer-load, anteprima DXF) * e che le funzioni di zoom/pan/fit/overlay non ci siano piu'. * (Il nome del file resta quello di #113 per non rompere i riferimenti.) * * Run from src/frontend/flask_app: node tests/js/test_dxf_zoom.js */ 'use strict'; const fs = require('fs'); const path = require('path'); global.document = { documentElement: { lang: 'it' } }; const src = fs.readFileSync( path.join(__dirname, '..', '..', 'static', 'js', 'dxf_recipe_wizard.js'), 'utf8', ); eval(src + ';global.dxfRecipeWizard = dxfRecipeWizard;'); let failures = 0; function check(label, cond, extra) { if (cond) console.log('ok - ' + label); else { failures++; console.log('FAIL - ' + label + (extra ? ' :: ' + extra : '')); } } const w = dxfRecipeWizard(1, () => 'tok', {}); w.$nextTick = fn => fn(); // #122: via tutto lo zoom/pan/fit/overlay del wizard const gone = ['views', 'viewPanKey', 'zoom', 'fitZoom', 'panning', 'resPx', 'vZoomBy', 'vFit', 'vWheel', 'vPanDown', 'vPanMove', 'vPanEnd', 'vCursor', 'vPct', 'vW', 'vH', 'vReset', 'vSetContent', 'zoomBy', 'fit', 'onWheel', 'onPanDown', 'onPanMove', 'onPanEnd', 'onResultImgLoad', 'drawOverlay', 'zoomPct', 'zoomW', 'zoomH', 'vpHeight']; for (const k of gone) check('#122 tolto dal wizard: ' + k, !(k in w)); check('#122 sorgente senza $refs di zoom', !/\$refs\./.test(src)); // onImagePreviewLoad riceve il detail di viewer-load e alimenta il riepilogo global.URL.createObjectURL = () => 'blob:x'; global.URL.revokeObjectURL = () => {}; w._setImage({ name: 'a.bmp' }, 'file'); w.onImagePreviewLoad({ width: 800, height: 240 }); check('#122 viewer-load: dimensioni nel riepilogo', w.imagePx.w === 800 && w.imagePx.h === 240 && w.imageBroken === false); check('#122 riepilogo «W × H px»', /800.*240 px/.test(w.imagePreviewSummary), w.imagePreviewSummary); w.onImagePreviewLoad({ width: 0, height: 0 }); check('#122 viewer-load senza dimensioni: imagePx null', w.imagePx === null); w.onImagePreviewLoad({ width: 800, height: 240 }); w.onImagePreviewError(); check('#122 errore immagine: avviso e dimensioni azzerate', w.imageBroken === true && w.imagePx === null); w._setImage({ name: 'b.bmp' }, 'file'); check('#122 nuova immagine: avviso tolto', w.imageBroken === false && w.imagePx === null); w._setImage(null); check('#122 immagine tolta: src vuoto', w.imageSrc === '' && w.imagePreviewUrl === ''); // Anteprima DXF: il viewBox resta quello per il (width/height del template) (async () => { const PREVIEW = { contorni: [[[0, 0], [20, 0], [20, 10]]], bbox: { xmin: 0, ymin: 0, xmax: 20, ymax: 10 }, larghezza_mm: 20, altezza_mm: 10, entita: 1, punti: 3, }; global.FormData = class { append() {} }; global.fetch = async () => ({ ok: true, json: async () => PREVIEW }); const wd = dxfRecipeWizard(1, () => 'tok', {}); wd.$nextTick = fn => fn(); wd.dxfFile = { name: 'a.dxf' }; await wd.loadDxfPreview(); const vb = wd.dxfPreviewViewBox().split(' ').map(Number); check('#122 DXF: viewBox con margine 5 % (w 22 x h 12)', vb.length === 4 && Math.abs(vb[2] - 22) < 1e-6 && Math.abs(vb[3] - 12) < 1e-6, vb.join(' ')); check('#122 DXF: anteprima caricata', wd.dxfPreview && wd.dxfPreviewD().startsWith('M 0 0')); wd.dxfFile = null; await wd.loadDxfPreview(); check('#122 DXF tolto: anteprima azzerata', wd.dxfPreview === null && wd.dxfPreviewViewBox() === '0 0 1 1'); if (failures) { console.log(failures + ' test falliti'); process.exit(1); } console.log('tutti i test #122 ok'); })();