0ad/binaries/data/mods/public/simulation/components/tests/test_ValueModificationHelper.js
Ralph Sennhauser 88eea5c7e3
Fix eslint rule 'prefer-const' in components/tests
eslint --no-config-lookup --fix --rule '"prefer-const": 1' \
    binaries/data/mods/public/simulation/components/tests

Ref: #7812
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-05-11 10:03:30 +02:00

40 lines
1,005 B
JavaScript

Engine.LoadHelperScript("Player.js");
Engine.LoadHelperScript("ValueModification.js");
Engine.LoadComponentScript("interfaces/Player.js");
Engine.LoadComponentScript("interfaces/ModifiersManager.js");
const player = 1;
const playerEnt = 10;
const ownedEnt = 60;
const techKey = "Attack/BigAttack";
const otherKey = "Other/Key";
AddMock(SYSTEM_ENTITY, IID_ModifiersManager, {
"ApplyModifiers": (key, val, ent) => {
if (key != techKey)
return val;
if (ent == playerEnt)
return val + 3;
if (ent == ownedEnt)
return val + 7;
return val;
}
});
AddMock(SYSTEM_ENTITY, IID_PlayerManager, {
"GetPlayerByID": () => 10
});
AddMock(playerEnt, IID_Player, {
"GetPlayerID": () => 1
});
AddMock(ownedEnt, IID_Ownership, {
"GetOwner": () => 1
});
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity(otherKey, 2.0, playerEnt), 2.0);
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity(techKey, 2.0, playerEnt), 5.0);
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity(techKey, 2.0, ownedEnt), 9.0);