You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

channel.spec.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { expect, test } from 'vitest'
  2. import { Channel } from '../src/channel.js'
  3. import { Reading } from '../src/channel.js'
  4. test('channel - instantiate channel with readers correctly', () => {
  5. let now = Date.now()
  6. let mockTemp = 70
  7. let testReader = new Reading({
  8. onRead: () => mockTemp,
  9. unit: 'F',
  10. max: 100,
  11. min: 50,
  12. })
  13. let testChan = new Channel({ interval: 1, reader: testReader })
  14. // Test that the channel and channel.reader are working
  15. expect(testChan.lastUpdate == now).toStrictEqual(true)
  16. expect(testChan.val).toStrictEqual(70)
  17. expect(testChan.unit).toStrictEqual('F')
  18. mockTemp = 101
  19. testChan = testChan.update()
  20. expect(testChan.lastUpdate > now).toStrictEqual(true)
  21. expect(testChan.val).toStrictEqual(101)
  22. expect(testChan.inRange).toStrictEqual(false)
  23. expect(testChan.aboveRange).toStrictEqual(true)
  24. expect(testChan.belowRange).toStrictEqual(false)
  25. mockTemp = 49
  26. testChan = testChan.update()
  27. now = Date.now()
  28. expect(testChan.lastUpdate == now).toStrictEqual(true)
  29. expect(testChan.inRange).toStrictEqual(false)
  30. expect(testChan.aboveRange).toStrictEqual(false)
  31. expect(testChan.belowRange).toStrictEqual(true)
  32. })