Fixed inactive test for new parenting structure

This commit is contained in:
Thaum Rystra
2023-09-28 15:16:52 +02:00
parent 3bd2806bc6
commit 60c13643fb
2 changed files with 45 additions and 20 deletions

View File

@@ -2,8 +2,9 @@ import { buildComputationFromProps } from '/imports/api/engine/computation/build
import { assert } from 'chai';
import clean from '../../utility/cleanProp.testFn.js';
export default function(){
export default function () {
let computation = buildComputationFromProps(testProperties);
const bySelf = (propId, note) => assertDeactivatedBySelf(computation, propId, note);
const byAncestor = (propId, note) => assertDeactivatedByAncestor(computation, propId, note);
const active = (propId, note) => assertActive(computation, propId, note);
@@ -24,22 +25,22 @@ export default function(){
// Notes
active('NoteId', 'Notes should be active');
byAncestor('NoteChildId', 'children of notes should always be inactive');
active('NoteChildId', 'children of notes should be active');
}
function assertDeactivatedBySelf(computation, propId, note){
function assertDeactivatedBySelf(computation, propId, note) {
const prop = computation.propsById[propId];
assert.isTrue(prop.deactivatedBySelf, note);
assert.isTrue(prop.inactive, note + '. The property should be inactive');
}
function assertDeactivatedByAncestor(computation, propId, note){
function assertDeactivatedByAncestor(computation, propId, note) {
const prop = computation.propsById[propId];
assert.isTrue(prop.deactivatedByAncestor, note);
assert.isTrue(prop.inactive, 'The property should be inactive');
}
function assertActive(computation, propId, note){
function assertActive(computation, propId, note) {
const prop = computation.propsById[propId];
assert.isNotTrue(prop.inactive, note);
assert.isNotTrue(prop.deactivatedBySelf, note);
@@ -51,66 +52,90 @@ var testProperties = [
clean({
_id: 'itemUnequippedId',
type: 'item',
ancestors: [{id: 'charId'}],
parentId: 'charId',
left: 1,
right: 4,
}),
clean({
_id: 'itemUnequippedChildId',
type: 'folder',
ancestors: [{id: 'charId'}, {id: 'itemUnequippedId'}],
parentId: 'itemUnequippedId',
left: 2,
right: 3,
}),
clean({
_id: 'itemEquippedId',
type: 'item',
equipped: true,
ancestors: [{id: 'charId'}],
parentId: 'charId',
left: 5,
right: 8,
}),
clean({
_id: 'itemEquippedChildId',
type: 'folder',
ancestors: [{id: 'charId'}, {id: 'itemEquippedId'}],
parentId: 'itemEquippedId',
left: 6,
right: 7,
}),
// Spells
clean({
_id: 'spellPreparedId',
type: 'spell',
ancestors: [{id: 'charId'}],
parentId: 'charId',
prepared: true,
left: 9,
right: 12,
}),
clean({
_id: 'spellPreparedChildId',
type: 'folder',
ancestors: [{id: 'charId'}, {id: 'spellPreparedId'}],
parentId: 'spellPreparedId',
left: 10,
right: 11,
}),
clean({
_id: 'spellAlwaysPreparedId',
type: 'spell',
ancestors: [{id: 'charId'}],
parentId: 'charId',
alwaysPrepared: true,
left: 13,
right: 16,
}),
clean({
_id: 'spellAlwaysPreparedChildId',
type: 'folder',
ancestors: [{id: 'charId'}, {id: 'spellAlwaysPreparedId'}],
parentId: 'spellAlwaysPreparedId',
left: 14,
right: 15,
}),
clean({
_id: 'spellUnpreparedId',
type: 'spell',
ancestors: [{id: 'charId'}],
parentId: 'charId',
left: 17,
right: 20,
}),
clean({
_id: 'spellUnpreparedChildId',
type: 'folder',
ancestors: [{id: 'charId'}, {id: 'spellUnpreparedId'}],
parentId: 'spellUnpreparedId',
left: 18,
right: 19,
}),
// Notes
clean({
_id: 'NoteId',
type: 'note',
ancestors: [{id: 'charId'}],
parentId: 'charId',
left: 21,
right: 24,
}),
clean({
_id: 'NoteChildId',
type: 'folder',
ancestors: [{id: 'charId'}, {id: 'NoteId'}],
parentId: 'NoteId',
left: 22,
right: 23,
}),
];

View File

@@ -1,4 +1,4 @@
import { docsToForest as nodeArrayToTree } from '/imports/api/parenting/parentingFunctions';
import { docsToForest } from '/imports/api/parenting/parentingFunctions';
import { DenormalisedOnlyCreaturePropertySchema as denormSchema }
from '/imports/api/creature/creatureProperties/CreatureProperties';
import { getProperties, getCreature, getVariables } from '/imports/api/engine/loadCreatures.js';
@@ -12,7 +12,7 @@ import computeToggleDependencies from './buildComputation/computeToggleDependenc
import linkCalculationDependencies from './buildComputation/linkCalculationDependencies.js';
import linkTypeDependencies from './buildComputation/linkTypeDependencies.js';
import computeSlotQuantityFilled from './buildComputation/computeSlotQuantityFilled.js';
import CreatureComputation from './CreatureComputation.ts';
import CreatureComputation from './CreatureComputation';
import removeSchemaFields from './buildComputation/removeSchemaFields.js';
/**
@@ -86,7 +86,7 @@ export function buildComputationFromProps(properties, creature, variables) {
});
// Get all the properties as trees based on their ancestors
let forest = nodeArrayToTree(properties);
let forest = docsToForest(properties);
// Walk the property trees computing things that need to be inherited
walkDown(forest, node => {
computeInactiveStatus(node);