Tested action toggles

This commit is contained in:
ThaumRystra
2024-10-15 21:17:33 +02:00
parent 7a480e333c
commit 01df7898cc
2 changed files with 64 additions and 1 deletions

View File

@@ -0,0 +1,63 @@
import { assert } from 'chai';
import {
allMutations,
createTestCreature,
getRandomIds,
removeAllCreaturesAndProps,
runActionById
} from '/imports/api/engine/action/functions/actionEngineTest.testFn';
const [
creatureId, trueToggleId, falseToggleId,
] = getRandomIds(3);
const actionTestCreature = {
_id: creatureId,
props: [
{
_id: trueToggleId,
type: 'toggle',
condition: { calculation: 'true' },
children: [
{
type: 'note',
summary: { text: 'this should run' },
},
],
},
{
_id: falseToggleId,
type: 'toggle',
condition: { calculation: 'false' },
children: [
{
type: 'note',
summary: { text: 'this should not run' },
},
],
},
],
}
describe('Apply Toggle Properties', function () {
// Increase timeout
this.timeout(8000);
before(async function () {
await removeAllCreaturesAndProps();
await createTestCreature(actionTestCreature);
});
// If branch
it('Runs a toggle with a true condition', async function () {
const action = await runActionById(trueToggleId);
assert.deepEqual(allMutations(action), [{
contents: [{ value: 'this should run' }],
targetIds: [],
}]);
});
it('runs a toggle with a false condition', async function () {
const action = await runActionById(falseToggleId);
assert.deepEqual(allMutations(action), []);
});
});

View File

@@ -41,7 +41,7 @@ const ComputedOnlyToggleSchema = createPropertySchema({
},
});
const ComputedToggleSchema = new SimpleSchema()
const ComputedToggleSchema = new SimpleSchema({})
.extend(ComputedOnlyToggleSchema)
.extend(ToggleSchema);