Differential D1125 Diff 4638 ps/trunk/binaries/data/mods/public/simulation/components/tests/test_ProductionQueue.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/tests/test_ProductionQueue.js
Resources = { | Resources = { | ||||
"BuildSchema": (a, b) => {} | "BuildSchema": (a, b) => {} | ||||
}; | }; | ||||
Engine.LoadHelperScript("Player.js"); | Engine.LoadHelperScript("Player.js"); | ||||
Engine.LoadComponentScript("interfaces/TechnologyManager.js"); | |||||
Engine.LoadComponentScript("interfaces/ProductionQueue.js"); | Engine.LoadComponentScript("interfaces/ProductionQueue.js"); | ||||
Engine.LoadComponentScript("ProductionQueue.js"); | Engine.LoadComponentScript("ProductionQueue.js"); | ||||
const productionQueueId = 6; | const productionQueueId = 6; | ||||
const playerId = 1; | const playerId = 1; | ||||
const playerEntityID = 2; | const playerEntityID = 2; | ||||
AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | ||||
"TemplateExists": () => true, | "TemplateExists": () => true, | ||||
"GetTemplate": name => {} | "GetTemplate": name => ({}) | ||||
}); | }); | ||||
let cmpProductionQueue = ConstructComponent(productionQueueId, "ProductionQueue", { | let cmpProductionQueue = ConstructComponent(productionQueueId, "ProductionQueue", { | ||||
"Entities": { "_string": "units/{civ}_cavalry_javelinist_b units/{civ}_infantry_swordsman_b " + | "Entities": { "_string": "units/{civ}_cavalry_javelinist_b " + | ||||
"units/{native}_support_female_citizen" } | "units/{civ}_infantry_swordsman_b " + | ||||
"units/{native}_support_female_citizen" }, | |||||
"Technologies": { "_string": "gather_fishing_net " + | |||||
"phase_town_{civ} " + | |||||
"phase_city_{civ}" } | |||||
}); | }); | ||||
cmpProductionQueue.CalculateEntitiesList(); | cmpProductionQueue.CalculateEntitiesList(); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpProductionQueue.GetEntitiesList(), []); | TS_ASSERT_UNEVAL_EQUALS(cmpProductionQueue.GetEntitiesList(), []); | ||||
AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | ||||
"GetPlayerByID": id => playerEntityID | "GetPlayerByID": id => playerEntityID | ||||
}); | }); | ||||
AddMock(SYSTEM_ENTITY, IID_DataTemplateManager, { | |||||
"TechnologyExists": name => name == "phase_town_athen" || name == "phase_city_athen" | |||||
}); | |||||
AddMock(playerEntityID, IID_Player, { | AddMock(playerEntityID, IID_Player, { | ||||
"GetCiv": () => "iber", | "GetCiv": () => "iber", | ||||
"GetDisabledTechnologies": () => ({}), | |||||
"GetDisabledTemplates": () => ({}), | "GetDisabledTemplates": () => ({}), | ||||
"GetPlayerID": () => playerId | "GetPlayerID": () => playerId | ||||
}); | }); | ||||
AddMock(playerEntityID, IID_TechnologyManager, { | |||||
"CheckTechnologyRequirements": () => true, | |||||
"GetTechnologyTemplate": tech => tech, | |||||
"IsInProgress": () => false, | |||||
"IsTechnologyResearched": () => false | |||||
}); | |||||
AddMock(productionQueueId, IID_Ownership, { | AddMock(productionQueueId, IID_Ownership, { | ||||
"GetOwner": () => playerId | "GetOwner": () => playerId | ||||
}); | }); | ||||
AddMock(productionQueueId, IID_Identity, { | AddMock(productionQueueId, IID_Identity, { | ||||
"GetCiv": () => "iber" | "GetCiv": () => "iber" | ||||
}); | }); | ||||
cmpProductionQueue.CalculateEntitiesList(); | cmpProductionQueue.CalculateEntitiesList(); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpProductionQueue.GetEntitiesList(), ["units/iber_cavalry_javelinist_b", "units/iber_infantry_swordsman_b", | TS_ASSERT_UNEVAL_EQUALS( | ||||
"units/iber_support_female_citizen"]); | cmpProductionQueue.GetEntitiesList(), | ||||
["units/iber_cavalry_javelinist_b", "units/iber_infantry_swordsman_b", "units/iber_support_female_citizen"] | |||||
); | |||||
TS_ASSERT_UNEVAL_EQUALS( | |||||
cmpProductionQueue.GetTechnologiesList(), | |||||
["gather_fishing_net", "phase_town_generic", "phase_city_generic"] | |||||
); | |||||
AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | ||||
"TemplateExists": name => name == "units/iber_support_female_citizen", | "TemplateExists": name => name == "units/iber_support_female_citizen", | ||||
"GetTemplate": name => {} | "GetTemplate": name => ({}) | ||||
}); | }); | ||||
cmpProductionQueue.CalculateEntitiesList(); | cmpProductionQueue.CalculateEntitiesList(); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpProductionQueue.GetEntitiesList(), ["units/iber_support_female_citizen"]); | TS_ASSERT_UNEVAL_EQUALS(cmpProductionQueue.GetEntitiesList(), ["units/iber_support_female_citizen"]); | ||||
AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | ||||
"TemplateExists": () => true, | "TemplateExists": () => true, | ||||
"GetTemplate": name => {} | "GetTemplate": name => ({}) | ||||
}); | }); | ||||
AddMock(playerEntityID, IID_Player, { | AddMock(playerEntityID, IID_Player, { | ||||
"GetCiv": () => "iber", | "GetCiv": () => "iber", | ||||
"GetDisabledTechnologies": () => ({}), | |||||
"GetDisabledTemplates": () => ({ "units/athen_infantry_swordsman_b": true }), | "GetDisabledTemplates": () => ({ "units/athen_infantry_swordsman_b": true }), | ||||
"GetPlayerID": () => playerId | "GetPlayerID": () => playerId | ||||
}); | }); | ||||
cmpProductionQueue.CalculateEntitiesList(); | cmpProductionQueue.CalculateEntitiesList(); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpProductionQueue.GetEntitiesList(), ["units/iber_cavalry_javelinist_b", "units/iber_infantry_swordsman_b", | TS_ASSERT_UNEVAL_EQUALS( | ||||
"units/iber_support_female_citizen"]); | cmpProductionQueue.GetEntitiesList(), | ||||
["units/iber_cavalry_javelinist_b", "units/iber_infantry_swordsman_b", "units/iber_support_female_citizen"] | |||||
); | |||||
AddMock(playerEntityID, IID_Player, { | AddMock(playerEntityID, IID_Player, { | ||||
"GetCiv": () => "iber", | "GetCiv": () => "iber", | ||||
"GetDisabledTechnologies": () => ({}), | |||||
"GetDisabledTemplates": () => ({ "units/iber_infantry_swordsman_b": true }), | "GetDisabledTemplates": () => ({ "units/iber_infantry_swordsman_b": true }), | ||||
"GetPlayerID": () => playerId | "GetPlayerID": () => playerId | ||||
}); | }); | ||||
cmpProductionQueue.CalculateEntitiesList(); | cmpProductionQueue.CalculateEntitiesList(); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpProductionQueue.GetEntitiesList(), ["units/iber_cavalry_javelinist_b", "units/iber_support_female_citizen"]); | TS_ASSERT_UNEVAL_EQUALS( | ||||
cmpProductionQueue.GetEntitiesList(), | |||||
["units/iber_cavalry_javelinist_b", "units/iber_support_female_citizen"] | |||||
); | |||||
AddMock(playerEntityID, IID_Player, { | AddMock(playerEntityID, IID_Player, { | ||||
"GetCiv": () => "athen", | "GetCiv": () => "athen", | ||||
"GetDisabledTechnologies": () => ({ "gather_fishing_net": true }), | |||||
"GetDisabledTemplates": () => ({ "units/athen_infantry_swordsman_b": true }), | "GetDisabledTemplates": () => ({ "units/athen_infantry_swordsman_b": true }), | ||||
"GetPlayerID": () => playerId | "GetPlayerID": () => playerId | ||||
}); | }); | ||||
cmpProductionQueue.CalculateEntitiesList(); | cmpProductionQueue.CalculateEntitiesList(); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpProductionQueue.GetEntitiesList(), ["units/athen_cavalry_javelinist_b", "units/iber_support_female_citizen"]); | TS_ASSERT_UNEVAL_EQUALS( | ||||
cmpProductionQueue.GetEntitiesList(), | |||||
["units/athen_cavalry_javelinist_b", "units/iber_support_female_citizen"] | |||||
); | |||||
TS_ASSERT_UNEVAL_EQUALS(cmpProductionQueue.GetTechnologiesList(), ["phase_town_athen", | |||||
"phase_city_athen"] | |||||
); | |||||
AddMock(playerEntityID, IID_TechnologyManager, { | |||||
"CheckTechnologyRequirements": () => true, | |||||
"GetTechnologyTemplate": tech => tech, | |||||
"IsInProgress": () => false, | |||||
"IsTechnologyResearched": tech => tech == "phase_town_athen" | |||||
}); | |||||
TS_ASSERT_UNEVAL_EQUALS(cmpProductionQueue.GetTechnologiesList(), [undefined, "phase_city_athen"]); | |||||
AddMock(playerEntityID, IID_Player, { | |||||
"GetCiv": () => "iber", | |||||
"GetDisabledTechnologies": () => ({}), | |||||
"GetPlayerID": () => playerId | |||||
}); | |||||
TS_ASSERT_UNEVAL_EQUALS( | |||||
cmpProductionQueue.GetTechnologiesList(), | |||||
["gather_fishing_net", "phase_town_generic", "phase_city_generic"] | |||||
); |
Wildfire Games · Phabricator