task(CAD-14): phase 4a - tool options store + panel (optionsSchema-driven UI in right sidebar, dispatcher getOptions wired, registry defaults seeded) - truss options length/chordCount/angle now actually reach the tools
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* CAD-14 Phase 4a: toolOptionsService — zentraler Store fuer
|
||||
* Werkzeug-Optionen (Laenge, Breite, chordCount, Winkel...).
|
||||
* Quelle der Defaults: optionsSchema der V2-Werkzeuge.
|
||||
* Der InteractionDispatcher liest darueber getOptions.
|
||||
*/
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import {
|
||||
getToolOption,
|
||||
setToolOption,
|
||||
getToolOptions,
|
||||
resetToolOptions,
|
||||
subscribeToolOptions,
|
||||
defaultsFromSchema,
|
||||
setToolOptionsDefaults,
|
||||
} from '../src/services/toolOptionsService';
|
||||
|
||||
describe('CAD-14 Phase 4a: toolOptionsService', () => {
|
||||
beforeEach(() => {
|
||||
resetToolOptions();
|
||||
});
|
||||
|
||||
it('defaultsFromSchema: leitet Defaults aus optionsSchema ab', () => {
|
||||
const defaults = defaultsFromSchema([
|
||||
{ key: 'length', label: 'Länge', type: 'number', min: 10, max: 1000 },
|
||||
{ key: 'chordCount', label: 'Gurtrohre', type: 'number', min: 1, max: 4 },
|
||||
] as never);
|
||||
// number ohne expliziten default: min clamped auf sinnvollen Start
|
||||
expect(defaults.length).toBeDefined();
|
||||
expect(defaults.chordCount).toBeDefined();
|
||||
});
|
||||
|
||||
it('set/get: Wert wird gespeichert und gelesen', () => {
|
||||
setToolOption('truss', 'length', 175);
|
||||
expect(getToolOption('truss', 'length')).toBe(175);
|
||||
});
|
||||
|
||||
it('getToolOption ohne Set: default aus Schema (defaultsFromSchema)', () => {
|
||||
setToolOptionsDefaults('truss', { length: 200, chordCount: 2, trussWidth: 29 });
|
||||
expect(getToolOption('truss', 'length')).toBe(200);
|
||||
expect(getToolOption('truss', 'chordCount')).toBe(2);
|
||||
});
|
||||
|
||||
it('getToolOptions liefert Gesamtsatz (defaults + gesetzte Werte)', () => {
|
||||
setToolOptionsDefaults('truss', { length: 200, trussWidth: 29 });
|
||||
setToolOption('truss', 'length', 300);
|
||||
const all = getToolOptions('truss');
|
||||
expect(all.length).toBe(300);
|
||||
expect(all.trussWidth).toBe(29);
|
||||
});
|
||||
|
||||
it('subscribe: Benachrichtigung bei Änderung (UI-Update)', () => {
|
||||
let notified = 0;
|
||||
const unsub = subscribeToolOptions(() => { notified++; });
|
||||
setToolOption('truss', 'length', 250);
|
||||
unsub();
|
||||
setToolOption('truss', 'length', 260);
|
||||
expect(notified).toBe(1);
|
||||
});
|
||||
|
||||
it('resetToolOptions leert alles', () => {
|
||||
setToolOptionsDefaults('truss', { length: 200 });
|
||||
resetToolOptions();
|
||||
expect(getToolOption('truss', 'length', 99)).toBe(99);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user