| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import { expect, test } from 'vitest'
- import { Container } from '../src/core/container.js'
- import { System, makeContainerT } from '../src/system.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.replaceContainer({ id: 'aaa' })
- expect(testSystem.containers[0].id).toStrictEqual('aaa')
-
- testSystem.remove('aaa')
- expect(testSystem.inventory).toStrictEqual({})
- })
-
- test('system - update 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,
- () => '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)
- expect(testSystem.inputs[0].onUpdate()).toStrictEqual('tick')
- })
|