Files
rotatingMachine/test/integration/shutdown-sequence.integration.test.js

73 lines
3.2 KiB
JavaScript
Raw Normal View History

const test = require('node:test');
const assert = require('node:assert/strict');
const Machine = require('../../src/specificClass');
const { makeMachineConfig, makeStateConfig } = require('../helpers/factories');
test('shutdown sequence from operational reaches idle', async () => {
const machine = new Machine(makeMachineConfig(), makeStateConfig());
await machine.handleInput('parent', 'execSequence', 'startup');
assert.equal(machine.state.getCurrentState(), 'operational');
await machine.handleInput('parent', 'execSequence', 'shutdown');
assert.equal(machine.state.getCurrentState(), 'idle');
});
test('shutdown from operational ramps down position before stopping', async () => {
const machine = new Machine(makeMachineConfig(), makeStateConfig());
await machine.handleInput('parent', 'execSequence', 'startup');
await machine.handleInput('parent', 'execMovement', 50);
const posBefore = machine.state.getCurrentPosition();
assert.ok(posBefore > 0, 'Machine should be at non-zero position');
await machine.handleInput('parent', 'execSequence', 'shutdown');
const posAfter = machine.state.getCurrentPosition();
assert.ok(posAfter <= posBefore, 'Position should have decreased after shutdown');
assert.equal(machine.state.getCurrentState(), 'idle');
});
test('shutdown clears predicted flow and power', async () => {
const machine = new Machine(makeMachineConfig(), makeStateConfig());
await machine.handleInput('parent', 'execSequence', 'startup');
machine.updateMeasuredPressure(1000, 'downstream', { timestamp: Date.now(), unit: 'mbar', childName: 'pt' });
await machine.handleInput('parent', 'execMovement', 50);
await machine.handleInput('parent', 'execSequence', 'shutdown');
const flow = machine.measurements.type('flow').variant('predicted').position('downstream').getCurrentValue();
const power = machine.measurements.type('power').variant('predicted').position('atEquipment').getCurrentValue();
assert.equal(flow, 0, 'Flow should be zero after shutdown');
assert.equal(power, 0, 'Power should be zero after shutdown');
});
test('entermaintenance sequence from operational reaches maintenance state', async () => {
const machine = new Machine(makeMachineConfig(), makeStateConfig());
await machine.handleInput('parent', 'execSequence', 'startup');
assert.equal(machine.state.getCurrentState(), 'operational');
await machine.handleInput('parent', 'enterMaintenance', 'entermaintenance');
assert.equal(machine.state.getCurrentState(), 'maintenance');
});
test('exitmaintenance requires mode with exitmaintenance action allowed', async () => {
const machine = new Machine(makeMachineConfig(), makeStateConfig());
// Use auto mode (has execsequence + entermaintenance) to reach maintenance
await machine.handleInput('parent', 'execSequence', 'startup');
assert.equal(machine.state.getCurrentState(), 'operational');
await machine.handleInput('parent', 'enterMaintenance', 'entermaintenance');
assert.equal(machine.state.getCurrentState(), 'maintenance');
// Switch to fysicalControl which allows exitmaintenance
machine.setMode('fysicalControl');
await machine.handleInput('fysical', 'exitMaintenance', 'exitmaintenance');
assert.equal(machine.state.getCurrentState(), 'idle');
});