36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
const Machine = require('../../src/specificClass');
|
|
const { makeMachineConfig, makeStateConfig } = require('../helpers/factories');
|
|
|
|
test('setMode changes mode only for allowed values', () => {
|
|
const machine = new Machine(makeMachineConfig(), makeStateConfig());
|
|
const original = machine.currentMode;
|
|
|
|
machine.setMode('virtualControl');
|
|
assert.equal(machine.currentMode, 'virtualControl');
|
|
|
|
machine.setMode('invalid-mode');
|
|
assert.equal(machine.currentMode, 'virtualControl');
|
|
assert.notEqual(machine.currentMode, original);
|
|
});
|
|
|
|
test('handleInput rejects non-string action safely', async () => {
|
|
const machine = new Machine(makeMachineConfig(), makeStateConfig());
|
|
await assert.doesNotReject(async () => {
|
|
await machine.handleInput('GUI', 123, null);
|
|
});
|
|
});
|
|
|
|
test('handleInput ignores disallowed source/action combination', async () => {
|
|
const machine = new Machine(makeMachineConfig(), makeStateConfig());
|
|
machine.setMode('fysicalControl');
|
|
|
|
const before = machine.state.getCurrentState();
|
|
await machine.handleInput('GUI', 'execSequence', 'startup');
|
|
const after = machine.state.getCurrentState();
|
|
|
|
assert.equal(before, after);
|
|
});
|