import { expect, test } from 'vitest' import { Channel } from '../src/channel.js' import { Reading } from '../src/channel.js' test('channel - instantiate channel with readers correctly', () => { let now = Date.now() let mockTemp = 70 let testReader = new Reading({ onRead: () => mockTemp, unit: 'F', max: 100, min: 50, }) let testChan = new Channel({ interval: 1, reader: testReader }) // Test that the channel and channel.reader are working expect(testChan.lastUpdate == now).toStrictEqual(true) expect(testChan.val).toStrictEqual(70) expect(testChan.unit).toStrictEqual('F') mockTemp = 101 testChan = testChan.update() expect(testChan.lastUpdate > now).toStrictEqual(true) expect(testChan.val).toStrictEqual(101) expect(testChan.inRange).toStrictEqual(false) expect(testChan.aboveRange).toStrictEqual(true) expect(testChan.belowRange).toStrictEqual(false) mockTemp = 49 testChan = testChan.update() now = Date.now() expect(testChan.lastUpdate == now).toStrictEqual(true) expect(testChan.inRange).toStrictEqual(false) expect(testChan.aboveRange).toStrictEqual(false) expect(testChan.belowRange).toStrictEqual(true) })