'use strict'; const state = require('../src/state'); describe('state', () => { test('set and get round-trip', () => { state.set('input-1', { value: 24.5, unit: '°C', moduleId: 'mod-a', moduleSlug: 'lrpc_abc', metric: 'temperature', timestamp: '2026-01-01T00:00:00Z' }); const entry = state.get('input-1'); expect(entry.value).toBe(24.5); expect(entry.unit).toBe('°C'); }); test('getAll returns all entries', () => { state.set('input-2', { value: 7.2, unit: 'pH', moduleId: 'mod-b', moduleSlug: 'lrps_xyz', metric: 'ph', timestamp: '2026-01-01T00:00:00Z' }); const all = state.getAll(); expect(all['input-1']).toBeDefined(); expect(all['input-2']).toBeDefined(); }); test('getByModule filters by moduleId', () => { const byMod = state.getByModule('mod-a'); expect(Object.keys(byMod)).toContain('input-1'); expect(Object.keys(byMod)).not.toContain('input-2'); }); test('inputCount returns store size', () => { expect(state.inputCount()).toBeGreaterThanOrEqual(2); }); test('get returns null for unknown inputId', () => { expect(state.get('does-not-exist')).toBeNull(); }); test('update event fires on set', done => { state.on('update', (id, entry) => { if (id === 'input-event-test') { expect(entry.value).toBe(999); done(); } }); state.set('input-event-test', { value: 999, moduleId: 'x', moduleSlug: 's', metric: 'm', timestamp: '' }); }); });