Improved Command class management.
This commit is contained in:
@@ -33,9 +33,15 @@ class TestCommandDefault:
|
||||
assert command.description == 'Command description'
|
||||
assert command.execute() == "Hello World"
|
||||
|
||||
def test_command_are_registered(self):
|
||||
def test_commands_are_registered(self):
|
||||
command = Command('test', 'Command description', None, callback)
|
||||
assert CommandsManager.commands.get(str(command.id)) is command
|
||||
|
||||
def test_commands_with_the_same_key_share_the_same_id(self):
|
||||
command1 = Command('test', 'Command description', None, None, key="test_key")
|
||||
command2 = Command('test', 'Command description', None, None, key="test_key")
|
||||
|
||||
assert command1.id is command2.id
|
||||
|
||||
|
||||
class TestCommandBind:
|
||||
@@ -74,7 +80,7 @@ class TestCommandBind:
|
||||
|
||||
res = command.execute()
|
||||
|
||||
assert res == ["another callback result", ("hello", "new value")]
|
||||
assert res == ["another callback result", "hello", "new value"]
|
||||
|
||||
def test_i_can_bind_a_command_to_an_observable_2(self):
|
||||
data = Data("hello")
|
||||
@@ -92,7 +98,7 @@ class TestCommandBind:
|
||||
|
||||
res = command.execute()
|
||||
|
||||
assert res == ["another 1", "another 2", ("hello", "new value")]
|
||||
assert res == ["another 1", "another 2", "hello", "new value"]
|
||||
|
||||
def test_by_default_swap_is_set_to_outer_html(self):
|
||||
command = Command('test', 'Command description', None, callback)
|
||||
@@ -120,6 +126,15 @@ class TestCommandBind:
|
||||
assert "hx_swap_oob" not in res[0].attrs
|
||||
assert res[1].attrs["hx-swap-oob"] == "true"
|
||||
assert res[3].attrs["hx-swap-oob"] == "true"
|
||||
|
||||
def test_i_can_send_parameters(self):
|
||||
command = Command('test', 'Command description', None, None, kwargs={"param": "value"}) # callback is not important
|
||||
elt = Button()
|
||||
updated = command.bind_ft(elt)
|
||||
|
||||
hx_vals = updated.attrs["hx-vals"]
|
||||
assert 'param' in hx_vals
|
||||
assert hx_vals['param'] == 'value'
|
||||
|
||||
|
||||
class TestCommandExecute:
|
||||
@@ -137,7 +152,7 @@ class TestCommandExecute:
|
||||
def callback_with_param(param):
|
||||
return f"Hello {param}"
|
||||
|
||||
command = Command('test', 'Command description', None, callback_with_param, "world")
|
||||
command = Command('test', 'Command description', None, callback_with_param, args=["world"])
|
||||
assert command.execute() == "Hello world"
|
||||
|
||||
def test_i_can_execute_a_command_with_open_parameter(self):
|
||||
@@ -188,9 +203,9 @@ class TestCommandExecute:
|
||||
class TestLambaCommand:
|
||||
|
||||
def test_i_can_create_a_command_from_lambda(self):
|
||||
command = LambdaCommand(None, lambda resp: "Hello World")
|
||||
command = LambdaCommand(None, lambda: "Hello World")
|
||||
assert command.execute() == "Hello World"
|
||||
|
||||
def test_by_default_target_is_none(self):
|
||||
command = LambdaCommand(None, lambda resp: "Hello World")
|
||||
command = LambdaCommand(None, lambda: "Hello World")
|
||||
assert command.get_htmx_params()["hx-swap"] == "none"
|
||||
|
||||
Reference in New Issue
Block a user