Merge pull request #7509 from aws-lumberyard-dev/daimini/FocusMode/boxSelectAndManipulatorsHidingTests

Focus Mode | Create an integration test for Box Select while in Focus Mode
monroegm-disable-blank-issue-2
Chris Galvan 4 years ago committed by GitHub
commit a4a1514729
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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. // When no containers are in the way, the function will just return the entityId of the entity that was clicked.
// Click on Car Entity // Click on Car Entity
ClickAtWorldPositionOnViewport(WorldCarEntityPosition); ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
// Verify the correct entity is selected // Verify the correct entity is selected
auto selectedEntitiesAfter = GetSelectedEntities(); auto selectedEntitiesAfter = GetSelectedEntities();
@ -29,7 +29,7 @@ namespace UnitTest
m_containerEntityInterface->RegisterEntityAsContainer(m_entityMap[StreetEntityName]); // Containers are closed by default m_containerEntityInterface->RegisterEntityAsContainer(m_entityMap[StreetEntityName]); // Containers are closed by default
// Click on Car Entity // Click on Car Entity
ClickAtWorldPositionOnViewport(WorldCarEntityPosition); ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
// Verify the correct entity is selected // Verify the correct entity is selected
auto selectedEntitiesAfter = GetSelectedEntities(); auto selectedEntitiesAfter = GetSelectedEntities();
@ -47,7 +47,7 @@ namespace UnitTest
m_containerEntityInterface->SetContainerOpen(m_entityMap[StreetEntityName], true); m_containerEntityInterface->SetContainerOpen(m_entityMap[StreetEntityName], true);
// Click on Car Entity // Click on Car Entity
ClickAtWorldPositionOnViewport(WorldCarEntityPosition); ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
// Verify the correct entity is selected // Verify the correct entity is selected
auto selectedEntitiesAfter = GetSelectedEntities(); auto selectedEntitiesAfter = GetSelectedEntities();
@ -65,7 +65,7 @@ namespace UnitTest
m_containerEntityInterface->RegisterEntityAsContainer(m_entityMap[CityEntityName]); m_containerEntityInterface->RegisterEntityAsContainer(m_entityMap[CityEntityName]);
// Click on Car Entity // Click on Car Entity
ClickAtWorldPositionOnViewport(WorldCarEntityPosition); ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
// Verify the correct entity is selected // Verify the correct entity is selected
auto selectedEntitiesAfter = GetSelectedEntities(); auto selectedEntitiesAfter = GetSelectedEntities();
@ -85,7 +85,7 @@ namespace UnitTest
m_containerEntityInterface->SetContainerOpen(m_entityMap[CityEntityName], true); m_containerEntityInterface->SetContainerOpen(m_entityMap[CityEntityName], true);
// Click on Car Entity // Click on Car Entity
ClickAtWorldPositionOnViewport(WorldCarEntityPosition); ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
// Verify the correct entity is selected // Verify the correct entity is selected
auto selectedEntitiesAfter = GetSelectedEntities(); auto selectedEntitiesAfter = GetSelectedEntities();

@ -8,6 +8,7 @@
#include <Tests/FocusMode/EditorFocusModeFixture.h> #include <Tests/FocusMode/EditorFocusModeFixture.h>
#include <AzCore/Component/TransformBus.h>
#include <AzToolsFramework/Entity/EditorEntityHelpers.h> #include <AzToolsFramework/Entity/EditorEntityHelpers.h>
#include <Tests/BoundsTestComponent.h> #include <Tests/BoundsTestComponent.h>
@ -93,10 +94,13 @@ namespace UnitTest
entity->CreateComponent<UnitTest::BoundsTestComponent>(); entity->CreateComponent<UnitTest::BoundsTestComponent>();
entity->Activate(); entity->Activate();
// Move the CarEntity so it's out of the way. // Move the City so that it is in view
AZ::TransformBus::Event(m_entityMap[CarEntityName], &AZ::TransformBus::Events::SetWorldTranslation, WorldCarEntityPosition); 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( AzFramework::SetCameraTransform(
m_cameraState, m_cameraState,
AZ::Transform::CreateFromQuaternionAndTranslation( AZ::Transform::CreateFromQuaternionAndTranslation(
@ -113,4 +117,5 @@ namespace UnitTest
return entity->GetId(); return entity->GetId();
} }
} // namespace UnitTest } // namespace UnitTest

@ -8,7 +8,6 @@
#pragma once #pragma once
#include <AzCore/Component/TransformBus.h>
#include <AzCore/UnitTest/TestTypes.h> #include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/UserSettings/UserSettingsComponent.h> #include <AzCore/UserSettings/UserSettingsComponent.h>
@ -38,9 +37,6 @@ namespace UnitTest
AzToolsFramework::EntityIdList GetSelectedEntities(); AzToolsFramework::EntityIdList GetSelectedEntities();
AzFramework::EntityContextId m_editorEntityContextId = AzFramework::EntityContextId::CreateNull(); 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* CityEntityName = "City";
inline static const char* StreetEntityName = "Street"; inline static const char* StreetEntityName = "Street";
@ -49,7 +45,11 @@ namespace UnitTest
inline static const char* Passenger1EntityName = "Passenger1"; inline static const char* Passenger1EntityName = "Passenger1";
inline static const char* Passenger2EntityName = "Passenger2"; 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 } // namespace UnitTest

