Pane_Undocked_ClosesSuccessfully.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. undock_pane = ("Pane is undocked successfully", "Failed to undock pane")
  9. close_sc_window = ("Script Canvas window is closed", "Failed to close Script Canvas window")
  10. pane_closed = ("Pane is closed successfully", "Failed to close the pane")
  11. # fmt: on
  12. def Pane_Undocked_ClosesSuccessfully():
  13. """
  14. Summary:
  15. The Script Canvas window is opened with one of the pane undocked.
  16. Verify if undocked pane closes upon closing Script canvas window.
  17. Expected Behavior:
  18. The undocked pane closes when Script Canvas window closed.
  19. Test Steps:
  20. 1) Open Script Canvas window (Tools > Script Canvas)
  21. 2) Undock Node Palette pane
  22. 3) Connect to Pane visibility signal emitter to verify pane closed
  23. 4) Close Script Canvas window
  24. 5) Restore default layout
  25. Note:
  26. - This test file must be called from the Open 3D Engine Editor command terminal
  27. - Any passed and failed tests are written to the Editor.log file.
  28. Parsing the file or running a log_monitor are required to observe the test results.
  29. :return: None
  30. """
  31. from PySide2 import QtWidgets
  32. # Helper imports
  33. from utils import Report
  34. from utils import TestHelper as helper
  35. import pyside_utils
  36. # Open 3D Engine imports
  37. import azlmbr.legacy.general as general
  38. TEST_PANE = "NodePalette" # Chosen most commonly used pane
  39. def click_menu_option(window, option_text):
  40. action = pyside_utils.find_child_by_pattern(window, {"text": option_text, "type": QtWidgets.QAction})
  41. action.trigger()
  42. def find_pane(window, pane_name):
  43. return window.findChild(QtWidgets.QDockWidget, pane_name)
  44. def on_top_level_changed():
  45. # This function has test condition always True since it gets emitted only when condition satisfied
  46. Report.result(Tests.undock_pane, True)
  47. def on_pane_closed():
  48. # This function has test condition always True since it gets emitted only when condition satisfied
  49. Report.result(Tests.pane_closed, True)
  50. # Test starts here
  51. general.idle_enable(True)
  52. # 1) Open Script Canvas window (Tools > Script Canvas)
  53. general.open_pane("Script Canvas")
  54. helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0)
  55. # 2) Undock Node Palette pane
  56. # Make sure Node Palette pane is opened
  57. editor_window = pyside_utils.get_editor_main_window()
  58. sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas")
  59. pane = find_pane(sc, TEST_PANE)
  60. if not pane.isVisible():
  61. click_menu_option(sc, "Node Palette")
  62. pane = find_pane(sc, TEST_PANE) # New reference
  63. # We drag/drop pane over the graph since it doesn't allow docking, so this will undock it
  64. try:
  65. graph = find_pane(sc, "GraphCanvasEditorCentralWidget")
  66. try:
  67. pane.topLevelChanged.connect(on_top_level_changed)
  68. pyside_utils.drag_and_drop(pane, graph)
  69. finally:
  70. pane.topLevelChanged.disconnect(on_top_level_changed)
  71. # 3) Connect to Pane visibility signal emitter to verify pane closed
  72. # No need to disconnect this since pane widget gets deleted when SC window closed
  73. pane.visibilityChanged.connect(on_pane_closed)
  74. # 4) Close Script Canvas window
  75. sc.close()
  76. is_sc_visible = helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 2.0)
  77. Report.result(Tests.close_sc_window, not is_sc_visible)
  78. finally:
  79. # 5) Restore default layout
  80. general.open_pane("Script Canvas")
  81. helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0)
  82. sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas")
  83. click_menu_option(sc, "Restore Default Layout")
  84. sc.close()
  85. if __name__ == "__main__":
  86. import ImportPathHelper as imports
  87. imports.init()
  88. from utils import Report
  89. Report.start_test(Pane_Undocked_ClosesSuccessfully)