Pane_HappyPath_DocksProperly.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. pane_opened = ("Pane is opened successfully", "Failed to open pane")
  9. dock_pane = ("Pane is docked successfully", "Failed to dock Pane into one or more allowed area")
  10. # fmt: on
  11. def Pane_HappyPath_DocksProperly():
  12. """
  13. Summary:
  14. The Script Canvas window is opened to verify if Script canvas panes can be docked into every
  15. possible area of Script Canvas main window. (top, bottom, right and left sides of the window)
  16. Expected Behavior:
  17. The pane docks successfully.
  18. Test Steps:
  19. 1) Open Script Canvas window (Tools > Script Canvas)
  20. 2) Make sure Node Palette pane is opened
  21. 3) Dock the Node Palette pane into every possible area of main window
  22. 4) Restore default layout
  23. 5) Close Script Canvas window
  24. Note:
  25. - This test file must be called from the Open 3D Engine Editor command terminal
  26. - Any passed and failed tests are written to the Editor.log file.
  27. Parsing the file or running a log_monitor are required to observe the test results.
  28. :return: None
  29. """
  30. from editor_python_test_tools.utils import Report
  31. from editor_python_test_tools.utils import TestHelper as helper
  32. import pyside_utils
  33. # Open 3D Engine imports
  34. import azlmbr.legacy.general as general
  35. # Pyside imports
  36. from PySide2 import QtCore, QtWidgets
  37. from PySide2.QtCore import Qt
  38. PANE_WIDGET = "NodePalette" # Chosen most commonly used pane
  39. DOCKAREAS = [Qt.TopDockWidgetArea, Qt.BottomDockWidgetArea, Qt.RightDockWidgetArea, Qt.LeftDockWidgetArea]
  40. DOCKED = True
  41. def click_menu_option(window, option_text):
  42. action = pyside_utils.find_child_by_pattern(window, {"text": option_text, "type": QtWidgets.QAction})
  43. action.trigger()
  44. def find_pane(window, pane_name):
  45. return window.findChild(QtWidgets.QDockWidget, pane_name)
  46. # Test starts here
  47. general.idle_enable(True)
  48. # 1) Open Script Canvas window (Tools > Script Canvas)
  49. general.open_pane("Script Canvas")
  50. helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0)
  51. # 2) Make sure Node Palette pane is opened
  52. editor_window = pyside_utils.get_editor_main_window()
  53. sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas")
  54. sc_main = sc.findChild(QtWidgets.QMainWindow)
  55. pane = find_pane(sc_main, PANE_WIDGET)
  56. if not pane.isVisible():
  57. click_menu_option(sc, "Node Palette")
  58. pane = find_pane(sc_main, PANE_WIDGET) # New reference
  59. Report.result(Tests.pane_opened, pane.isVisible())
  60. # 3) Dock the Node Palette pane into every possible area of main window
  61. for area in DOCKAREAS:
  62. sc_main.addDockWidget(area, find_pane(sc_main, PANE_WIDGET), QtCore.Qt.Vertical)
  63. if not (sc_main.dockWidgetArea(find_pane(sc_main, PANE_WIDGET)) == area):
  64. Report.info(f"Failed to dock into {str(area)}")
  65. DOCKED = DOCKED and (sc_main.dockWidgetArea(find_pane(sc_main, PANE_WIDGET)) == area)
  66. Report.result(Tests.dock_pane, DOCKED)
  67. # 4) Restore default layout
  68. # Need this step to restore to default in case of test failure
  69. click_menu_option(sc, "Restore Default Layout")
  70. # 5) Close Script Canvas window
  71. sc.close()
  72. if __name__ == "__main__":
  73. import ImportPathHelper as imports
  74. imports.init()
  75. from editor_python_test_tools.utils import Report
  76. Report.start_test(Pane_HappyPath_DocksProperly)