PrefabInspectorOverrideTests.cpp 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzToolsFramework/Prefab/DocumentPropertyEditor/PrefabPropertyEditorNodes.h>
  9. #include <AzToolsFramework/UI/PropertyEditor/ComponentEditor.hxx>
  10. #include <Prefab/Overrides/PrefabInspectorOverrideTestFixture.h>
  11. namespace UnitTest
  12. {
  13. using PrefabInspectorOverrideTest = PrefabInspectorOverrideTestFixture;
  14. // These index paths depend on multiple factors like the data in the component, how its reflected to serialize and edit contexts,
  15. // how different DPE adapters likes ReflectionAdapter and PrefabAdapter construct the DPE DOM etc. Therefore, these may
  16. // change in the future if the data stored in the DPE DOM itself changes and need to be modified accordingly to prevent test failures.
  17. constexpr AZStd::string_view pathToTranslateRow = "/1/2";
  18. TEST_F(PrefabInspectorOverrideTest, ValidatePresenceOfOverrideProperty)
  19. {
  20. AZ::EntityId newEntityId, parentContainerId, grandparentContainerId;
  21. CreateEntityInNestedPrefab(newEntityId, parentContainerId, grandparentContainerId);
  22. CreateAndValidateEditEntityOverride(newEntityId, grandparentContainerId);
  23. GenerateComponentAdapterDoms(newEntityId);
  24. AzToolsFramework::ComponentEditor::VisitComponentAdapterContentsCallback callback = [](const AZ::Dom::Value& adapterContents)
  25. {
  26. using AZ::DocumentPropertyEditor::Nodes::PropertyEditor;
  27. using AzToolsFramework::Prefab::PrefabPropertyEditorNodes::PrefabOverrideLabel;
  28. EXPECT_FALSE(adapterContents.IsArrayEmpty());
  29. // Validate the translate row has overridden data.
  30. AZ::Dom::Path domPathToTranslateRow(pathToTranslateRow);
  31. AZ::Dom::Value translateRow = adapterContents[domPathToTranslateRow];
  32. EXPECT_EQ(translateRow.GetType(), AZ::Dom::Type::Node);
  33. EXPECT_EQ(translateRow.ArraySize(), 2);
  34. AZ::Dom::Value labelPropertyEditor = translateRow[0];
  35. EXPECT_EQ(labelPropertyEditor[PropertyEditor::Type.GetName()].GetString(), PrefabOverrideLabel::Name);
  36. EXPECT_EQ(labelPropertyEditor[PrefabOverrideLabel::Value.GetName()].GetString(), "Translate");
  37. EXPECT_FALSE(labelPropertyEditor[PrefabOverrideLabel::RelativePath.GetName()].GetString().empty());
  38. EXPECT_FALSE(labelPropertyEditor[PrefabOverrideLabel::RevertOverride.GetName()].IsNull());
  39. EXPECT_TRUE(labelPropertyEditor[PrefabOverrideLabel::IsOverridden.GetName()].GetBool());
  40. AZ::Dom::Value valuePropertyEditor = translateRow[1];
  41. EXPECT_EQ(valuePropertyEditor[PropertyEditor::Value.GetName()][0].GetDouble(), 10.0);
  42. };
  43. ValidateComponentEditorDomContents(callback);
  44. }
  45. TEST_F(PrefabInspectorOverrideTest, ValidateAbsenceOfOverrideProperty)
  46. {
  47. AZ::EntityId newEntityId, parentContainerId, grandparentContainerId;
  48. CreateEntityInNestedPrefab(newEntityId, parentContainerId, grandparentContainerId);
  49. EditEntityAndValidateNoOverride(newEntityId);
  50. m_prefabFocusPublicInterface->FocusOnOwningPrefab(grandparentContainerId);
  51. GenerateComponentAdapterDoms(newEntityId);
  52. AzToolsFramework::ComponentEditor::VisitComponentAdapterContentsCallback callback = [](const AZ::Dom::Value& adapterContents)
  53. {
  54. using AZ::DocumentPropertyEditor::Nodes::PropertyEditor;
  55. using AzToolsFramework::Prefab::PrefabPropertyEditorNodes::PrefabOverrideLabel;
  56. EXPECT_FALSE(adapterContents.IsArrayEmpty());
  57. // Validate the translate row has no overridden data.
  58. AZ::Dom::Path domPathToTranslateRow(pathToTranslateRow);
  59. AZ::Dom::Value translateRow = adapterContents[domPathToTranslateRow];
  60. EXPECT_EQ(translateRow.GetType(), AZ::Dom::Type::Node);
  61. EXPECT_EQ(translateRow.ArraySize(), 2);
  62. AZ::Dom::Value labelPropertyEditor = translateRow[0];
  63. EXPECT_EQ(labelPropertyEditor[PropertyEditor::Type.GetName()].GetString(), PrefabOverrideLabel::Name);
  64. EXPECT_EQ(labelPropertyEditor[PrefabOverrideLabel::Value.GetName()].GetString(), "Translate");
  65. EXPECT_FALSE(labelPropertyEditor[PrefabOverrideLabel::RelativePath.GetName()].GetString().empty());
  66. EXPECT_FALSE(labelPropertyEditor[PrefabOverrideLabel::RevertOverride.GetName()].IsNull());
  67. EXPECT_FALSE(labelPropertyEditor[PrefabOverrideLabel::IsOverridden.GetName()].GetBool());
  68. AZ::Dom::Value valuePropertyEditor = translateRow[1];
  69. EXPECT_EQ(valuePropertyEditor[PropertyEditor::Value.GetName()][0].GetDouble(), 10.0);
  70. };
  71. ValidateComponentEditorDomContents(callback);
  72. }
  73. } // namespace UnitTest