EditMenu_Default_UndoRedo.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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
  7. import PySide2.QtCore as QtCore
  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 pyside_utils
  12. import scripting_utils.scripting_tools as scripting_tools
  13. from scripting_utils.scripting_constants import (WAIT_TIME_3, SCRIPT_CANVAS_UI, VARIABLE_TYPES, GRAPH_VARIABLES_QT)
  14. # fmt: off
  15. class Tests():
  16. variable_created = ("New variable created", "New variable not created")
  17. undo_worked = ("Undo action working", "Undo action did not work")
  18. redo_worked = ("Redo action working", "Redo action did not work")
  19. # fmt: on
  20. class EditMenu_Default_UndoRedo:
  21. """
  22. Summary:
  23. Edit > Undo undoes the last action
  24. Edit > Redo redoes the last undone action
  25. We create a new variable in variable manager, undo and verify if variable is removed,
  26. redo it and verify if the variable is created again.
  27. Expected Behavior:
  28. The last action is undone upon selecting Undo.
  29. The last undone action is redone upon selecting Redo.
  30. Test Steps:
  31. 1) Open Script Canvas window (Tools > Script Canvas)
  32. 2) Open Variable Manager if not opened already
  33. 3) Create Graph
  34. 4) Create and verify the new variable exists in variable manager
  35. 5) Trigger Undo action and verify if variable is removed in Variable Manager
  36. 6) Trigger Redo action and verify if variable is re-added in Variable Manager
  37. 7) Close SC window
  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. self.variable_manager = None
  49. def get_graph_variables_row_count(self, graph_variables):
  50. return graph_variables.model().rowCount(QtCore.QModelIndex())
  51. @pyside_utils.wrap_async
  52. async def run_test(self):
  53. # Preconditions
  54. general.idle_enable(True)
  55. scripting_tools.initialize_editor_object(self)
  56. # 1) Open Script Canvas window and initialize the qt SC objects
  57. general.open_pane(SCRIPT_CANVAS_UI)
  58. helper.wait_for_condition(lambda: general.is_pane_visible(SCRIPT_CANVAS_UI), WAIT_TIME_3)
  59. scripting_tools.initialize_sc_editor_objects(self)
  60. # 2) Open Variable Manager if not opened already
  61. scripting_tools.initialize_variable_manager_object(self)
  62. # 3) Create Graph
  63. scripting_tools.create_new_sc_graph(self.sc_editor_main_window)
  64. # 4) Create and verify the new variable exists in variable manager
  65. scripting_tools.create_new_variable(self, VARIABLE_TYPES[0])
  66. graph_variables = self.variable_manager.findChild(QtWidgets.QTableView, GRAPH_VARIABLES_QT)
  67. row_count = 1
  68. Report.result(Tests.variable_created, helper.wait_for_condition(
  69. lambda: self.get_graph_variables_row_count(graph_variables) == row_count, WAIT_TIME_3))
  70. # 5) Trigger Undo action and verify if variable is removed in Variable Manager
  71. undo_redo_action = self.sc_editor.findChild(QtWidgets.QAction, "action_Undo")
  72. undo_redo_action.trigger()
  73. row_count = 0
  74. Report.result(Tests.undo_worked, helper.wait_for_condition(
  75. lambda: self.get_graph_variables_row_count(graph_variables) == row_count, WAIT_TIME_3))
  76. # 6) Trigger Redo action and verify if variable is re-added in Variable Manager
  77. undo_redo_action = self.sc_editor.findChild(QtWidgets.QAction, "action_Redo")
  78. undo_redo_action.trigger()
  79. row_count = 1
  80. Report.result(Tests.redo_worked, helper.wait_for_condition(
  81. lambda: self.get_graph_variables_row_count(graph_variables) == row_count, WAIT_TIME_3))
  82. # 7) Close SC window
  83. general.close_pane(SCRIPT_CANVAS_UI)
  84. test = EditMenu_Default_UndoRedo()
  85. test.run_test()