0ad/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js
Ykkrosh c8c10a4871 # Extensions and cleanups to session GUI files.
Add various GUI pieces (exit button, resource counts, unit details).
Clean up implementation of button panels.
Split some content out of 'common' and into page-specific files.
Delete some obsolete content.

This was SVN commit r7337.
2010-02-28 21:45:09 +00:00

64 lines
1.8 KiB
JavaScript

Engine.LoadComponentScript("interfaces/Attack.js");
Engine.LoadComponentScript("interfaces/Builder.js");
Engine.LoadComponentScript("interfaces/DamageReceiver.js");
Engine.LoadComponentScript("interfaces/Health.js");
Engine.LoadComponentScript("interfaces/ResourceGatherer.js");
Engine.LoadComponentScript("interfaces/ResourceSupply.js");
Engine.LoadComponentScript("GuiInterface.js");
var cmp = ConstructComponent(SYSTEM_ENTITY, "GuiInterface");
AddMock(SYSTEM_ENTITY, IID_PlayerManager, {
GetNumPlayers: function() { return 2; },
GetPlayerByID: function(id) { TS_ASSERT(id === 0 || id === 1); return 100+id; }
});
AddMock(SYSTEM_ENTITY, IID_TemplateManager, {
GetCurrentTemplateName: function(ent) { return "example"; },
GetTemplate: function(name) { return ""; },
});
AddMock(100, IID_Player, {
GetPopulationCount: function() { return 10; },
GetPopulationLimit: function() { return 20; },
GetResourceCounts: function() { return { "food": 100 }; }
});
AddMock(101, IID_Player, {
GetPopulationCount: function() { return 40; },
GetPopulationLimit: function() { return 30; },
GetResourceCounts: function() { return { "food": 200 }; }
});
TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
players: [{popCount:10, popLimit:20, resourceCounts:{food:100}}, {popCount:40, popLimit:30, resourceCounts:{food:200}}]
});
AddMock(10, IID_Position, {
GetPosition: function() {
return {x:1, y:2, z:3};
}
});
AddMock(10, IID_Health, {
GetHitpoints: function() { return 50; },
GetMaxHitpoints: function() { return 60; },
});
AddMock(10, IID_Builder, {
GetEntitiesList: function() {
return ["test1", "test2"];
}
});
var state = cmp.GetEntityState(-1, 10);
TS_ASSERT_UNEVAL_EQUALS(state, {
template: "example",
position: {x:1, y:2, z:3},
hitpoints: 50,
maxHitpoints: 60,
buildEntities: ["test1", "test2"]
});