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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { expect, test } from 'vitest'
  2. import { System, makeContainerT } from '../src/system.js'
  3. import { Reading } from '../src/channel.js'
  4. import { Container } from '../src/container.js'
  5. import { controllerTypes } from '../src/controller.js'
  6. import { InputConf } from '../src/index.js'
  7. test('system - instantiates and stores inventory correctly', () => {
  8. let testSystem = new System()
  9. testSystem.add('aaa', [['input_test'], ['output_test'], { id: 'aaa' }])
  10. expect(testSystem.inputs).toStrictEqual(['input_test'])
  11. expect(testSystem.outputs).toStrictEqual(['output_test'])
  12. expect(testSystem.containers[0].id).toStrictEqual('aaa')
  13. const inputs = testSystem.inputsFor({ id: 'aaa' })
  14. expect(inputs).toStrictEqual(['input_test'])
  15. const outputs = testSystem.outputsFor({ id: 'aaa' })
  16. expect(outputs).toStrictEqual(['output_test'])
  17. testSystem.remove('aaa')
  18. expect(testSystem.inventory).toStrictEqual({})
  19. })
  20. test('system - instiantes channels with readers correctly', () => {
  21. let testSystem = new System()
  22. let testContainer = new Container({ l: 10, w: 10, h: 10 })
  23. let mockTemp = 70
  24. let testInConf = new InputConf(
  25. controllerTypes.temp,
  26. () => mockTemp,
  27. 0.1,
  28. () => {
  29. console.log('tick')
  30. return 'tick'
  31. }
  32. )
  33. const cT = makeContainerT([testInConf], [], testContainer)
  34. testSystem.add('aaa', cT)
  35. expect(testSystem.inputs[0].type).toStrictEqual('temperature')
  36. let chan = testSystem.inputs[0].channel
  37. expect(chan.interval).toStrictEqual(0.1)
  38. // Test that the channel and channel.reader are working
  39. expect(chan.val).toStrictEqual(70)
  40. expect(chan.unit).toStrictEqual('F')
  41. expect(chan.inRange).toStrictEqual(false)
  42. expect(testSystem.inputs[0].onUpdate()).toStrictEqual('tick')
  43. mockTemp = 79
  44. chan = chan.update()
  45. expect(chan.val).toStrictEqual(79)
  46. })