From deb5e4a2fa93b533ba6cf55d2639c953c457f41f Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Sat, 13 Nov 2010 05:09:21 +0000 Subject: [PATCH] Test for UndoManager.undo() and redo() git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1866 eee81c28-f429-11dd-99c0-75d572ba1ddd --- test/history_test.html | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/history_test.html b/test/history_test.html index 1b73a1a5..9e35611f 100644 --- a/test/history_test.html +++ b/test/history_test.html @@ -242,6 +242,61 @@ tearDown(); }); + test('Test UndoManager.undo() and redo() functions', function() { + expect(10); + + setUp(); + + var lastCalled = null; + var cmd1 = new MockCommand(); + var cmd2 = new MockCommand(); + var cmd3 = new MockCommand(); + cmd1.apply = function() { lastCalled = 'cmd1.apply'; }; + cmd2.apply = function() { lastCalled = 'cmd2.apply'; }; + cmd3.apply = function() { lastCalled = 'cmd3.apply'; }; + cmd1.unapply = function() { lastCalled = 'cmd1.unapply'; }; + cmd2.unapply = function() { lastCalled = 'cmd2.unapply'; }; + cmd3.unapply = function() { lastCalled = 'cmd3.unapply'; }; + + undoMgr.addCommandToHistory(cmd1); + undoMgr.addCommandToHistory(cmd2); + undoMgr.addCommandToHistory(cmd3); + + ok(!lastCalled); + + undoMgr.undo(); + equals(lastCalled, 'cmd3.unapply'); + + undoMgr.redo(); + equals(lastCalled, 'cmd3.apply'); + + undoMgr.undo(); + undoMgr.undo(); + equals(lastCalled, 'cmd2.unapply'); + + undoMgr.undo(); + equals(lastCalled, 'cmd1.unapply'); + lastCalled = null; + + undoMgr.undo(); + ok(!lastCalled); + + undoMgr.redo(); + equals(lastCalled, 'cmd1.apply'); + + undoMgr.redo(); + equals(lastCalled, 'cmd2.apply'); + + undoMgr.redo(); + equals(lastCalled, 'cmd3.apply'); + lastCalled = null; + + undoMgr.redo(); + ok(!lastCalled); + + tearDown(); + }); + });