Introduce a new Focus Mode API function to retrieve full list of EntityIds that are in focus. (#7159)

Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>
This commit is contained in:
Danilo Aimini
2022-01-26 08:12:34 -08:00
committed by GitHub
parent ec47c4fdfc
commit 1a7a350880
4 changed files with 135 additions and 0 deletions
@@ -7,6 +7,7 @@
*/
#include <Tests/FocusMode/EditorFocusModeFixture.h>
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
namespace UnitTest
{
@@ -30,6 +31,58 @@ namespace UnitTest
EXPECT_EQ(m_focusModeInterface->GetFocusRoot(m_editorEntityContextId), AZ::EntityId());
}
TEST_F(EditorFocusModeFixture, GetFocusedEntitiesBase)
{
m_focusModeInterface->SetFocusRoot(m_entityMap[StreetEntityName]);
AzToolsFramework::EntityIdList entities = m_focusModeInterface->GetFocusedEntities(m_editorEntityContextId);
EXPECT_EQ(entities.size(), 5);
EXPECT_TRUE(AZStd::find(entities.begin(), entities.end(), m_entityMap[StreetEntityName]) != entities.end());
EXPECT_TRUE(AZStd::find(entities.begin(), entities.end(), m_entityMap[CarEntityName]) != entities.end());
EXPECT_TRUE(AZStd::find(entities.begin(), entities.end(), m_entityMap[Passenger1EntityName]) != entities.end());
EXPECT_TRUE(AZStd::find(entities.begin(), entities.end(), m_entityMap[SportsCarEntityName]) != entities.end());
EXPECT_TRUE(AZStd::find(entities.begin(), entities.end(), m_entityMap[Passenger2EntityName]) != entities.end());
}
TEST_F(EditorFocusModeFixture, GetFocusedEntitiesSiblings)
{
m_focusModeInterface->SetFocusRoot(m_entityMap[SportsCarEntityName]);
AzToolsFramework::EntityIdList entities = m_focusModeInterface->GetFocusedEntities(m_editorEntityContextId);
EXPECT_EQ(entities.size(), 2);
EXPECT_TRUE(AZStd::find(entities.begin(), entities.end(), m_entityMap[SportsCarEntityName]) != entities.end());
EXPECT_TRUE(AZStd::find(entities.begin(), entities.end(), m_entityMap[Passenger2EntityName]) != entities.end());
}
TEST_F(EditorFocusModeFixture, GetFocusedEntitiesAddEntity)
{
m_focusModeInterface->SetFocusRoot(m_entityMap[SportsCarEntityName]);
AZ::EntityId testEntityId = CreateEditorEntity("Test", m_entityMap[Passenger2EntityName]);
AzToolsFramework::EntityIdList entities = m_focusModeInterface->GetFocusedEntities(m_editorEntityContextId);
EXPECT_EQ(entities.size(), 3);
EXPECT_TRUE(AZStd::find(entities.begin(), entities.end(), m_entityMap[SportsCarEntityName]) != entities.end());
EXPECT_TRUE(AZStd::find(entities.begin(), entities.end(), m_entityMap[Passenger2EntityName]) != entities.end());
EXPECT_TRUE(AZStd::find(entities.begin(), entities.end(), testEntityId) != entities.end());
}
TEST_F(EditorFocusModeFixture, GetFocusedEntitiesRemoveEntity)
{
m_focusModeInterface->SetFocusRoot(m_entityMap[SportsCarEntityName]);
AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
&AzToolsFramework::ToolsApplicationRequests::DeleteEntityAndAllDescendants, m_entityMap[Passenger2EntityName]);
AzToolsFramework::EntityIdList entities = m_focusModeInterface->GetFocusedEntities(m_editorEntityContextId);
EXPECT_EQ(entities.size(), 1);
EXPECT_TRUE(AZStd::find(entities.begin(), entities.end(), m_entityMap[SportsCarEntityName]) != entities.end());
}
TEST_F(EditorFocusModeFixture, IsInFocusSubTreeAncestorsDescendants)
{
// When the focus is set to an entity, all its descendants are in the focus subtree while the ancestors aren't.