| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import { expect, test } from 'vitest'
- import { System, makeContainerT } from '../src/system.js'
- import { Reading } from '../src/channel.js'
- import { Container } from '../src/container.js'
- import { controllerTypes } from '../src/controller.js'
- import { InputConf } from '../src/index.js'
-
- test('system - instantiates and stores inventory correctly', () => {
- let testSystem = new System()
- testSystem.add('aaa', [['input_test'], ['output_test'], { id: 'aaa' }])
- expect(testSystem.inputs).toStrictEqual(['input_test'])
- expect(testSystem.outputs).toStrictEqual(['output_test'])
- expect(testSystem.containers[0].id).toStrictEqual('aaa')
-
- const inputs = testSystem.inputsFor({ id: 'aaa' })
- expect(inputs).toStrictEqual(['input_test'])
-
- const outputs = testSystem.outputsFor({ id: 'aaa' })
- expect(outputs).toStrictEqual(['output_test'])
-
- testSystem.remove('aaa')
- expect(testSystem.inventory).toStrictEqual({})
- })
-
- test('system - instiantes channels with readers correctly', () => {
- let testSystem = new System()
- let testContainer = new Container({ l: 10, w: 10, h: 10 })
- let mockTemp = 70
- let testInConf = new InputConf(
- controllerTypes.temp,
- () => mockTemp,
- 0.1,
- () => {
- console.log('tick')
- return 'tick'
- }
- )
- const cT = makeContainerT([testInConf], [], testContainer)
- testSystem.add('aaa', cT)
-
- expect(testSystem.inputs[0].type).toStrictEqual('temperature')
-
- let chan = testSystem.inputs[0].channel
- expect(chan.interval).toStrictEqual(0.1)
-
- // Test that the channel and channel.reader are working
- expect(chan.val).toStrictEqual(70)
- expect(chan.unit).toStrictEqual('F')
- expect(chan.inRange).toStrictEqual(false)
- expect(testSystem.inputs[0].onUpdate()).toStrictEqual('tick')
-
- mockTemp = 79
- chan = chan.update()
- expect(chan.val).toStrictEqual(79)
- })
|