From 8c545138673c7b8fdc249cff6a4c2d780279f35f Mon Sep 17 00:00:00 2001 From: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> Date: Tue, 8 Feb 2022 16:59:25 -0800 Subject: [PATCH] Add box selection tests for Editor Focus Mode Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> --- .../ContainerEntitySelectionTests.cpp | 10 +-- .../FocusMode/EditorFocusModeFixture.cpp | 11 ++- .../Tests/FocusMode/EditorFocusModeFixture.h | 10 +-- .../EditorFocusModeSelectionFixture.h | 15 ++++ .../EditorFocusModeSelectionTests.cpp | 71 +++++++++++++++++-- 5 files changed, 99 insertions(+), 18 deletions(-) diff --git a/Code/Framework/AzToolsFramework/Tests/FocusMode/ContainerEntitySelectionTests.cpp b/Code/Framework/AzToolsFramework/Tests/FocusMode/ContainerEntitySelectionTests.cpp index 0ad61b924b..483db4076e 100644 --- a/Code/Framework/AzToolsFramework/Tests/FocusMode/ContainerEntitySelectionTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/FocusMode/ContainerEntitySelectionTests.cpp @@ -15,7 +15,7 @@ namespace UnitTest // When no containers are in the way, the function will just return the entityId of the entity that was clicked. // Click on Car Entity - ClickAtWorldPositionOnViewport(WorldCarEntityPosition); + ClickAtWorldPositionOnViewport(s_worldCarEntityPosition); // Verify the correct entity is selected auto selectedEntitiesAfter = GetSelectedEntities(); @@ -29,7 +29,7 @@ namespace UnitTest m_containerEntityInterface->RegisterEntityAsContainer(m_entityMap[StreetEntityName]); // Containers are closed by default // Click on Car Entity - ClickAtWorldPositionOnViewport(WorldCarEntityPosition); + ClickAtWorldPositionOnViewport(s_worldCarEntityPosition); // Verify the correct entity is selected auto selectedEntitiesAfter = GetSelectedEntities(); @@ -47,7 +47,7 @@ namespace UnitTest m_containerEntityInterface->SetContainerOpen(m_entityMap[StreetEntityName], true); // Click on Car Entity - ClickAtWorldPositionOnViewport(WorldCarEntityPosition); + ClickAtWorldPositionOnViewport(s_worldCarEntityPosition); // Verify the correct entity is selected auto selectedEntitiesAfter = GetSelectedEntities(); @@ -65,7 +65,7 @@ namespace UnitTest m_containerEntityInterface->RegisterEntityAsContainer(m_entityMap[CityEntityName]); // Click on Car Entity - ClickAtWorldPositionOnViewport(WorldCarEntityPosition); + ClickAtWorldPositionOnViewport(s_worldCarEntityPosition); // Verify the correct entity is selected auto selectedEntitiesAfter = GetSelectedEntities(); @@ -85,7 +85,7 @@ namespace UnitTest m_containerEntityInterface->SetContainerOpen(m_entityMap[CityEntityName], true); // Click on Car Entity - ClickAtWorldPositionOnViewport(WorldCarEntityPosition); + ClickAtWorldPositionOnViewport(s_worldCarEntityPosition); // Verify the correct entity is selected auto selectedEntitiesAfter = GetSelectedEntities(); diff --git a/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeFixture.cpp b/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeFixture.cpp index 90becfa46f..374b85c01d 100644 --- a/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeFixture.cpp +++ b/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeFixture.cpp @@ -8,6 +8,7 @@ #include +#include #include #include @@ -93,10 +94,13 @@ namespace UnitTest entity->CreateComponent(); entity->Activate(); - // Move the CarEntity so it's out of the way. - AZ::TransformBus::Event(m_entityMap[CarEntityName], &AZ::TransformBus::Events::SetWorldTranslation, WorldCarEntityPosition); + // Move the City so that it is in view + AZ::TransformBus::Event(m_entityMap[CityEntityName], &AZ::TransformBus::Events::SetWorldTranslation, s_worldCityEntityPosition); - // Setup the camera so the Car entity is in view. + // Move the CarEntity so that it's not overlapping with the rest + AZ::TransformBus::Event(m_entityMap[CarEntityName], &AZ::TransformBus::Events::SetWorldTranslation, s_worldCarEntityPosition); + + // Setup the camera so the entities is in view. AzFramework::SetCameraTransform( m_cameraState, AZ::Transform::CreateFromQuaternionAndTranslation( @@ -113,4 +117,5 @@ namespace UnitTest return entity->GetId(); } + } // namespace UnitTest diff --git a/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeFixture.h b/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeFixture.h index 0cf1be6ffd..88cc5ac921 100644 --- a/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeFixture.h +++ b/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeFixture.h @@ -8,7 +8,6 @@ #pragma once -#include #include #include @@ -38,9 +37,6 @@ namespace UnitTest AzToolsFramework::EntityIdList GetSelectedEntities(); AzFramework::EntityContextId m_editorEntityContextId = AzFramework::EntityContextId::CreateNull(); - AzFramework::CameraState m_cameraState; - - inline static const AZ::Vector3 CameraPosition = AZ::Vector3(10.0f, 15.0f, 10.0f); inline static const char* CityEntityName = "City"; inline static const char* StreetEntityName = "Street"; @@ -49,7 +45,11 @@ namespace UnitTest inline static const char* Passenger1EntityName = "Passenger1"; inline static const char* Passenger2EntityName = "Passenger2"; - inline static AZ::Vector3 WorldCarEntityPosition = AZ::Vector3(5.0f, 15.0f, 0.0f); + AzFramework::CameraState m_cameraState; + + inline static const AZ::Vector3 CameraPosition = AZ::Vector3(10.0f, 15.0f, 10.0f); + inline static AZ::Vector3 s_worldCityEntityPosition = AZ::Vector3(5.0f, 10.0f, 0.0f); + inline static AZ::Vector3 s_worldCarEntityPosition = AZ::Vector3(5.0f, 15.0f, 0.0f); }; } // namespace UnitTest diff --git a/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeSelectionFixture.h b/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeSelectionFixture.h index fe1de9b122..5dc323dd8c 100644 --- a/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeSelectionFixture.h +++ b/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeSelectionFixture.h @@ -45,5 +45,20 @@ namespace UnitTest // Click the entity in the viewport m_actionDispatcher->CameraState(m_cameraState)->MousePosition(carScreenPosition)->MouseLButtonDown()->MouseLButtonUp(); } + + void BoxSelectOnViewport() + { + // Calculate the position in screen space of where to begin and end the box select action + const auto beginningPositionWorldBoxSelect = AzFramework::WorldToScreen(AZ::Vector3(-10.0f, 15.0f, 5.0f), m_cameraState); + const auto endingPositionWorldBoxSelect = AzFramework::WorldToScreen(AZ::Vector3(10.0f, 15.0f, -5.0f), m_cameraState); + + // Perform a box select in the viewport + m_actionDispatcher->SetStickySelect(true) + ->CameraState(m_cameraState) + ->MousePosition(beginningPositionWorldBoxSelect) + ->MouseLButtonDown() + ->MousePosition(endingPositionWorldBoxSelect) + ->MouseLButtonUp(); + } }; } // namespace UnitTest diff --git a/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeSelectionTests.cpp b/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeSelectionTests.cpp index 1efcb15b30..ee338539a8 100644 --- a/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeSelectionTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/FocusMode/EditorFocusModeSelectionTests.cpp @@ -13,7 +13,7 @@ namespace UnitTest TEST_F(EditorFocusModeSelectionFixture, EditorFocusModeSelectionSelectEntityWithFocusOnLevel) { // Click on Car Entity - ClickAtWorldPositionOnViewport(WorldCarEntityPosition); + ClickAtWorldPositionOnViewport(s_worldCarEntityPosition); // Verify entity is selected auto selectedEntitiesAfter = GetSelectedEntities(); @@ -27,7 +27,7 @@ namespace UnitTest m_focusModeInterface->SetFocusRoot(m_entityMap[StreetEntityName]); // Click on Car Entity - ClickAtWorldPositionOnViewport(WorldCarEntityPosition); + ClickAtWorldPositionOnViewport(s_worldCarEntityPosition); // Verify entity is selected auto selectedEntitiesAfter = GetSelectedEntities(); @@ -41,7 +41,7 @@ namespace UnitTest m_focusModeInterface->SetFocusRoot(m_entityMap[CarEntityName]); // Click on Car Entity - ClickAtWorldPositionOnViewport(WorldCarEntityPosition); + ClickAtWorldPositionOnViewport(s_worldCarEntityPosition); // Verify entity is selected auto selectedEntitiesAfter = GetSelectedEntities(); @@ -55,7 +55,7 @@ namespace UnitTest m_focusModeInterface->SetFocusRoot(m_entityMap[SportsCarEntityName]); // Click on Car Entity - ClickAtWorldPositionOnViewport(WorldCarEntityPosition); + ClickAtWorldPositionOnViewport(s_worldCarEntityPosition); // Verify entity is selected auto selectedEntitiesAfter = GetSelectedEntities(); @@ -68,10 +68,71 @@ namespace UnitTest m_focusModeInterface->SetFocusRoot(m_entityMap[Passenger1EntityName]); // Click on Car Entity - ClickAtWorldPositionOnViewport(WorldCarEntityPosition); + ClickAtWorldPositionOnViewport(s_worldCarEntityPosition); // Verify entity is selected auto selectedEntitiesAfter = GetSelectedEntities(); EXPECT_EQ(selectedEntitiesAfter.size(), 0); } + + TEST_F(EditorFocusModeSelectionFixture, EditorFocusModeSelectionBoxSelectWithFocusOnLevel) + { + // Do a box select that includes all entities in the fixture + BoxSelectOnViewport(); + + // Entities are selected + using ::testing::UnorderedElementsAre; + auto selectedEntitiesAfter = GetSelectedEntities(); + EXPECT_THAT(selectedEntitiesAfter, + UnorderedElementsAre( + m_entityMap[CityEntityName], + m_entityMap[StreetEntityName], + m_entityMap[CarEntityName], + m_entityMap[Passenger1EntityName], + m_entityMap[SportsCarEntityName], + m_entityMap[Passenger2EntityName] + ) + ); + } + + TEST_F(EditorFocusModeSelectionFixture, EditorFocusModeSelectionBoxSelectWithFocusOnChild) + { + // Set the focus on the Passenger1 Entity (child of the entity) + m_focusModeInterface->SetFocusRoot(m_entityMap[StreetEntityName]); + + // Do a box select that includes all entities in the fixture + BoxSelectOnViewport(); + + // Entities are selected + using ::testing::UnorderedElementsAre; + auto selectedEntitiesAfter = GetSelectedEntities(); + EXPECT_THAT(selectedEntitiesAfter, + UnorderedElementsAre( + m_entityMap[StreetEntityName], + m_entityMap[CarEntityName], + m_entityMap[Passenger1EntityName], + m_entityMap[SportsCarEntityName], + m_entityMap[Passenger2EntityName] + ) + ); + } + + TEST_F(EditorFocusModeSelectionFixture, EditorFocusModeSelectionBoxSelectWithFocusOnLeaf) + { + // Set the focus on the Passenger1 Entity (child of the entity) + m_focusModeInterface->SetFocusRoot(m_entityMap[Passenger1EntityName]); + + // Do a box select that includes all entities in the fixture + BoxSelectOnViewport(); + + // Entities are selected + using ::testing::UnorderedElementsAre; + auto selectedEntitiesAfter = GetSelectedEntities(); + EXPECT_THAT(selectedEntitiesAfter, + UnorderedElementsAre( + m_entityMap[Passenger1EntityName] + ) + ); + } + } // namespace UnitTest