Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI, Test Explorer:] Reimplement tree vs flat view #661

Open
MikeSchulze opened this issue Feb 4, 2025 · 1 comment
Open

[UI, Test Explorer:] Reimplement tree vs flat view #661

MikeSchulze opened this issue Feb 4, 2025 · 1 comment
Assignees

Comments

@MikeSchulze
Copy link
Owner

MikeSchulze commented Feb 4, 2025

A Task is not a bug or feature request

Description

We removed the tree mode handling to create a flat or tree presentation and needs to reimplement it.

Acceptance criteria

implement a new way to restructure the existing tree into flat or tree presentation.

  • add_test_case should respect the current tree view mode to create the items
  • connect to tree view mode changed signal to restructure the tree
@MikeSchulze MikeSchulze self-assigned this Feb 4, 2025
@MikeSchulze
Copy link
Owner Author


func _expand_folders() -> void:
	pass


## Collects the full path of given item
func _get_parent_folder_path(item: TreeItem) -> String:
	var path := ""
	var parent := item.get_parent()

	while parent != _tree_root:
		if is_folder(parent):
			path = parent.get_meta(META_GDUNIT_NAME) + ("/" + path if path else "")
		parent = parent.get_parent()

	return path


## Returns dictionary where key is flattened folder path and value is array of child items
func _flatmap_folders(parent: TreeItem = _tree_root) -> Dictionary:
	var folder_map := {}

	for item in parent.get_children():
		if is_folder(item):
			var current_path: String = item.get_meta(META_GDUNIT_NAME)
			# Get parent folder paths
			var parent_path := _get_parent_folder_path(item)
			if parent_path:
				current_path = parent_path + "/" + current_path

			# Collect direct children of this folder
			var children := []
			for child in item.get_children():
				if is_test_suite(child):
					children.append(child)

			# Add children to existing path or create new entry
			if not children.is_empty():
				if folder_map.has(current_path):
					folder_map[current_path].append_array(children)
				else:
					folder_map[current_path] = children

			# Recursively process subfolders
			var sub_folders := _flatmap_folders(item)
			for path: String in sub_folders.keys():
				if folder_map.has(path):
					folder_map[path].append_array(sub_folders[path])
				else:
					folder_map[path] = sub_folders[path]
	return folder_map


    func _on_restructure_tree(new_mode_flat: bool) -> void:
    	_tree_view_mode_flat = new_mode_flat
    	if new_mode_flat:
    		var flatmapped_by_folders: =_flatmap_folders()
    		# TODO reorder and replace folders with the new flatmapped_by_folders on the
    	else:
    		_expand_folders()
    	sort_tree_items(_tree_root)

tests


func test_flatmap_folders() -> void:
	_inspector.init_tree()
	_inspector.add_test_case(GdUnitTestCase.from("res://addons/gdUnit4/test/dir_a/suite_a.gd", 0, "test_a"))
	_inspector.add_test_case(GdUnitTestCase.from("res://addons/gdUnit4/test/dir_a/suite_b.gd", 0, "test_a"))
	_inspector.add_test_case(GdUnitTestCase.from("res://addons/gdUnit4/test/dir_a/dir_b/suite_a_b.gd", 0, "test_foo"))
	_inspector.add_test_case(GdUnitTestCase.from("res://addons/gdUnit4/test/dir_a/dir_b/suite_a_b.gd", 0, "test_bar"))
	_inspector.add_test_case(GdUnitTestCase.from("res://addons/gdUnit4/test/dir_a/dir_b/suite_a_b.gd", 0, "test_parameterized", 0, "1.2"))
	_inspector.add_test_case(GdUnitTestCase.from("res://addons/gdUnit4/test/dir_a/dir_b/suite_a_b.gd", 0, "test_parameterized", 1, "2.2"))
	_inspector.add_test_case(GdUnitTestCase.from("res://addons/gdUnit4/test/dir_a/dir_x/dir_y/suite_a_x1.gd", 0, "test_foo"))
	_inspector.add_test_case(GdUnitTestCase.from("res://addons/gdUnit4/test/dir_a/dir_x/dir_y/suite_a_x2.gd", 0, "test_foo"))

	var suite_a := find_suite_item("suite_a")
	var suite_b := find_suite_item("suite_b")
	var suite_a_b := find_suite_item("suite_a_b")
	var suite_a_x1 := find_suite_item("suite_a_x1")
	var suite_a_x2 := find_suite_item("suite_a_x2")

	var result := _inspector._flatmap_folders()
	assert_dict(result).is_equal({
		"dir_a" : [suite_a, suite_b],
		"dir_a/dir_b" : [suite_a_b],
		"dir_a/dir_x/dir_y" : [suite_a_x1, suite_a_x2]
	})


    func find_suite_item(name: String, parent: TreeItem = _inspector._tree_root) -> TreeItem:
    	for item in parent.get_children():
    		if item.get_meta(_inspector.META_GDUNIT_TYPE) == _inspector.GdUnitType.TEST_SUITE:
    			if item.get_meta(_inspector.META_GDUNIT_NAME) == name:
    				return item
    		var suite_item := find_suite_item(name, item)
    		if suite_item != null:
    			return suite_item
    	return null

@MikeSchulze MikeSchulze changed the title [Test Explorer:] Reimplement tree vs flat view [UI, Test Explorer:] Reimplement tree vs flat view Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant