Test for UndoManager.undo() and redo()

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1866 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2010-11-13 05:09:21 +00:00
parent 4a514ee231
commit deb5e4a2fa
1 changed files with 55 additions and 0 deletions

View File

@ -242,6 +242,61 @@
tearDown(); 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();
});
}); });
</script> </script>
</head> </head>