Graph_HappyPath_ZoomInZoomOut.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. zoom_in = ("Zoom In action working as expected", "Zoom In action not working as expected")
  9. zoom_out = ("Zoom Out action working as expected", "Zoom Out action not working as expected")
  10. # fmt: on
  11. GENERAL_WAIT = 0.5 # seconds
  12. def Graph_HappyPath_ZoomInZoomOut():
  13. """
  14. Summary:
  15. The graph can be zoomed in and zoomed out.
  16. Expected Behavior:
  17. The graph is zoomed in when when we click View->ZoomIn
  18. The graph is zoomed out when when we click View->ZoomOut
  19. Test Steps:
  20. 1) Open Script Canvas window (Tools > Script Canvas)
  21. 2) Get the SC window object
  22. 3) Create new graph
  23. 4) Get initial graph transform values
  24. 5) Trigger Zoom In and verify if the graph transform scale is increased
  25. 6) Trigger Zoom Out and verify if the graph transform scale is decreased
  26. 7) Close Script Canvas window
  27. Note:
  28. - This test file must be called from the Open 3D Engine Editor command terminal
  29. - Any passed and failed tests are written to the Editor.log file.
  30. Parsing the file or running a log_monitor are required to observe the test results.
  31. :return: None
  32. """
  33. # Helper imports
  34. import ImportPathHelper as imports
  35. imports.init()
  36. from PySide2 import QtWidgets
  37. import azlmbr.legacy.general as general
  38. import pyside_utils
  39. from utils import TestHelper as helper
  40. from utils import Report
  41. # 1) Open Script Canvas window (Tools > Script Canvas)
  42. general.idle_enable(True)
  43. general.open_pane("Script Canvas")
  44. helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0)
  45. # 2) Get the SC window object
  46. editor_window = pyside_utils.get_editor_main_window()
  47. sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas")
  48. sc_main = sc.findChild(QtWidgets.QMainWindow)
  49. # 3) Create new graph
  50. create_new_graph = pyside_utils.find_child_by_pattern(
  51. sc_main, {"objectName": "action_New_Script", "type": QtWidgets.QAction}
  52. )
  53. create_new_graph.trigger()
  54. # 4) Get initial graph transform values
  55. graphics_view = sc_main.findChild(QtWidgets.QGraphicsView)
  56. # NOTE: transform m11 and m22 are horizontal and vertical scales of graph
  57. # they increase when zoomed in and decreased when zoomed out
  58. curr_m11, curr_m22 = graphics_view.transform().m11(), graphics_view.transform().m22()
  59. # 5) Trigger Zoom In and verify if the graph transform scale is increased
  60. zin = pyside_utils.find_child_by_pattern(sc_main, {"objectName": "action_ZoomIn", "type": QtWidgets.QAction})
  61. zin.trigger()
  62. result = helper.wait_for_condition(
  63. lambda: curr_m11 < graphics_view.transform().m11() and curr_m22 < graphics_view.transform().m22(), GENERAL_WAIT
  64. )
  65. Report.result(Tests.zoom_in, result)
  66. # 6) Trigger Zoom Out and verify if the graph transform scale is decreased
  67. curr_m11, curr_m22 = graphics_view.transform().m11(), graphics_view.transform().m22()
  68. zout = pyside_utils.find_child_by_pattern(sc_main, {"objectName": "action_ZoomOut", "type": QtWidgets.QAction})
  69. zout.trigger()
  70. result = helper.wait_for_condition(
  71. lambda: curr_m11 > graphics_view.transform().m11() and curr_m22 > graphics_view.transform().m22(), GENERAL_WAIT
  72. )
  73. Report.result(Tests.zoom_out, result)
  74. # 7) Close Script Canvas window
  75. general.close_pane("Script Canvas")
  76. if __name__ == "__main__":
  77. import ImportPathHelper as imports
  78. imports.init()
  79. from utils import Report
  80. Report.start_test(Graph_HappyPath_ZoomInZoomOut)