updates to rotating machine struct
This commit is contained in:
35
test/basic/mode-and-input.basic.test.js
Normal file
35
test/basic/mode-and-input.basic.test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user