Tested folders, notes, and rolls

This commit is contained in:
Thaum Rystra
2024-10-14 21:52:37 +02:00
parent efc52b4f68
commit b772a4eaa1
8 changed files with 155 additions and 6 deletions

View File

@@ -125,7 +125,6 @@ describe('Interrupt action system', function () {
name: 'New Roll',
value: '7d1 [1, 1, 1, 1, 1, 1, 1] + 9\n**16**',
inline: true,
silenced: undefined,
}, {
value: 'rollVar: 16'
}

View File

@@ -0,0 +1,49 @@
import { assert } from 'chai';
import {
allMutations,
createTestCreature,
getRandomIds,
removeAllCreaturesAndProps,
runActionById
} from '/imports/api/engine/action/functions/actionEngineTest.testFn';
const [
creatureId, folderId
] = getRandomIds(100);
const actionTestCreature = {
_id: creatureId,
props: [
{
_id: folderId,
type: 'folder',
children: [{
type: 'note',
summary: { text: 'this should run' },
}],
},
],
}
describe('Apply folder properties', function () {
// Increase timeout
this.timeout(8000);
before(async function () {
await removeAllCreaturesAndProps();
await createTestCreature(actionTestCreature);
});
it('Applies the children of the folder', async function () {
const action = await runActionById(folderId);
assert.exists(action);
assert.deepEqual(allMutations(action), [{
contents: [
{
value: 'this should run'
}
],
targetIds: [],
}]);
});
});

View File

@@ -0,0 +1,48 @@
import { assert } from 'chai';
import {
allMutations,
createTestCreature,
getRandomIds,
removeAllCreaturesAndProps,
runActionById
} from '/imports/api/engine/action/functions/actionEngineTest.testFn';
const [
creatureId, noteId
] = getRandomIds(2);
const actionTestCreature = {
_id: creatureId,
props: [
{
_id: noteId,
type: 'note',
name: 'Note Name',
summary: { text: 'Note summary {1 + 2}' }
},
],
}
describe('Apply note properties', function () {
// Increase timeout
this.timeout(8000);
before(async function () {
await removeAllCreaturesAndProps();
await createTestCreature(actionTestCreature);
});
it('Applies the note text', async function () {
const action = await runActionById(noteId);
assert.exists(action);
assert.deepEqual(allMutations(action), [{
contents: [
{
name: 'Note Name',
value: 'Note summary 3'
}
],
targetIds: [],
}]);
});
});

View File

@@ -0,0 +1,53 @@
import { assert } from 'chai';
import {
allLogContent,
createTestCreature,
getRandomIds,
removeAllCreaturesAndProps,
runActionById
} from '/imports/api/engine/action/functions/actionEngineTest.testFn';
const [
creatureId, rollId,
] = getRandomIds(2);
const actionTestCreature = {
_id: creatureId,
props: [
{
_id: rollId,
type: 'roll',
name: 'Roll Name',
variableName: 'roll1',
roll: { calculation: '7 + 15' },
children: [
{
type: 'note',
summary: { text: 'roll: {roll1}' },
},
],
},
],
};
describe('Apply roll properties', function () {
// Increase timeout
this.timeout(8000);
before(async function () {
await removeAllCreaturesAndProps();
await createTestCreature(actionTestCreature);
});
it('Saves the value of the roll into the variable name', async function () {
const action = await runActionById(rollId);
assert.exists(action);
assert.deepEqual(allLogContent(action), [{
inline: true,
name: 'Roll Name',
value: '**22**',
}, {
value: 'roll: 22',
}]);
});
});

View File

@@ -52,7 +52,7 @@ export default async function applyRollProperty(
name: prop.name,
value: logValue.join('\n'),
inline: true,
silenced: prop.silent,
...prop.silent && { silenced: true },
}, task.targetIds);
// Apply children

View File

@@ -6,8 +6,8 @@ const inputProviderForTests: InputProvider = {
},
/**
* For testing, randomness is hard to deal with
* rollDice function returns the average roll for every dice rolled
* [5d10, 1d4] => [[6,6,6,6,6], [3]]
* rollDice function returns the average roll for every dice rolled, but increasing by one each time
* [6d10, 1d4] => [[6,7,8,9,10,1], [3]]
*/
async rollDice(dice = []) {
const result: number[][] = [];

View File

@@ -52,7 +52,7 @@ let ComputedOnlyBranchSchema = createPropertySchema({
},
});
const ComputedBranchSchema = new SimpleSchema()
const ComputedBranchSchema = new SimpleSchema({})
.extend(BranchSchema)
.extend(ComputedOnlyBranchSchema);

View File

@@ -56,7 +56,7 @@ let ComputedOnlyRollSchema = createPropertySchema({
},
});
const ComputedRollSchema = new SimpleSchema()
const ComputedRollSchema = new SimpleSchema({})
.extend(RollSchema)
.extend(ComputedOnlyRollSchema);