From 0a51aaf7cba8a218677632ceac479aea9464538e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Mon, 18 Apr 2022 04:19:55 +0200 Subject: [PATCH] GH-139 Create simple tests for Friendly acs list elements builder --- ...ildFriendlyAcsListElement.utils.UETest.php | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 modules/flightControl/components/FlightsList/utils/buildFriendlyAcsListElement.utils.UETest.php diff --git a/modules/flightControl/components/FlightsList/utils/buildFriendlyAcsListElement.utils.UETest.php b/modules/flightControl/components/FlightsList/utils/buildFriendlyAcsListElement.utils.UETest.php new file mode 100644 index 00000000..47d66872 --- /dev/null +++ b/modules/flightControl/components/FlightsList/utils/buildFriendlyAcsListElement.utils.UETest.php @@ -0,0 +1,180 @@ + [ + "id" => "119", + "main_fleet_id" => "1283", + "owner_id" => "2", + "fleets_id" => "", + "start_time" => "1591971305", + "end_galaxy" => "2", + "end_system" => "5", + "end_planet" => "10", + "end_type" => "3", + "username" => "testUser_friend_1", + "fleet_amount" => "20", + "fleet_array" => "202,100;204,10", + "fleet_start_galaxy" => "1", + "fleet_start_system" => "1", + "fleet_start_planet" => "1", + "fleet_start_type" => "1", + "fleet_start_time" => "1591971305", + "fleet_send_time" => "1591966805", + ], + 'joinedUnion' => [ + "fleets_id" => "|1284|", + ], + ]; + + public $expectedResults = [ + 'baseUnion' => [ + 'positionsAndTime' => [ + 'FleetOriGalaxy' => '1', + 'FleetOriSystem' => '1', + 'FleetOriPlanet' => '1', + 'FleetOriType' => 'planet', + 'FleetOriStart' => '12.06.2020
13:00:05', + 'FleetDesGalaxy' => '2', + 'FleetDesSystem' => '5', + 'FleetDesPlanet' => '10', + 'FleetDesType' => 'moon', + 'FleetDesArrive' => '12.06.2020
14:15:05', + 'FleetEndTime' => '-', + ], + ], + ]; + + /** + * @test + */ + public function itShouldCreateCorrectElementStructure() { + $params = [ + 'elementNo' => 1, + 'acsUnion' => $this->mockAcsUnions['baseUnion'], + 'acsMainFleets' => [], + 'currentTimestamp' => 1591968605, + 'acsUnionsExtraSquads' => [], + "isJoiningThisUnion" => false, + ]; + + $result = Utils\buildFriendlyAcsListElement($params); + + $expectedParams = [ + 'FleetNo' => 1, + 'FleetMissionColor' => 'orange', + 'FleetMission' => "United Attack #1", + 'FleetBehaviour' => 'In flight to the destination point', + 'FleetBehaviourTxt' => '(In flight)', + 'FleetCount' => '110', + 'FleetHideTargetorBackTime' => $this->hidingClassString, + 'FleetHideComeBackTime' => $this->hidingClassString, + 'FleetHideStayTime' => $this->hidingClassString, + 'FleetHideRetreatTime' => $this->hidingClassString, + ]; + $expectedParamsData = [ + 'ships' => [ + '202' => 100, + '204' => 10, + ], + ]; + + $this->assertArraySubset($this->expectedResults['baseUnion']['positionsAndTime'], $result, true); + $this->assertArraySubset($expectedParams, $result, true); + $this->assertArraySubset($expectedParamsData, $result['data'], true); + } + + /** + * @test + */ + public function itShouldCreateCorrectElementWithJoinedFleetsStructure() { + $params = [ + 'elementNo' => 1, + 'acsUnion' => array_merge( + $this->mockAcsUnions['baseUnion'], + $this->mockAcsUnions['joinedUnion'], + ), + "acsMainFleets" => [ + "1269" => [ + "acsId" => "113", + "hasJoinedFleets" => true, + ], + ], + "currentTimestamp" => 1591968605, + "acsUnionsExtraSquads" => [ + "1283" => [ + [ + "array" => [ + "202" => "1", + "203" => "10", + ], + "count" => "11", + ], + ], + ], + "isJoiningThisUnion" => false, + ]; + + $result = Utils\buildFriendlyAcsListElement($params); + + $expectedParams = [ + 'FleetNo' => 1, + 'FleetMissionColor' => 'orange', + 'FleetMission' => "United Attack #1", + 'FleetBehaviour' => 'In flight to the destination point', + 'FleetBehaviourTxt' => '(In flight)', + 'FleetCount' => '121', + 'FleetHideTargetorBackTime' => $this->hidingClassString, + 'FleetHideComeBackTime' => $this->hidingClassString, + 'FleetHideStayTime' => $this->hidingClassString, + 'FleetHideRetreatTime' => $this->hidingClassString, + ]; + $expectedParamsData = [ + 'ships' => [ + '202' => 101, + '203' => 10, + '204' => 10, + ], + ]; + + $this->assertArraySubset($this->expectedResults['baseUnion']['positionsAndTime'], $result, true); + $this->assertArraySubset($expectedParams, $result, true); + $this->assertArraySubset($expectedParamsData, $result['data'], true); + } +}