import { expect, test } from 'vitest' import { Channel, Reading } from '../src/core/channel' import { Controller } from '../src/controller' test('controller - updates correctly', () => { let mockTemp = 70 let testReader = new Reading({ onRead: () => mockTemp, unit: 'F', max: 100, min: 50, }) let testChan = new Channel({ interval: 1, reader: testReader }) const testController = new Controller({ type: 'blah', channel: testChan, }) expect(testController.inRange).toBe(true) mockTemp = 101 testController.update() expect(testController.inRange).toBe(false) testController.onUpdate = foo => 'foo' expect(testController.onUpdate('bar')).toBe('foo') }) test('controller - onUpdate overloading works', () => { let mockTemp = 70 let testReader = new Reading({ onRead: () => mockTemp, unit: 'F', max: 100, min: 50, }) let testChan = new Channel({ interval: 1, reader: testReader }) const testController = new Controller({ type: 'blah', channel: testChan, }) testController.onUpdate = foo => 'foo' expect(testController.onUpdate('bar')).toBe('foo') })