Skip to content

Commit

Permalink
GD-573: Fixed the inspector double-click, inherited tests to jump to …
Browse files Browse the repository at this point in the history
…the script where the test are located (#574)

# Why
see #573

# What
- use the `script_path` provided by the test case and enrich the
inspector item with this metadata `META_SCRIPT_PATH`
- use the `META_SCRIPT_PATH` on select event to jump to the script where
the test are located
  • Loading branch information
MikeSchulze authored Sep 19, 2024
1 parent 00159ba commit 3612ef5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
12 changes: 12 additions & 0 deletions addons/gdUnit4/src/network/rpc/dtos/GdUnitTestCaseDto.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class_name GdUnitTestCaseDto
extends GdUnitResourceDto

var _line_number :int = -1
var _script_path: String
var _test_case_names :PackedStringArray = []


Expand All @@ -11,6 +12,12 @@ func serialize(test_case :Node) -> Dictionary:
serialized["line_number"] = test_case.line_number()
else:
serialized["line_number"] = test_case.get("LineNumber")
if test_case.has_method("script_path"):
serialized["script_path"] = test_case.script_path()
else:
# TODO 'script_path' needs to be implement in c# the the
# serialized["script_path"] = test_case.get("ScriptPath")
serialized["script_path"] = serialized["resource_path"]
if test_case.has_method("test_case_names"):
serialized["test_case_names"] = test_case.test_case_names()
elif test_case.has_method("TestCaseNames"):
Expand All @@ -21,6 +28,7 @@ func serialize(test_case :Node) -> Dictionary:
func deserialize(data :Dictionary) -> GdUnitResourceDto:
super.deserialize(data)
_line_number = data.get("line_number", -1)
_script_path = data.get("script_path", data.get("resource_path", ""))
_test_case_names = data.get("test_case_names", [])
return self

Expand All @@ -29,5 +37,9 @@ func line_number() -> int:
return _line_number


func script_path() -> String:
return _script_path


func test_case_names() -> PackedStringArray:
return _test_case_names
17 changes: 11 additions & 6 deletions addons/gdUnit4/src/ui/parts/InspectorTreeMainPanel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const META_GDUNIT_ORPHAN := "gdUnit_orphan"
const META_GDUNIT_EXECUTION_TIME := "gdUnit_execution_time"
const META_RESOURCE_PATH := "resource_path"
const META_LINE_NUMBER := "line_number"
const META_SCRIPT_PATH := "script_path"
const META_TEST_PARAM_INDEX := "test_param_index"

var _tree_root: TreeItem
Expand Down Expand Up @@ -848,6 +849,7 @@ func add_test(parent: TreeItem, test_case: GdUnitTestCaseDto) -> void:
item.set_meta(META_GDUNIT_SUCCESS_TESTS, 0)
item.set_meta(META_GDUNIT_EXECUTION_TIME, 0)
item.set_meta(META_GDUNIT_TOTAL_TESTS, test_case_names.size())
item.set_meta(META_SCRIPT_PATH, test_case.script_path())
item.set_meta(META_LINE_NUMBER, test_case.line_number())
item.set_meta(META_TEST_PARAM_INDEX, -1)
set_item_icon_by_state(item)
Expand All @@ -870,6 +872,7 @@ func add_test_cases(parent: TreeItem, test_case_names: PackedStringArray) -> voi
item.set_meta(META_GDUNIT_TYPE, GdUnitType.TEST_CASE_PARAMETERIZED)
item.set_meta(META_GDUNIT_EXECUTION_TIME, 0)
item.set_meta(META_RESOURCE_PATH, resource_path)
item.set_meta(META_SCRIPT_PATH, parent.get_meta(META_SCRIPT_PATH))
item.set_meta(META_LINE_NUMBER, parent.get_meta(META_LINE_NUMBER))
item.set_meta(META_TEST_PARAM_INDEX, index)
set_item_icon_by_state(item)
Expand Down Expand Up @@ -937,10 +940,13 @@ func _on_Tree_item_selected() -> void:
# Opens the test suite
func _on_Tree_item_activated() -> void:
var selected_item := _tree.get_selected()
var resource_path: String = selected_item.get_meta(META_RESOURCE_PATH)
if selected_item.has_meta(META_LINE_NUMBER):
if selected_item != null and selected_item.has_meta(META_LINE_NUMBER):
var script_path: String = (
selected_item.get_meta(META_RESOURCE_PATH) if is_test_suite(selected_item)
else selected_item.get_meta(META_SCRIPT_PATH)
)
var line_number: int = selected_item.get_meta(META_LINE_NUMBER)
var resource := load(resource_path)
var resource := load(script_path)

if selected_item.has_meta(META_GDUNIT_REPORT):
var reports := get_item_reports(selected_item)
Expand All @@ -950,9 +956,8 @@ func _on_Tree_item_activated() -> void:
if report_line_number != -1:
line_number = report_line_number

EditorInterface.get_file_system_dock().navigate_to_path(resource_path)
EditorInterface.edit_resource(resource)
EditorInterface.get_script_editor().goto_line(line_number - 1)
EditorInterface.get_file_system_dock().navigate_to_path(script_path)
EditorInterface.edit_script(resource, line_number)
elif selected_item.get_meta(META_GDUNIT_TYPE) == GdUnitType.FOLDER:
# Toggle collapse if dir
selected_item.collapsed = not selected_item.collapsed
Expand Down

0 comments on commit 3612ef5

Please sign in to comment.