Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

channel.spec.js 1.2KB

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