Working on undo redo
This commit is contained in:
@@ -9,7 +9,7 @@ from my_mocks import tabs_manager
|
||||
|
||||
class UndoableCommand(CommandHistory):
|
||||
def __init__(self, old_value=0, new_value=0):
|
||||
super().__init__("command", f"The new value is {new_value}")
|
||||
super().__init__("Set new value", lambda value: f"Setting new value to {value}", None)
|
||||
self.old_value = old_value
|
||||
self.new_value = new_value
|
||||
|
||||
@@ -31,8 +31,8 @@ def undo_redo(session, tabs_manager):
|
||||
def test_i_can_render(undo_redo):
|
||||
actual = undo_redo.__ft__()
|
||||
expected = Div(
|
||||
Div(div_icon("undo", cls=Contains("mmt-btn-disabled")), data_tooltip="Nothing to undo"),
|
||||
Div(div_icon("redo", cls=Contains("mmt-btn-disabled")), data_tooltip="Nothing to redo"),
|
||||
Div(div_icon("undo", cls=Contains("mmt-btn-disabled")), data_tooltip="Nothing to undo."),
|
||||
Div(div_icon("redo", cls=Contains("mmt-btn-disabled")), data_tooltip="Nothing to redo."),
|
||||
id=undo_redo.get_id(),
|
||||
)
|
||||
|
||||
@@ -40,13 +40,13 @@ def test_i_can_render(undo_redo):
|
||||
|
||||
|
||||
def test_i_can_render_when_undoing_and_redoing(undo_redo):
|
||||
undo_redo.push(UndoableCommand())
|
||||
undo_redo.push(UndoableCommand())
|
||||
undo_redo.push(UndoableCommand(0, 1))
|
||||
undo_redo.push(UndoableCommand(1, 2))
|
||||
|
||||
actual = undo_redo.__ft__()
|
||||
expected = Div(
|
||||
Div(div_icon("undo", cls=DoesNotContain("mmt-btn-disabled")), data_tooltip="Undo "),
|
||||
Div(div_icon("redo", cls=Contains("mmt-btn-disabled")), data_tooltip=""),
|
||||
Div(div_icon("undo", cls=DoesNotContain("mmt-btn-disabled")), data_tooltip="Undo 'Set new value'."),
|
||||
Div(div_icon("redo", cls=Contains("mmt-btn-disabled")), data_tooltip="Nothing to redo."),
|
||||
id=undo_redo.get_id(),
|
||||
)
|
||||
assert matches(actual, expected)
|
||||
@@ -54,8 +54,8 @@ def test_i_can_render_when_undoing_and_redoing(undo_redo):
|
||||
undo_redo.undo() # The command is now undone. We can redo it and undo the first command.
|
||||
actual = undo_redo.__ft__()
|
||||
expected = Div(
|
||||
div_icon("undo", cls=DoesNotContain("mmt-btn-disabled")),
|
||||
div_icon("redo", cls=DoesNotContain("mmt-btn-disabled")),
|
||||
Div(div_icon("undo", cls=DoesNotContain("mmt-btn-disabled")), data_tooltip="Undo 'Set new value'."),
|
||||
Div(div_icon("redo", cls=DoesNotContain("mmt-btn-disabled")), data_tooltip="Redo 'Set new value'."),
|
||||
id=undo_redo.get_id(),
|
||||
)
|
||||
assert matches(actual, expected)
|
||||
@@ -63,8 +63,8 @@ def test_i_can_render_when_undoing_and_redoing(undo_redo):
|
||||
undo_redo.undo() # Undo again, I cannot undo anymore.
|
||||
actual = undo_redo.__ft__()
|
||||
expected = Div(
|
||||
div_icon("undo", cls=Contains("mmt-btn-disabled")),
|
||||
div_icon("redo", cls=DoesNotContain("mmt-btn-disabled")),
|
||||
Div(div_icon("undo", cls=Contains("mmt-btn-disabled"))),
|
||||
Div(div_icon("redo", cls=DoesNotContain("mmt-btn-disabled"))),
|
||||
id=undo_redo.get_id(),
|
||||
)
|
||||
assert matches(actual, expected)
|
||||
@@ -72,8 +72,8 @@ def test_i_can_render_when_undoing_and_redoing(undo_redo):
|
||||
undo_redo.redo() # Redo once.
|
||||
actual = undo_redo.__ft__()
|
||||
expected = Div(
|
||||
div_icon("undo", cls=DoesNotContain("mmt-btn-disabled")),
|
||||
div_icon("redo", cls=DoesNotContain("mmt-btn-disabled")),
|
||||
Div(div_icon("undo", cls=DoesNotContain("mmt-btn-disabled"))),
|
||||
Div(div_icon("redo", cls=DoesNotContain("mmt-btn-disabled"))),
|
||||
id=undo_redo.get_id(),
|
||||
)
|
||||
assert matches(actual, expected)
|
||||
@@ -81,8 +81,8 @@ def test_i_can_render_when_undoing_and_redoing(undo_redo):
|
||||
undo_redo.redo() # Redo a second time.
|
||||
actual = undo_redo.__ft__()
|
||||
expected = Div(
|
||||
div_icon("undo", cls=DoesNotContain("mmt-btn-disabled")),
|
||||
div_icon("redo", cls=Contains("mmt-btn-disabled")),
|
||||
Div(div_icon("undo", cls=DoesNotContain("mmt-btn-disabled"))),
|
||||
Div(div_icon("redo", cls=Contains("mmt-btn-disabled"))),
|
||||
id=undo_redo.get_id(),
|
||||
)
|
||||
assert matches(actual, expected)
|
||||
@@ -99,3 +99,14 @@ def test_i_can_undo_and_redo(undo_redo):
|
||||
self, res = undo_redo.redo()
|
||||
expected = Div(2, hx_swap_oob="true")
|
||||
assert matches(res, expected)
|
||||
|
||||
def test_history_is_rewritten_when_pushing_a_command(undo_redo):
|
||||
undo_redo.push(UndoableCommand(0, 1))
|
||||
undo_redo.push(UndoableCommand(1, 2))
|
||||
undo_redo.push(UndoableCommand(2, 3))
|
||||
|
||||
undo_redo.undo()
|
||||
undo_redo.undo()
|
||||
undo_redo.push(UndoableCommand(1, 5))
|
||||
|
||||
assert len(undo_redo.history) == 2
|
||||
Reference in New Issue
Block a user