Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Health.js
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | |||||||||||
TS_ASSERT_EQUALS(injured_flag, false); | TS_ASSERT_EQUALS(injured_flag, false); | ||||||||||
TS_ASSERT_EQUALS(change.new, 50); | TS_ASSERT_EQUALS(change.new, 50); | ||||||||||
TS_ASSERT_EQUALS(cmpHealth.GetHitpoints(), 50); | TS_ASSERT_EQUALS(cmpHealth.GetHitpoints(), 50); | ||||||||||
TS_ASSERT_EQUALS(cmpHealth.GetMaxHitpoints(), 50); | TS_ASSERT_EQUALS(cmpHealth.GetMaxHitpoints(), 50); | ||||||||||
TS_ASSERT_EQUALS(cmpHealth.IsInjured(), false); | TS_ASSERT_EQUALS(cmpHealth.IsInjured(), false); | ||||||||||
TS_ASSERT_EQUALS(cmpHealth.IsUnhealable(), true); | TS_ASSERT_EQUALS(cmpHealth.IsUnhealable(), true); | ||||||||||
let numberOfCorpses = 0; | |||||||||||
AddMock(SYSTEM_ENTITY, IID_UnitRenderer, { | |||||||||||
"CanAddCorpse": () => { return numberOfCorpses < 1; }, | |||||||||||
wraitiiUnsubmitted Done Inline Actions
wraitii: | |||||||||||
}); | |||||||||||
// Check death. | // Check death. | ||||||||||
Engine.AddLocalEntity = function(template) { | Engine.AddLocalEntity = function(template) { | ||||||||||
corpse_entity = template; | corpse_entity = template; | ||||||||||
AddMock(corpse_id, IID_Position, { | AddMock(corpse_id, IID_Position, { | ||||||||||
"JumpTo": () => {}, | "JumpTo": () => {}, | ||||||||||
"SetYRotation": () => {}, | "SetYRotation": () => {}, | ||||||||||
"SetXZRotation": () => {}, | "SetXZRotation": () => {}, | ||||||||||
}); | }); | ||||||||||
AddMock(corpse_id, IID_Ownership, { | AddMock(corpse_id, IID_Ownership, { | ||||||||||
"SetOwner": () => {}, | "SetOwner": () => {}, | ||||||||||
}); | }); | ||||||||||
AddMock(corpse_id, IID_Visual, { | AddMock(corpse_id, IID_Visual, { | ||||||||||
"SetActorSeed": () => {}, | "SetActorSeed": () => {}, | ||||||||||
"SelectAnimation": () => {}, | "SelectAnimation": () => {}, | ||||||||||
}); | }); | ||||||||||
return corpse_id; | return corpse_id; | ||||||||||
}; | }; | ||||||||||
let querySpy = new Spy(Engine, "AddLocalEntity"); | |||||||||||
change = cmpHealth.Reduce(50); | change = cmpHealth.Reduce(50); | ||||||||||
// Fake the engine addition of the new corpse. | |||||||||||
++numberOfCorpses; | |||||||||||
Done Inline Actions
wraitii: | |||||||||||
// Assert we create a corpse with the proper template. | // Assert we create a corpse with the proper template. | ||||||||||
TS_ASSERT_EQUALS(corpse_entity, "corpse|test"); | TS_ASSERT_EQUALS(corpse_entity, "corpse|test"); | ||||||||||
TS_ASSERT_EQUALS(querySpy._called, 1); | |||||||||||
// Check that we are not marked as injured. | // Check that we are not marked as injured. | ||||||||||
TS_ASSERT_EQUALS(injured_flag, false); | TS_ASSERT_EQUALS(injured_flag, false); | ||||||||||
TS_ASSERT_EQUALS(change.killed, true); | TS_ASSERT_EQUALS(change.killed, true); | ||||||||||
TS_ASSERT_EQUALS(change.HPchange, -50); | TS_ASSERT_EQUALS(change.HPchange, -50); | ||||||||||
TS_ASSERT_EQUALS(cmpHealth.GetHitpoints(), 0); | TS_ASSERT_EQUALS(cmpHealth.GetHitpoints(), 0); | ||||||||||
TS_ASSERT_EQUALS(cmpHealth.GetMaxHitpoints(), 50); | TS_ASSERT_EQUALS(cmpHealth.GetMaxHitpoints(), 50); | ||||||||||
Show All 30 Lines | |||||||||||
change = cmpHealth.Reduce(30); | change = cmpHealth.Reduce(30); | ||||||||||
change = cmpHealth.Increase(30); | change = cmpHealth.Increase(30); | ||||||||||
TS_ASSERT_EQUALS(injured_flag, false); | TS_ASSERT_EQUALS(injured_flag, false); | ||||||||||
TS_ASSERT_EQUALS(change.new, 50); | TS_ASSERT_EQUALS(change.new, 50); | ||||||||||
TS_ASSERT_EQUALS(cmpHealth.GetHitpoints(), 50); | TS_ASSERT_EQUALS(cmpHealth.GetHitpoints(), 50); | ||||||||||
TS_ASSERT_EQUALS(cmpHealth.GetMaxHitpoints(), 50); | TS_ASSERT_EQUALS(cmpHealth.GetMaxHitpoints(), 50); | ||||||||||
TS_ASSERT_EQUALS(cmpHealth.IsInjured(), false); | TS_ASSERT_EQUALS(cmpHealth.IsInjured(), false); | ||||||||||
TS_ASSERT_EQUALS(cmpHealth.IsUnhealable(), true); | TS_ASSERT_EQUALS(cmpHealth.IsUnhealable(), true); | ||||||||||
Done Inline ActionsYou could have just overwritten the mock to disallow adding a corpse ^^ Freagarach: You could have just overwritten the mock to disallow adding a corpse ^^ | |||||||||||
// Test that a new local entity is not created if the config does not allow it. | |||||||||||
querySpy._reset(); | |||||||||||
cmpHealth = setEntityUp(); | |||||||||||
// Kill the entity | |||||||||||
change = cmpHealth.Reduce(80); | |||||||||||
// It was only called the first time. | |||||||||||
Done Inline ActionsThere's a _reset function, might be better to use that and check against 0. wraitii: There's a _reset function, might be better to use that and check against 0. | |||||||||||
TS_ASSERT_EQUALS(querySpy._called, 0); |
Wildfire Games · Phabricator