From 01df7898cc88d68a16f64d9f5ca1251bb6ee3a14 Mon Sep 17 00:00:00 2001 From: ThaumRystra Date: Tue, 15 Oct 2024 21:17:33 +0200 Subject: [PATCH] Tested action toggles --- .../applyToggleProperty.test.ts | 63 +++++++++++++++++++ app/imports/api/properties/Toggles.js | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 app/imports/api/engine/action/applyProperties/applyToggleProperty.test.ts diff --git a/app/imports/api/engine/action/applyProperties/applyToggleProperty.test.ts b/app/imports/api/engine/action/applyProperties/applyToggleProperty.test.ts new file mode 100644 index 00000000..7d59c303 --- /dev/null +++ b/app/imports/api/engine/action/applyProperties/applyToggleProperty.test.ts @@ -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), []); + }); +}); diff --git a/app/imports/api/properties/Toggles.js b/app/imports/api/properties/Toggles.js index e52f6e49..c0802588 100644 --- a/app/imports/api/properties/Toggles.js +++ b/app/imports/api/properties/Toggles.js @@ -41,7 +41,7 @@ const ComputedOnlyToggleSchema = createPropertySchema({ }, }); -const ComputedToggleSchema = new SimpleSchema() +const ComputedToggleSchema = new SimpleSchema({}) .extend(ComputedOnlyToggleSchema) .extend(ToggleSchema);