| 1234567891011121314151617181920212223242526272829303132333435 |
- import { expect, test } from 'vitest'
- import { updateChannel, Channel, Reading } from '../src/core/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 = updateChannel(testChan)
- 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 = updateChannel(testChan)
- now = Date.now()
- expect(testChan.lastUpdate == now).toStrictEqual(true)
- expect(testChan.inRange).toStrictEqual(false)
- expect(testChan.aboveRange).toStrictEqual(false)
- expect(testChan.belowRange).toStrictEqual(true)
- })
|