Files
o3de/Gems/ScriptCanvasDeveloper/Code/Editor/Source/EditorAutomationTests/InteractionTests.cpp
T
Esteban Papp 1f9b284de2 Merge branch 'development' into cmake/SPEC-7179
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>

# Conflicts:
#	Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h
#	Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h
#	Code/Editor/Plugins/EditorCommon/stdafx.cpp
#	Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h
#	Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h
#	Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h
#	Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h
#	Code/Tools/AssetProcessor/native/precompiled.h
#	Code/Tools/Standalone/StandaloneTools_precompiled.h
#	Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h
#	Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h
#	Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h
#	Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h
#	Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h
#	Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h
#	Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake
#	Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h
#	Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h
#	Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp
#	Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake
#	Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h
#	Gems/Blast/Code/Source/StdAfx.cpp
#	Gems/Camera/Code/Source/Camera_precompiled.h
#	Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h
#	Gems/FastNoise/Code/Source/FastNoise_precompiled.h
#	Gems/Gestures/Code/Source/Gestures_precompiled.h
#	Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h
#	Gems/GraphCanvas/Code/precompiled.h
#	Gems/ImGui/Code/Source/ImGui_precompiled.h
#	Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h
#	Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h
#	Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp
#	Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h
#	Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h
#	Gems/LyShine/Code/Source/LyShine_precompiled.h
#	Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h
#	Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h
#	Gems/Maestro/Code/Source/Maestro_precompiled.h
#	Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h
#	Gems/Metastream/Code/Source/Metastream_precompiled.h
#	Gems/Microphone/Code/Source/Microphone_precompiled.h
#	Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h
#	Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h
#	Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h
#	Gems/PhysX/Code/Source/PhysX_precompiled.h
#	Gems/PhysX/Code/physx_unsupported_files.cmake
#	Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h
#	Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h
#	Gems/ScriptCanvas/Code/Editor/precompiled.h
#	Gems/ScriptCanvas/Code/Source/precompiled.h
#	Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h
#	Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h
#	Gems/ScriptEvents/Code/Source/precompiled.h
#	Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp
#	Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h
#	Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h
#	Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h
#	Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h
#	Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h
#	Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h
#	Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h
#	Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h
#	Gems/Twitch/Code/Source/Twitch_precompiled.h
#	Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h
#	Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h
#	Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
2021-07-16 15:42:37 -07:00

