Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

system.spec.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { expect, test } from 'vitest'
  2. import { Container } from '../src/core/container.js'
  3. import { System, makeContainerT } from '../src/system.js'
  4. import { controllerTypes } from '../src/controller.js'
  5. import { InputConf } from '../src/index.js'
  6. test('system - instantiates and stores inventory correctly', () => {
  7. let testSystem = new System()
  8. testSystem.add('aaa', [['input_test'], ['output_test'], { id: 'aaa' }])
  9. expect(testSystem.inputs).toStrictEqual(['input_test'])
  10. expect(testSystem.outputs).toStrictEqual(['output_test'])
  11. expect(testSystem.containers[0].id).toStrictEqual('aaa')
  12. const inputs = testSystem.inputsFor({ id: 'aaa' })
  13. expect(inputs).toStrictEqual(['input_test'])
  14. const outputs = testSystem.outputsFor({ id: 'aaa' })
  15. expect(outputs).toStrictEqual(['output_test'])
  16. testSystem.replaceContainer({ id: 'aaa' })
  17. expect(testSystem.containers[0].id).toStrictEqual('aaa')
  18. testSystem.remove('aaa')
  19. expect(testSystem.inventory).toStrictEqual({})
  20. })
  21. test('system - update channels with readers correctly', () => {
  22. let testSystem = new System()
  23. let testContainer = new Container({ l: 10, w: 10, h: 10 })
  24. let mockTemp = 70
  25. let testInConf = new InputConf(
  26. controllerTypes.temp,
  27. () => mockTemp,
  28. 0.1,
  29. () => 'tick',
  30. )
  31. const cT = makeContainerT([testInConf], [], testContainer)
  32. testSystem.add('aaa', cT)
  33. expect(testSystem.inputs[0].type).toStrictEqual('temperature')
  34. let chan = testSystem.inputs[0].channel
  35. expect(chan.interval).toStrictEqual(0.1)
  36. expect(testSystem.inputs[0].onUpdate()).toStrictEqual('tick')
  37. })