Improved Command class management.
This commit is contained in:
@@ -45,7 +45,7 @@ def test_i_can_mk_button_with_attrs():
|
||||
def test_i_can_mk_button_with_command(user, rt):
|
||||
def new_value(value): return value
|
||||
|
||||
command = Command('test', 'TestingCommand', None, new_value, "this is my new value")
|
||||
command = Command('test', 'TestingCommand', None, new_value, args=["this is my new value"])
|
||||
|
||||
@rt('/')
|
||||
def get(): return mk.button('button', command)
|
||||
|
||||
@@ -464,20 +464,20 @@ class TestTreeviewBehaviour:
|
||||
def test_i_cannot_ensure_path_with_none(self, root_instance):
|
||||
"""Test that ensure_path raises ValueError when path is None."""
|
||||
tree_view = TreeView(root_instance)
|
||||
|
||||
|
||||
with pytest.raises(ValueError, match="Invalid path.*None"):
|
||||
tree_view.ensure_path(None)
|
||||
|
||||
|
||||
def test_i_cannot_ensure_path_with_empty_string(self, root_instance):
|
||||
"""Test that ensure_path raises ValueError for empty strings after stripping."""
|
||||
tree_view = TreeView(root_instance)
|
||||
|
||||
|
||||
with pytest.raises(ValueError, match="Invalid path.*empty"):
|
||||
tree_view.ensure_path(" ")
|
||||
|
||||
|
||||
with pytest.raises(ValueError, match="Invalid path.*empty"):
|
||||
tree_view.ensure_path("")
|
||||
|
||||
|
||||
with pytest.raises(ValueError, match="Invalid path.*empty"):
|
||||
tree_view.ensure_path("...")
|
||||
|
||||
@@ -531,44 +531,57 @@ class TestTreeviewBehaviour:
|
||||
def test_i_cannot_ensure_path_with_only_spaces_parts(self, root_instance):
|
||||
"""Test that ensure_path raises ValueError for path parts with only spaces."""
|
||||
tree_view = TreeView(root_instance)
|
||||
|
||||
|
||||
with pytest.raises(ValueError, match="Invalid path"):
|
||||
tree_view.ensure_path("folder1. .folder2")
|
||||
|
||||
|
||||
def test_ensure_path_returns_last_node_id(self, root_instance):
|
||||
"""Test that ensure_path returns the ID of the last node in the path."""
|
||||
tree_view = TreeView(root_instance)
|
||||
|
||||
|
||||
# Create a path and get the returned ID
|
||||
returned_id = tree_view.ensure_path("folder1.folder2.folder3")
|
||||
|
||||
|
||||
# Verify the returned ID is not None
|
||||
assert returned_id is not None
|
||||
|
||||
|
||||
# Verify the returned ID corresponds to folder3
|
||||
assert returned_id in tree_view._state.items
|
||||
assert tree_view._state.items[returned_id].label == "folder3"
|
||||
|
||||
|
||||
# Verify we can use this ID to add a child
|
||||
leaf = TreeNode(label="file.txt", type="file")
|
||||
tree_view.add_node(leaf, parent_id=returned_id)
|
||||
|
||||
|
||||
assert leaf.parent == returned_id
|
||||
assert leaf.id in tree_view._state.items[returned_id].children
|
||||
|
||||
|
||||
def test_ensure_path_returns_existing_node_id(self, root_instance):
|
||||
"""Test that ensure_path returns ID even when path already exists."""
|
||||
tree_view = TreeView(root_instance)
|
||||
|
||||
|
||||
# Create initial path
|
||||
first_id = tree_view.ensure_path("folder1.folder2")
|
||||
|
||||
|
||||
# Ensure same path again
|
||||
second_id = tree_view.ensure_path("folder1.folder2")
|
||||
|
||||
|
||||
# Should return the same ID
|
||||
assert first_id == second_id
|
||||
assert tree_view._state.items[first_id].label == "folder2"
|
||||
|
||||
def test_i_can_add_the_same_node_id_twice(self, root_instance):
|
||||
"""Test that adding a node with the same ID as an existing node raises ValueError."""
|
||||
tree_view = TreeView(root_instance)
|
||||
|
||||
node1 = TreeNode(label="Node", type="folder", id="existing_id")
|
||||
tree_view.add_node(node1)
|
||||
|
||||
node2 = TreeNode(label="Other Node", type="folder", id="existing_id")
|
||||
tree_view.add_node(node2)
|
||||
|
||||
assert len(tree_view._state.items) == 1, "Node should not have been added to items"
|
||||
assert tree_view._state.items[node1.id] == node2, "Node should not have been replaced"
|
||||
|
||||
|
||||
class TestTreeViewRender:
|
||||
|
||||
Reference in New Issue
Block a user