Another implementation of undo/redo
This commit is contained in:
@@ -1,25 +1,12 @@
|
||||
import pytest
|
||||
from fasthtml.components import Div
|
||||
|
||||
from components.undo_redo.components.UndoRedo import UndoRedo, CommandHistory
|
||||
from components.undo_redo.components.UndoRedo import UndoRedo
|
||||
from core.settings_management import SettingsManager, MemoryDbEngine
|
||||
from helpers import matches, div_icon, Contains, DoesNotContain
|
||||
from my_mocks import tabs_manager
|
||||
|
||||
|
||||
class UndoableCommand(CommandHistory):
|
||||
def __init__(self, old_value=0, new_value=0):
|
||||
super().__init__("Set new value", lambda value: f"Setting new value to {value}", None)
|
||||
self.old_value = old_value
|
||||
self.new_value = new_value
|
||||
|
||||
def undo(self):
|
||||
return Div(self.old_value, hx_swap_oob="true")
|
||||
|
||||
def redo(self):
|
||||
return Div(self.new_value, hx_swap_oob="true")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def undo_redo(session, tabs_manager):
|
||||
return UndoRedo(session,
|
||||
@@ -100,6 +87,7 @@ def test_i_can_undo_and_redo(undo_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))
|
||||
@@ -109,4 +97,4 @@ def test_history_is_rewritten_when_pushing_a_command(undo_redo):
|
||||
undo_redo.undo()
|
||||
undo_redo.push(UndoableCommand(1, 5))
|
||||
|
||||
assert len(undo_redo.history) == 2
|
||||
assert len(undo_redo.history) == 2
|
||||
|
||||
Reference in New Issue
Block a user