Differential D2952 Diff 14052 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
Show All 32 Lines | function testEntitiesList() | ||||
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_javelineer_b " + | "Entities": { "_string": "units/{civ}/cavalry_javelineer_b " + | ||||
"units/{civ}_infantry_swordsman_b " + | "units/{civ}/infantry_swordsman_b " + | ||||
"units/{native}_support_female_citizen" }, | "units/{native}/support_female_citizen" }, | ||||
"Technologies": { "_string": "gather_fishing_net " + | "Technologies": { "_string": "gather_fishing_net " + | ||||
"phase_town_{civ} " + | "phase_town_{civ} " + | ||||
"phase_city_{civ}" } | "phase_city_{civ}" } | ||||
}); | }); | ||||
cmpProductionQueue.GetUpgradedTemplate = (template) => template; | cmpProductionQueue.GetUpgradedTemplate = (template) => template; | ||||
AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | ||||
"GetPlayerByID": id => playerEntityID | "GetPlayerByID": id => playerEntityID | ||||
Show All 22 Lines | function testEntitiesList() | ||||
AddMock(productionQueueId, IID_Upgrade, { | AddMock(productionQueueId, IID_Upgrade, { | ||||
"IsUpgrading": () => false | "IsUpgrading": () => false | ||||
}); | }); | ||||
cmpProductionQueue.CalculateEntitiesMap(); | cmpProductionQueue.CalculateEntitiesMap(); | ||||
TS_ASSERT_UNEVAL_EQUALS( | TS_ASSERT_UNEVAL_EQUALS( | ||||
cmpProductionQueue.GetEntitiesList(), | cmpProductionQueue.GetEntitiesList(), | ||||
["units/iber_cavalry_javelineer_b", "units/iber_infantry_swordsman_b", "units/iber_support_female_citizen"] | ["units/iber/cavalry_javelineer_b", "units/iber/infantry_swordsman_b", "units/iber/support_female_citizen"] | ||||
); | ); | ||||
TS_ASSERT_UNEVAL_EQUALS( | TS_ASSERT_UNEVAL_EQUALS( | ||||
cmpProductionQueue.GetTechnologiesList(), | cmpProductionQueue.GetTechnologiesList(), | ||||
["gather_fishing_net", "phase_town_generic", "phase_city_generic"] | ["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.CalculateEntitiesMap(); | cmpProductionQueue.CalculateEntitiesMap(); | ||||
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": () => ({}), | "GetDisabledTechnologies": () => ({}), | ||||
"GetDisabledTemplates": () => ({ "units/athen_infantry_swordsman_b": true }), | "GetDisabledTemplates": () => ({ "units/athen/infantry_swordsman_b": true }), | ||||
"GetPlayerID": () => playerId | "GetPlayerID": () => playerId | ||||
}); | }); | ||||
cmpProductionQueue.CalculateEntitiesMap(); | cmpProductionQueue.CalculateEntitiesMap(); | ||||
TS_ASSERT_UNEVAL_EQUALS( | TS_ASSERT_UNEVAL_EQUALS( | ||||
cmpProductionQueue.GetEntitiesList(), | cmpProductionQueue.GetEntitiesList(), | ||||
["units/iber_cavalry_javelineer_b", "units/iber_infantry_swordsman_b", "units/iber_support_female_citizen"] | ["units/iber/cavalry_javelineer_b", "units/iber/infantry_swordsman_b", "units/iber/support_female_citizen"] | ||||
); | ); | ||||
AddMock(playerEntityID, IID_Player, { | AddMock(playerEntityID, IID_Player, { | ||||
"GetCiv": () => "iber", | "GetCiv": () => "iber", | ||||
"GetDisabledTechnologies": () => ({}), | "GetDisabledTechnologies": () => ({}), | ||||
"GetDisabledTemplates": () => ({ "units/iber_infantry_swordsman_b": true }), | "GetDisabledTemplates": () => ({ "units/iber/infantry_swordsman_b": true }), | ||||
"GetPlayerID": () => playerId | "GetPlayerID": () => playerId | ||||
}); | }); | ||||
cmpProductionQueue.CalculateEntitiesMap(); | cmpProductionQueue.CalculateEntitiesMap(); | ||||
TS_ASSERT_UNEVAL_EQUALS( | TS_ASSERT_UNEVAL_EQUALS( | ||||
cmpProductionQueue.GetEntitiesList(), | cmpProductionQueue.GetEntitiesList(), | ||||
["units/iber_cavalry_javelineer_b", "units/iber_support_female_citizen"] | ["units/iber/cavalry_javelineer_b", "units/iber/support_female_citizen"] | ||||
); | ); | ||||
AddMock(playerEntityID, IID_Player, { | AddMock(playerEntityID, IID_Player, { | ||||
"GetCiv": () => "athen", | "GetCiv": () => "athen", | ||||
"GetDisabledTechnologies": () => ({ "gather_fishing_net": true }), | "GetDisabledTechnologies": () => ({ "gather_fishing_net": true }), | ||||
"GetDisabledTemplates": () => ({ "units/athen_infantry_swordsman_b": true }), | "GetDisabledTemplates": () => ({ "units/athen/infantry_swordsman_b": true }), | ||||
"GetPlayerID": () => playerId | "GetPlayerID": () => playerId | ||||
}); | }); | ||||
cmpProductionQueue.CalculateEntitiesMap(); | cmpProductionQueue.CalculateEntitiesMap(); | ||||
TS_ASSERT_UNEVAL_EQUALS( | TS_ASSERT_UNEVAL_EQUALS( | ||||
cmpProductionQueue.GetEntitiesList(), | cmpProductionQueue.GetEntitiesList(), | ||||
["units/athen_cavalry_javelineer_b", "units/iber_support_female_citizen"] | ["units/athen/cavalry_javelineer_b", "units/iber/support_female_citizen"] | ||||
); | ); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpProductionQueue.GetTechnologiesList(), ["phase_town_athen", | TS_ASSERT_UNEVAL_EQUALS(cmpProductionQueue.GetTechnologiesList(), ["phase_town_athen", | ||||
"phase_city_athen"] | "phase_city_athen"] | ||||
); | ); | ||||
AddMock(playerEntityID, IID_TechnologyManager, { | AddMock(playerEntityID, IID_TechnologyManager, { | ||||
"CheckTechnologyRequirements": () => true, | "CheckTechnologyRequirements": () => true, | ||||
"IsInProgress": () => false, | "IsInProgress": () => false, | ||||
▲ Show 20 Lines • Show All 222 Lines • ▼ Show 20 Lines | function test_batch_adding() | ||||
cmpProdQueue.AddBatch("some_template", "unit", 3); | cmpProdQueue.AddBatch("some_template", "unit", 3); | ||||
TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 1); | TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 1); | ||||
} | } | ||||
function test_token_changes() | function test_token_changes() | ||||
{ | { | ||||
const ent = 10; | const ent = 10; | ||||
let cmpProductionQueue = ConstructComponent(10, "ProductionQueue", { | let cmpProductionQueue = ConstructComponent(10, "ProductionQueue", { | ||||
"Entities": { "_string": "units/{civ}_a " + | "Entities": { "_string": "units/{civ}/a " + | ||||
"units/{civ}_b" }, | "units/{civ}/b" }, | ||||
"Technologies": { "_string": "a " + | "Technologies": { "_string": "a " + | ||||
"b_{civ} " + | "b_{civ} " + | ||||
"c_{civ}" }, | "c_{civ}" }, | ||||
"BatchTimeModifier": 1 | "BatchTimeModifier": 1 | ||||
}); | }); | ||||
cmpProductionQueue.GetUpgradedTemplate = (template) => template; | cmpProductionQueue.GetUpgradedTemplate = (template) => template; | ||||
// Merges interface of multiple components because it's enough here. | // Merges interface of multiple components because it's enough here. | ||||
Show All 16 Lines | function test_token_changes() | ||||
AddMock(SYSTEM_ENTITY, IID_GuiInterface, { | AddMock(SYSTEM_ENTITY, IID_GuiInterface, { | ||||
"SetSelectionDirty": () => {} | "SetSelectionDirty": () => {} | ||||
}); | }); | ||||
// Test Setup | // Test Setup | ||||
cmpProductionQueue.CalculateEntitiesMap(); | cmpProductionQueue.CalculateEntitiesMap(); | ||||
TS_ASSERT_UNEVAL_EQUALS( | TS_ASSERT_UNEVAL_EQUALS( | ||||
cmpProductionQueue.GetEntitiesList(), ["units/test_a", "units/test_b"] | cmpProductionQueue.GetEntitiesList(), ["units/test/a", "units/test/b"] | ||||
); | ); | ||||
TS_ASSERT_UNEVAL_EQUALS( | TS_ASSERT_UNEVAL_EQUALS( | ||||
cmpProductionQueue.GetTechnologiesList(), ["a", "b_generic", "c_generic"] | cmpProductionQueue.GetTechnologiesList(), ["a", "b_generic", "c_generic"] | ||||
); | ); | ||||
// Add a unit of each type to our queue, validate. | // Add a unit of each type to our queue, validate. | ||||
cmpProductionQueue.AddBatch("units/test_a", "unit", 1, {}); | cmpProductionQueue.AddBatch("units/test/a", "unit", 1, {}); | ||||
cmpProductionQueue.AddBatch("units/test_b", "unit", 1, {}); | cmpProductionQueue.AddBatch("units/test/b", "unit", 1, {}); | ||||
TS_ASSERT_EQUALS(cmpProductionQueue.GetQueue()[0].unitTemplate, "units/test_a"); | TS_ASSERT_EQUALS(cmpProductionQueue.GetQueue()[0].unitTemplate, "units/test/a"); | ||||
TS_ASSERT_EQUALS(cmpProductionQueue.GetQueue()[1].unitTemplate, "units/test_b"); | TS_ASSERT_EQUALS(cmpProductionQueue.GetQueue()[1].unitTemplate, "units/test/b"); | ||||
// Add a modifier that replaces unit A with unit C, | // Add a modifier that replaces unit A with unit C, | ||||
// adds a unit D and removes unit B from the roster. | // adds a unit D and removes unit B from the roster. | ||||
Engine.RegisterGlobal("ApplyValueModificationsToEntity", (_, val) => { | Engine.RegisterGlobal("ApplyValueModificationsToEntity", (_, val) => { | ||||
return HandleTokens(val, "units/{civ}_a>units/{civ}_c units/{civ}_d -units/{civ}_b"); | return HandleTokens(val, "units/{civ}/a>units/{civ}/c units/{civ}/d -units/{civ}/b"); | ||||
}); | }); | ||||
cmpProductionQueue.OnValueModification({ | cmpProductionQueue.OnValueModification({ | ||||
"component": "ProductionQueue", | "component": "ProductionQueue", | ||||
"valueNames": ["ProductionQueue/Entities/_string"], | "valueNames": ["ProductionQueue/Entities/_string"], | ||||
"entities": [ent] | "entities": [ent] | ||||
}); | }); | ||||
TS_ASSERT_UNEVAL_EQUALS( | TS_ASSERT_UNEVAL_EQUALS( | ||||
cmpProductionQueue.GetEntitiesList(), ["units/test_c", "units/test_d"] | cmpProductionQueue.GetEntitiesList(), ["units/test/c", "units/test/d"] | ||||
); | ); | ||||
TS_ASSERT_EQUALS(cmpProductionQueue.GetQueue()[0].unitTemplate, "units/test_c"); | TS_ASSERT_EQUALS(cmpProductionQueue.GetQueue()[0].unitTemplate, "units/test/c"); | ||||
TS_ASSERT_EQUALS(cmpProductionQueue.GetQueue().length, 1); | TS_ASSERT_EQUALS(cmpProductionQueue.GetQueue().length, 1); | ||||
} | } | ||||
testEntitiesList(); | testEntitiesList(); | ||||
regression_test_d1879(); | regression_test_d1879(); | ||||
test_batch_adding(); | test_batch_adding(); | ||||
test_token_changes(); | test_token_changes(); |
Wildfire Games · Phabricator