Add test for BatchCommand

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1870 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2010-11-14 03:12:00 +00:00
parent 304d83f0ed
commit 1918ddae7a
1 changed files with 46 additions and 17 deletions

View File

@ -35,24 +35,14 @@
module('svgedit.history');
var MockCommand = function(opt_text) {
this.text_ = opt_text;
};
MockCommand.prototype.apply = function() {
};
MockCommand.prototype.unapply = function() {
};
MockCommand.prototype.getText = function() {
return this.text_;
};
MockCommand.prototype.elements = function() {
return [];
};
var MockCommand = function(opt_text) { this.text_ = opt_text; };
MockCommand.prototype.apply = function() {};
MockCommand.prototype.unapply = function() {};
MockCommand.prototype.getText = function() { return this.text_; };
MockCommand.prototype.elements = function() { return []; };
var MockHistoryEventHandler = function() {
};
MockHistoryEventHandler.prototype.handleHistoryEvent = function(eventType, command) {
};
var MockHistoryEventHandler = function() {};
MockHistoryEventHandler.prototype.handleHistoryEvent = function(eventType, command) {};
function setUp() {
undoMgr = new svgedit.history.UndoManager();
@ -522,6 +512,45 @@
tearDown();
});
test('Test BatchCommand', function() {
expect(13);
setUp();
var concatResult = '';
MockCommand.prototype.apply = function() { concatResult += this.text_; };
var batch = new svgedit.history.BatchCommand();
ok(batch.unapply);
ok(batch.apply);
ok(batch.addSubCommand);
ok(batch.isEmpty);
equals(typeof batch.unapply, typeof function(){});
equals(typeof batch.apply, typeof function(){});
equals(typeof batch.addSubCommand, typeof function(){});
equals(typeof batch.isEmpty, typeof function(){});
ok(batch.isEmpty());
batch.addSubCommand(new MockCommand('a'));
ok(!batch.isEmpty());
batch.addSubCommand(new MockCommand('b'));
batch.addSubCommand(new MockCommand('c'));
ok(!concatResult);
batch.apply();
equals(concatResult, 'abc');
MockCommand.prototype.apply = function() {};
MockCommand.prototype.unapply = function() { concatResult += this.text_; };
concatResult = '';
batch.unapply();
equals(concatResult, 'cba');
tearDown();
});
});
</script>
</head>