NodeInspector_HappyPath_VariableRenames.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. # fmt: off
  7. class Tests():
  8. variable_created = ("New variable created", "New variable is not created")
  9. node_inspector_rename = ("Variable is renamed in Node Inspector", "Variable is not renamed in Node Inspector")
  10. variable_manager_rename = ("Variable is renamed in Variable Manager", "Variable is not renamed in Variable Manager")
  11. # fmt: on
  12. GENERAL_WAIT = 0.5 # seconds
  13. def NodeInspector_HappyPath_VariableRenames():
  14. """
  15. Summary:
  16. Renaming variables in the Node Inspector, renames the actual variable.
  17. Expected Behavior:
  18. The Variable's name is changed in both Node Inspector and Variable Manager.
  19. Test Steps:
  20. 1) Open Script Canvas window (Tools > Script Canvas)
  21. 2) Get the SC window object
  22. 3) Open Variable Manager if not opened already
  23. 4) Open Node Inspector if not opened already
  24. 5) Create new graph and a new variable in Variable manager
  25. 6) Click on the variable
  26. 7) Update name in Node Inspector and click on ENTER
  27. 8) Verify if the name is updated in Node inspector and Variable manager
  28. 9) Close Script Canvas window
  29. Note:
  30. - This test file must be called from the Open 3D Engine Editor command terminal
  31. - Any passed and failed tests are written to the Editor.log file.
  32. Parsing the file or running a log_monitor are required to observe the test results.
  33. :return: None
  34. """
  35. from PySide2 import QtWidgets, QtCore, QtTest
  36. from PySide2.QtCore import Qt
  37. import pyside_utils
  38. from utils import TestHelper as helper
  39. import azlmbr.legacy.general as general
  40. TEST_NAME = "test name"
  41. def open_tool(sc, dock_widget_name, pane_name):
  42. if sc.findChild(QtWidgets.QDockWidget, dock_widget_name) is None:
  43. action = pyside_utils.find_child_by_pattern(sc, {"text": pane_name, "type": QtWidgets.QAction})
  44. action.trigger()
  45. tool = sc.findChild(QtWidgets.QDockWidget, dock_widget_name)
  46. return tool
  47. # 1) Open Script Canvas window
  48. general.idle_enable(True)
  49. general.open_pane("Script Canvas")
  50. helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0)
  51. # 2) Get the SC window object
  52. editor_window = pyside_utils.get_editor_main_window()
  53. sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas")
  54. # 3) Open Variable Manager if not opened already
  55. variable_manager = open_tool(sc, "VariableManager", "Variable Manager")
  56. # 4) Open Node Inspector if not opened already
  57. node_inspector = open_tool(sc, "NodeInspector", "Node Inspector")
  58. # 5) Create new graph and a new variable in Variable manager
  59. action = pyside_utils.find_child_by_pattern(sc, {"objectName": "action_New_Script", "type": QtWidgets.QAction})
  60. action.trigger()
  61. graph_vars = variable_manager.findChild(QtWidgets.QTableView, "graphVariables")
  62. add_button = variable_manager.findChild(QtWidgets.QPushButton, "addButton")
  63. add_button.click()
  64. # Select variable type
  65. table_view = variable_manager.findChild(QtWidgets.QTableView, "variablePalette")
  66. model_index = pyside_utils.find_child_by_pattern(table_view, "Boolean")
  67. # Click on it to create variable
  68. pyside_utils.item_view_index_mouse_click(table_view, model_index)
  69. result = graph_vars.model().rowCount(QtCore.QModelIndex()) == 1
  70. var_mi = pyside_utils.find_child_by_pattern(graph_vars, "Variable 1")
  71. result = result and (var_mi is not None)
  72. Report.critical_result(Tests.variable_created, result)
  73. # 6) Click on the variable
  74. pyside_utils.item_view_index_mouse_click(graph_vars, var_mi)
  75. # 7) Update name in Node Inspector and click on ENTER
  76. helper.wait_for_condition(
  77. lambda: node_inspector.findChild(QtWidgets.QWidget, "ContainerForRows") is not None, GENERAL_WAIT
  78. )
  79. row_container = node_inspector.findChild(QtWidgets.QWidget, "ContainerForRows")
  80. name_frame = row_container.findChild(QtWidgets.QWidget, "Name")
  81. name_line_edit = name_frame.findChild(QtWidgets.QLineEdit)
  82. name_line_edit.setText(TEST_NAME)
  83. QtTest.QTest.keyClick(name_line_edit, Qt.Key_Return, Qt.NoModifier)
  84. # 8) Verify if the name is updated in Node inspector and Variable manager
  85. helper.wait_for_condition(lambda: var_mi.data(Qt.DisplayRole) == TEST_NAME, GENERAL_WAIT)
  86. Report.critical_result(Tests.node_inspector_rename, name_line_edit.text() == TEST_NAME)
  87. Report.critical_result(Tests.variable_manager_rename, var_mi.data(Qt.DisplayRole) == TEST_NAME)
  88. # 9) Close Script Canvas window
  89. general.close_pane("Script Canvas")
  90. if __name__ == "__main__":
  91. import ImportPathHelper as imports
  92. imports.init()
  93. from utils import Report
  94. Report.start_test(NodeInspector_HappyPath_VariableRenames)