429 lines
14 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <qpushbutton.h>
#include <GraphCanvas/Components/GridBus.h>
#include <GraphCanvas/Components/Nodes/Group/NodeGroupBus.h>
#include <EditorAutomationTests/InteractionTests.h>
#include <Editor/GraphCanvas/GraphCanvasEditorNotificationBusId.h>
#include <ScriptCanvas/GraphCanvas/MappingBus.h>
#include <ScriptCanvas/Core/Node.h>
#include <ScriptCanvas/Core/NodeBus.h>
#include <ScriptCanvas/Bus/EditorScriptCanvasBus.h>
#include <ScriptCanvasDeveloperEditor/EditorAutomation/EditorAutomationStates/EditorViewStates.h>
#include <ScriptCanvasDeveloperEditor/EditorAutomation/EditorAutomationStates/ElementInteractionStates.h>
#include <ScriptCanvasDeveloperEditor/EditorAutomation/EditorAutomationStates/GraphStates.h>
#include <ScriptCanvasDeveloperEditor/EditorAutomation/EditorAutomationStates/UtilityStates.h>
namespace ScriptCanvasDeveloper
{
///////////////////////
// AltClickDeleteTest
///////////////////////
AltClickDeleteTest::AltClickDeleteTest()
: EditorAutomationTest("Alt Click Deletion Test")
{
AddState(new CreateRuntimeGraphState());
AutomationStateModelId onGraphStartTargetPointId = "OnGraphStartScenePoint";
AutomationStateModelId onGraphStartId = "OnGraphStartId";
AddState(new FindViewCenterState(onGraphStartTargetPointId));
AddState(new CreateNodeFromContextMenuState("On Graph Start", CreateNodeFromContextMenuState::CreationType::ScenePosition, onGraphStartTargetPointId, onGraphStartId));
AutomationStateModelId onGraphStartEndpoint = "OnGraphStart::ExecutionEndpoint";
AddState(new FindEndpointOfTypeState(onGraphStartId, onGraphStartEndpoint, GraphCanvas::CT_Output, GraphCanvas::SlotTypes::ExecutionSlot));
AutomationStateModelId buildStringNodeId = "BuildStringId";
AddState(new CreateNodeFromProposalState("Build String", onGraphStartEndpoint, "", buildStringNodeId));
AutomationStateModelId buildStringEndpoint = "BuildString::ExecutionEndpoint";
AddState(new FindEndpointOfTypeState(buildStringNodeId, buildStringEndpoint, GraphCanvas::CT_Output, GraphCanvas::SlotTypes::ExecutionSlot));
AutomationStateModelId printNodeId = "PrintNodeId";
AddState(new CreateNodeFromProposalState("Print", buildStringEndpoint, "", printNodeId));
AddState(new AltClickSceneElementState(buildStringNodeId));
AutomationStateModelId altClickConnectionTarget = "ConnectionTarget";
AddState(new GetLastConnection(onGraphStartEndpoint, altClickConnectionTarget));
AddState(new AltClickSceneElementState(altClickConnectionTarget));
AddState(new ForceCloseActiveGraphState());
}
//////////////////////////////
// CutCopyPasteDuplicateTest
//////////////////////////////
CutCopyPasteDuplicateTest::CheckpointState::CheckpointState(AZStd::string checkPoint)
: CustomActionState(checkPoint.c_str())
{
}
CutCopyPasteDuplicateTest::CutCopyPasteDuplicateTest(QString nodeName)
: EditorAutomationTest(QString("Cut/Copy/Paste/Duplicate %1 Test").arg(nodeName))
, m_originalNodeId("OriginalNodeId")
{
AddState(new CreateRuntimeGraphState());
AutomationStateModelId viewCenter = "ViewCenter";
AddState(new FindViewCenterState(viewCenter));
m_createNodeState = new CreateNodeFromContextMenuState(nodeName, CreateNodeFromContextMenuState::CreationType::ScenePosition, viewCenter, m_originalNodeId);
AddState(m_createNodeState);
AddState(new SelectSceneElementState(m_originalNodeId));
AddState(new TriggerHotKey(QChar('x'), "CutOriginal"));
AddState(new TriggerHotKey(QChar('v'), "PasteOriginal"));
m_cutPasteCheckpoint = new CheckpointState("Confirm Cut/Paste");
AddState(m_cutPasteCheckpoint);
AddState(new TriggerHotKey(QChar('c'), "CopyOriginal"));
AddState(new TriggerHotKey(QChar('v'), "PasteCopied"));
m_copyPasteCheckpoint = new CheckpointState("Confirm Copy/Paste");
AddState(m_copyPasteCheckpoint);
AddState(new TriggerHotKey(QChar('c'), "CopyCopied"));
AddState(new TriggerHotKey(QChar('v'), "PasteCopiedCopied"));
m_copyPasteCopyCheckpoint = new CheckpointState("Confirm Copy/Paste for Copy");
AddState(m_copyPasteCopyCheckpoint);
AddState(new TriggerHotKey(QChar('d'), "Duplicate"));
m_duplicateCheckpoint = new CheckpointState("Confirm Duplication");
AddState(m_duplicateCheckpoint);
AddState(new ForceCloseActiveGraphState());
}
void CutCopyPasteDuplicateTest::OnNodeAdded(const AZ::EntityId& nodeId, bool)
{
m_createdSet.insert(nodeId);
}
void CutCopyPasteDuplicateTest::OnNodeRemoved(const AZ::EntityId& nodeId)
{
if (nodeId == m_removalTarget)
{
m_removalTarget.SetInvalid();
}
}
void CutCopyPasteDuplicateTest::OnStateComplete(int stateId)
{
if (stateId == CreateRuntimeGraphStateId::StateID())
{
const GraphCanvas::GraphId* graphId = GetStateDataAs<GraphCanvas::GraphId>(StateModelIds::GraphCanvasId);
if (graphId)
{
GraphCanvas::SceneNotificationBus::Handler::BusConnect((*graphId));
}
}
else if (stateId == m_createNodeState->GetStateId())
{
const GraphCanvas::NodeId* nodeId = GetStateDataAs<GraphCanvas::GraphId>(m_originalNodeId);
if (nodeId)
{
m_removalTarget = (*nodeId);
m_createdSet.clear();
}
}
else if (stateId == m_cutPasteCheckpoint->GetStateId())
{
if (m_removalTarget.IsValid())
{
AddError("Cut failed to remove original element from the scene.");
}
else if (m_createdSet.empty())
{
AddError("Paste failed to add element to the scene.");
}
else
{
ProcessCreationSet();
}
}
else if (stateId == m_copyPasteCheckpoint->GetStateId()
|| stateId == m_copyPasteCopyCheckpoint->GetStateId())
{
if (m_createdSet.empty())
{
AddError("Paste failed to add element to the scene.");
}
else
{
ProcessCreationSet();
}
}
else if (stateId == stateId == m_duplicateCheckpoint->GetStateId())
{
if (m_createdSet.empty())
{
AddError("Duplicate failed to add element to the scene.");
}
else
{
ProcessCreationSet();
}
}
else if (stateId == ForceCloseActiveGraphStateId::StateID())
{
GraphCanvas::SceneNotificationBus::Handler::BusDisconnect();
}
}
void CutCopyPasteDuplicateTest::ProcessCreationSet()
{
AZ::EntityId testId;
for (GraphCanvas::NodeId nodeId : m_createdSet)
{
if (GraphCanvas::GraphUtils::IsNodeWrapped(nodeId))
{
continue;
}
testId = nodeId;
break;
}
m_createdSet.clear();
bool isSelected = false;
GraphCanvas::SceneMemberUIRequestBus::EventResult(isSelected, testId, &GraphCanvas::SceneMemberUIRequests::IsSelected);
if (!isSelected)
{
AddError("Pasted node is not selected by default.");
}
}
/*
bool CutCopyPasteDuplicateTest::TransitionToState(int state)
{
if (state == CutOriginalNode)
{
delete m_selectElement;
m_selectElement = aznew SelectSceneElementAction(m_target);
m_removalTarget = m_target;
m_actionRunner.AddAction(m_selectElement);
m_actionRunner.AddAction(&m_pressCtrlAction);
m_actionRunner.AddAction(&m_processEvents);
m_actionRunner.AddAction(&m_typeX);
m_actionRunner.AddAction(&m_processEvents);
m_actionRunner.AddAction(&m_releaseCtrlAction);
m_actionRunner.AddAction(&m_processEvents);
}
else if (state == PasteOriginalNode)
{
m_actionRunner.AddAction(&m_pressCtrlAction);
m_actionRunner.AddAction(&m_processEvents);
m_actionRunner.AddAction(&m_typeV);
m_actionRunner.AddAction(&m_processEvents);
m_actionRunner.AddAction(&m_releaseCtrlAction);
m_actionRunner.AddAction(&m_processEvents);
}
else if (state == CopyPasteOriginalNodeState)
{
m_actionRunner.AddAction(&m_pressCtrlAction);
m_actionRunner.AddAction(&m_processEvents);
m_actionRunner.AddAction(&m_typeC);
m_actionRunner.AddAction(&m_processEvents);
m_actionRunner.AddAction(&m_typeV);
m_actionRunner.AddAction(&m_processEvents);
m_actionRunner.AddAction(&m_releaseCtrlAction);
m_actionRunner.AddAction(&m_processEvents);
}
else if (state == CopyPasteDuplicatedNodeState)
{
m_actionRunner.AddAction(&m_pressCtrlAction);
m_actionRunner.AddAction(&m_processEvents);
m_actionRunner.AddAction(&m_typeC);
m_actionRunner.AddAction(&m_processEvents);
m_actionRunner.AddAction(&m_typeV);
m_actionRunner.AddAction(&m_processEvents);
m_actionRunner.AddAction(&m_releaseCtrlAction);
m_actionRunner.AddAction(&m_processEvents);
}
else if (state == DuplicateNodeState)
{
m_actionRunner.AddAction(&m_pressCtrlAction);
m_actionRunner.AddAction(&m_processEvents);
m_actionRunner.AddAction(&m_typeD);
m_actionRunner.AddAction(&m_processEvents);
m_actionRunner.AddAction(&m_releaseCtrlAction);
m_actionRunner.AddAction(&m_processEvents);
}
else if (state == ForceCloseGraphState)
{
m_actionRunner.AddAction(&m_forceCloseGraphAction);
}
return m_actionRunner.HasActions();
}
void CutCopyPasteDuplicateTest::OnTestComplete()
{
delete m_createFromContextMenu;
m_createFromContextMenu = nullptr;
GraphCanvas::SceneNotificationBus::Handler::BusDisconnect();
}
void CutCopyPasteDuplicateTest::OnStateComplete(int state)
{
if (state == CreateGraphState)
{
m_graphId = m_createNewGraphAction.GetGraphId();
GraphCanvas::SceneNotificationBus::Handler::BusConnect(m_graphId);
}
else if (state == CreateNodeState)
{
m_target = m_createFromContextMenu->GetCreatedNodeId();
m_createdSet.clear();
}
else if (state == CutOriginalNode)
{
if (m_removalTarget.IsValid())
{
AddError(QString("Failed to cut %1").arg(m_nodeName).toUtf8().data());
}
}
else if (state == PasteOriginalNode)
{
if (m_createdSet.empty())
{
AddError(QString("Failed to cut and paste original %1").arg(m_nodeName).toUtf8().data());
}
else
{
for (GraphCanvas::NodeId nodeId : m_createdSet)
{
if (GraphCanvas::GraphUtils::IsNodeWrapped(nodeId))
{
continue;
}
m_target = nodeId;
break;
}
m_createdSet.clear();
bool isSelected = false;
GraphCanvas::SceneMemberUIRequestBus::EventResult(isSelected, m_target, &GraphCanvas::SceneMemberUIRequests::IsSelected);
if (!isSelected)
{
AddError("Pasted node is not selected by default.");
}
}
}
else if (state == CopyPasteOriginalNodeState)
{
if (m_createdSet.empty())
{
AddError(QString("Failed to copy and paste original %1").arg(m_nodeName).toUtf8().data());
}
else
{
for (GraphCanvas::NodeId nodeId : m_createdSet)
{
if (GraphCanvas::GraphUtils::IsNodeWrapped(nodeId))
{
continue;
}
m_target = nodeId;
break;
}
m_createdSet.clear();
bool isSelected = false;
GraphCanvas::SceneMemberUIRequestBus::EventResult(isSelected, m_target, &GraphCanvas::SceneMemberUIRequests::IsSelected);
if (!isSelected)
{
AddError("Pasted node is not selected by default.");
}
}
}
else if (state == CopyPasteDuplicatedNodeState)
{
if (m_createdSet.empty())
{
AddError(QString("Failed to copy and paste duplicated %1").arg(m_nodeName).toUtf8().data());
}
else
{
for (GraphCanvas::NodeId nodeId : m_createdSet)
{
if (GraphCanvas::GraphUtils::IsNodeWrapped(nodeId))
{
continue;
}
m_target = nodeId;
break;
}
m_createdSet.clear();
bool isSelected = false;
GraphCanvas::SceneMemberUIRequestBus::EventResult(isSelected, m_target, &GraphCanvas::SceneMemberUIRequests::IsSelected);
if (!isSelected)
{
AddError("Pasted node is not selected by default.");
}
}
}
else if (state == DuplicateNodeState)
{
if (m_createdSet.empty())
{
AddError(QString("Failed to duplicate %1").arg(m_nodeName).toUtf8().data());
}
else
{
m_createdSet.clear();
}
}
}
bool CutCopyPasteDuplicateTest::CleanupAfterErrorState()
{
if (m_createNewGraphAction.GetGraphId().IsValid())
{
m_actionRunner.AddAction(&m_forceCloseGraphAction);
}
return m_actionRunner.HasActions();
}
*/
}