@ -45,5 +45,20 @@ namespace UnitTest
// Click the entity in the viewport // Click the entity in the viewport
m_actionDispatcher->CameraState(m_cameraState)->MousePosition(carScreenPosition)->MouseLButtonDown()->MouseLButtonUp(); 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 } // namespace UnitTest

@ -13,7 +13,7 @@ namespace UnitTest
TEST_F(EditorFocusModeSelectionFixture, EditorFocusModeSelectionSelectEntityWithFocusOnLevel) TEST_F(EditorFocusModeSelectionFixture, EditorFocusModeSelectionSelectEntityWithFocusOnLevel)
{ {
// Click on Car Entity // Click on Car Entity
ClickAtWorldPositionOnViewport(WorldCarEntityPosition); ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
// Verify entity is selected // Verify entity is selected
auto selectedEntitiesAfter = GetSelectedEntities(); auto selectedEntitiesAfter = GetSelectedEntities();
@ -27,7 +27,7 @@ namespace UnitTest
m_focusModeInterface->SetFocusRoot(m_entityMap[StreetEntityName]); m_focusModeInterface->SetFocusRoot(m_entityMap[StreetEntityName]);
// Click on Car Entity // Click on Car Entity
ClickAtWorldPositionOnViewport(WorldCarEntityPosition); ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
// Verify entity is selected // Verify entity is selected
auto selectedEntitiesAfter = GetSelectedEntities(); auto selectedEntitiesAfter = GetSelectedEntities();
@ -41,7 +41,7 @@ namespace UnitTest
m_focusModeInterface->SetFocusRoot(m_entityMap[CarEntityName]); m_focusModeInterface->SetFocusRoot(m_entityMap[CarEntityName]);
// Click on Car Entity // Click on Car Entity
ClickAtWorldPositionOnViewport(WorldCarEntityPosition); ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
// Verify entity is selected // Verify entity is selected
auto selectedEntitiesAfter = GetSelectedEntities(); auto selectedEntitiesAfter = GetSelectedEntities();
@ -55,7 +55,7 @@ namespace UnitTest
m_focusModeInterface->SetFocusRoot(m_entityMap[SportsCarEntityName]); m_focusModeInterface->SetFocusRoot(m_entityMap[SportsCarEntityName]);
// Click on Car Entity // Click on Car Entity
ClickAtWorldPositionOnViewport(WorldCarEntityPosition); ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
// Verify entity is selected // Verify entity is selected
auto selectedEntitiesAfter = GetSelectedEntities(); auto selectedEntitiesAfter = GetSelectedEntities();
@ -68,10 +68,71 @@ namespace UnitTest
m_focusModeInterface->SetFocusRoot(m_entityMap[Passenger1EntityName]); m_focusModeInterface->SetFocusRoot(m_entityMap[Passenger1EntityName]);
// Click on Car Entity // Click on Car Entity
ClickAtWorldPositionOnViewport(WorldCarEntityPosition); ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
// Verify entity is selected // Verify entity is selected
auto selectedEntitiesAfter = GetSelectedEntities(); auto selectedEntitiesAfter = GetSelectedEntities();
EXPECT_EQ(selectedEntitiesAfter.size(), 0); 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 } // namespace UnitTest

Loading…
Cancel
Save