/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include #include #include #include #include "AzToolsFramework/UI/PropertyEditor/PropertyStringLineEditCtrl.hxx" #include #include #include #include #include #include #include #include #include #include #include namespace EMotionFX { TEST_F(UIFixture, CanEditAnimGraphNode) { /* Test Rail ID: C22083483 Expected Result: Making changes to an AnimGraph Node through the Attributes Panel should reflect in the UI */ RecordProperty("test_case_id", "C22083483"); // Declare useful objects from other namespaces using AzToolsFramework::PropertyRowWidget; using AzToolsFramework::ReflectedPropertyEditor; using EMotionFX::AnimGraphNodeNameLineEdit; using AzToolsFramework::InstanceDataNode; // Typedefs to help minimize long defintions typedef AZStd::pair WidgetListItem; typedef AZStd::unordered_map WidgetList; // Constants const AZStd::string originalNodeName = "Original-Node"; const AZStd::string motionNodeID = azrtti_typeid().ToString(); const QString newNodeName = "New-Node"; // Load AnimGraph mode and get useful widgets/objects EMStudio::GetMainWindow()->ApplicationModeChanged("AnimGraph"); auto animGraphPlugin = static_cast(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::AnimGraphPlugin::CLASS_ID)); EMStudio::BlendGraphWidget* graphWidget = animGraphPlugin->GetGraphWidget(); ASSERT_TRUE(graphWidget) << "Failed retrieving BlendGraphWidget"; EMStudio::AttributesWindow* attributesWindow = animGraphPlugin->GetAttributesWindow(); ASSERT_TRUE(attributesWindow) << "Failed retrieving Attributes Window"; // Handle for active AnimGraph AnimGraph* activeAnimGraph = nullptr; { const AZStd::string createAnimGraphCommand = "CreateAnimGraph"; const AZStd::string createNodeCommand = "AnimGraphCreateNode -type " + motionNodeID + " -name " + originalNodeName + " -parentName Root -xPos 1 -yPos 1"; AZStd::string result; // Create a new AnimGraph EXPECT_FALSE(animGraphPlugin->GetActiveAnimGraph()) << "Expected there to be no anim graph loaded"; EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(createAnimGraphCommand, result)) << result.c_str(); activeAnimGraph = animGraphPlugin->GetActiveAnimGraph(); ASSERT_TRUE(activeAnimGraph) << "An anim graph was not created with command: " << createAnimGraphCommand.c_str(); // Create a new AnimGraph Node const AZ::u32 nodeCount = activeAnimGraph->GetNumNodes(); EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(createNodeCommand, result)) << result.c_str(); EXPECT_EQ(activeAnimGraph->GetNumNodes(), nodeCount + 1) << "Expected one more anim graph node after running command: " << createNodeCommand.c_str(); } // Ensure the name of the created node is as expected AnimGraphNode* node = activeAnimGraph->GetNode(activeAnimGraph->GetNumNodes() - 1); ASSERT_TRUE(node) << "Failed retrieving node from active animgraph"; EXPECT_EQ(originalNodeName, node->GetName()) << "Expected the created node to have the name: " << originalNodeName.c_str(); // Select the new Graph Node (via left mouse click) graphWidget->resize(200, 200); EXPECT_EQ(graphWidget->CalcNumSelectedNodes(), 0) << "Expected to have exactly zero (0) selected nodes"; QRect nodeRect = graphWidget->GetActiveGraph()->FindGraphNode(node)->GetFinalRect(); QTest::mouseClick(graphWidget, Qt::LeftButton, Qt::KeyboardModifiers(), nodeRect.center()); EXPECT_EQ(graphWidget->CalcNumSelectedNodes(), 1) << "Expected to have exactly one (1) selected node"; auto objectEditor = attributesWindow->findChild("EMFX.AttributesWindow.ObjectEditor"); auto propertyEditor = objectEditor->findChild("PropertyEditor"); // Get list of all PropertyRowWidgets (and their InstanceDataNodes) const WidgetList list = propertyEditor->GetWidgets(); ASSERT_GT(list.size(), 0) << "Did not find any PropertyRowWidgets"; // Look for PropertyRowWidget for "Name" PropertyRowWidget* propertyRow = nullptr; for (const WidgetListItem& item : list) { if (item.second->objectName() == "Name") { propertyRow = item.second; } } ASSERT_TRUE(propertyRow) << "Could not find the 'Name' PropertyRowWidget"; // Set the text for the textbox to edit AnimGraph Node name auto lineEdit = static_cast(propertyRow->GetChildWidget()); lineEdit->setText(newNodeName); // Push changes in text to the AnimGraph Node lineEdit->OnEditingFinished(); // Validate the name for the Node has changed EXPECT_EQ(newNodeName, node->GetName()) << "Expected the created node to have the name: " << newNodeName.toStdString(); // Unselect AnimGraphNode before cleanup QPoint pt = QPoint(nodeRect.left() - 2, nodeRect.top() - 2); // Some point to click NOT in the AnimGraphNode's rectangle QTest::mouseClick(graphWidget, Qt::LeftButton, Qt::KeyboardModifiers(), pt); EXPECT_EQ(graphWidget->CalcNumSelectedNodes(), 0) << "Expected to have exactly zero (0) selected nodes"; } // CanEditAnimGraph } // EMotionFX namespace