NodeCategory_ExpandOnClick.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. from PySide2 import QtWidgets, QtTest, QtCore
  7. import pyside_utils
  8. from editor_python_test_tools.utils import TestHelper as helper
  9. from editor_python_test_tools.utils import Report
  10. import azlmbr.legacy.general as general
  11. import scripting_utils.scripting_tools as scripting_tools
  12. from scripting_utils.scripting_constants import WAIT_TIME_3, SCRIPT_CANVAS_UI, NODE_PALETTE_UI, NODE_PALETTE_QT,\
  13. TREE_VIEW_QT, NODE_CATEGORY_MATH
  14. # fmt: off
  15. class Tests:
  16. pane_close = ("Script Canvas pane successfully closed", "Script Canvas pane failed to close")
  17. pane_open = ("Script Canvas pane successfully opened", "Script Canvas pane failed to open")
  18. click_expand = ("Category expanded on left click", "Category failed to expand on left click")
  19. click_collapse = ("Category collapsed on left click", "Category failed to collapse on left click")
  20. dClick_expand = ("Category expanded on double click", "Category failed to expand on double click")
  21. dClick_collapse = ("Category collapsed on double click", "Category failed to collapse on double click")
  22. # fmt: on
  23. class NodeCategory_ExpandOnClick:
  24. """
  25. Summary:
  26. Verifying the expand/collapse functionality on node categories
  27. Expected Behavior:
  28. The node category should expand when double clicked or when the drop down indicator is
  29. left-clicked. Once expanded, it should be collapsed via the same actions.
  30. Test Steps:
  31. 1) Open Script Canvas pane
  32. 2) Get the SC window objects
  33. 3) Ensure all categories are collapsed for a clean state
  34. 4) Left-Click on a node category arrow to expand it and verify it's expanded
  35. 5) Left-Click on a node category arrow to collapse it and verify it's collapsed
  36. 6) Double-Click on a node category to expand it then verify it's expanded
  37. 7) Double-Click on a node category to collapse it and verify it's collapsed
  38. Note:
  39. - This test file must be called from the Open 3D Engine Editor command terminal
  40. - Any passed and failed tests are written to the Editor.log file.
  41. Parsing the file or running a log_monitor are required to observe the test results.
  42. :return: None
  43. """
  44. def __init__(self):
  45. self.editor_main_window = None
  46. self.sc_editor = None
  47. self.sc_editor_main_window = None
  48. def left_click_expander_button(self, node_palette_node_tree, category_index):
  49. rect_left_x = 1 # 1 pixel from the left side of the widget looks like where the expand button begins
  50. rect_center_y = node_palette_node_tree.visualRect(category_index).center().y()
  51. click_position = QtCore.QPoint(rect_left_x, rect_center_y)
  52. # click position relative to node palette tree view and not screen space xy
  53. QtTest.QTest.mouseClick(node_palette_node_tree.viewport(),
  54. QtCore.Qt.LeftButton,
  55. QtCore.Qt.NoModifier,
  56. click_position,
  57. )
  58. def double_click_node_category(self, node_palette_node_tree, index):
  59. item_index_center = node_palette_node_tree.visualRect(index).center()
  60. # Left click on the item before trying to double click, will otherwise fail to expand
  61. # as first click would highlight and second click would be a 'single click'
  62. pyside_utils.item_view_index_mouse_click(node_palette_node_tree, index)
  63. QtTest.QTest.mouseDClick(node_palette_node_tree.viewport(),
  64. QtCore.Qt.LeftButton,
  65. QtCore.Qt.NoModifier,
  66. item_index_center)
  67. def wait_and_verify_category_expanded_state(self, test_case, node_palette_node_tree, node_palette_math_category, expanded = True):
  68. category_has_expanded = helper.wait_for_condition(
  69. lambda: node_palette_node_tree.isExpanded(node_palette_math_category), WAIT_TIME_3)
  70. Report.result(test_case, expanded == category_has_expanded)
  71. @pyside_utils.wrap_async
  72. async def run_test(self):
  73. # Preconditions
  74. general.idle_enable(True)
  75. general.close_pane(SCRIPT_CANVAS_UI)
  76. helper.wait_for_condition(lambda: general.is_pane_visible(SCRIPT_CANVAS_UI) is None, WAIT_TIME_3)
  77. # 1) Open Script Canvas pane
  78. general.open_pane(SCRIPT_CANVAS_UI)
  79. Report.critical_result(Tests.pane_open, general.is_pane_visible(SCRIPT_CANVAS_UI))
  80. # 2) Get the SC window objects (editor, sc editor, node palette elements)
  81. scripting_tools.initialize_editor_object(self)
  82. scripting_tools.initialize_sc_editor_objects(self)
  83. scripting_tools.open_node_palette(self)
  84. # wait for the node palette and other SC elements to render
  85. helper.wait_for_condition(lambda: self.sc_editor.findChild(QtWidgets.QDockWidget, NODE_PALETTE_QT) is not None, WAIT_TIME_3)
  86. node_palette_node_tree = scripting_tools.get_node_palette_node_tree_qt_object(self)
  87. node_palette_math_category = scripting_tools.get_node_palette_category_qt_object(self, NODE_CATEGORY_MATH)
  88. # 3) Ensure all categories are collapsed for a clean state
  89. node_palette_node_tree.collapseAll()
  90. # 4) Left-Click on a node category arrow to expand it and verify it's expanded
  91. self.left_click_expander_button(node_palette_node_tree, node_palette_math_category)
  92. self.wait_and_verify_category_expanded_state(Tests.click_expand, node_palette_node_tree, node_palette_math_category)
  93. # 5) Left-Click on a node category arrow to collapse it and verify it's collapsed
  94. self.left_click_expander_button(node_palette_node_tree, node_palette_math_category)
  95. self.wait_and_verify_category_expanded_state(Tests.click_collapse, node_palette_node_tree, node_palette_math_category, False)
  96. # 6) Double-Click on a node category to expand it then verify it's expanded
  97. self.double_click_node_category(node_palette_node_tree, node_palette_math_category)
  98. self.wait_and_verify_category_expanded_state(Tests.dClick_expand, node_palette_node_tree, node_palette_math_category)
  99. # 7) Double-Click on a node category to collapse it and verify it's collapsed
  100. self.double_click_node_category(node_palette_node_tree, node_palette_math_category)
  101. self.wait_and_verify_category_expanded_state(Tests.dClick_collapse, node_palette_node_tree, node_palette_math_category, False)
  102. test = NodeCategory_ExpandOnClick()
  103. test.run_test()