more command manager tests

This commit is contained in:
Fabian Jakobs 2011-11-11 12:26:46 +01:00
commit fc220d0363
2 changed files with 32 additions and 3 deletions

View file

@ -19,7 +19,7 @@ var CommandManager = function(platform, commands) {
this.addCommand = function(command) {
if (this.commands[command.name])
this.removeCommand(command);
this.commands[command.name] = command;
if (command.bindKey) {
@ -32,7 +32,7 @@ var CommandManager = function(platform, commands) {
command = this.commands[name];
delete this.commands[name];
// exaustive search is a little bit brute force but since removeCommand is
// exaustive search is brute force but since removeCommand is
// not a performance critical operation this should be OK
var ckb = this.commmandKeyBinding;
for (var hashId in ckb) {

View file

@ -83,7 +83,17 @@ module.exports = {
var command = cm.findKeyCommand(keys.KEY_MODS.ctrl, "L");
assert.equal(command, this.command);
},
"test: remove command by object": function() {
this.cm.removeCommand(this.command);
this.cm.exec("gotoline");
assert.ok(!this.command.called);
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "L");
assert.equal(command, null);
},
"test: remove command by name": function() {
this.cm.removeCommand("gotoline");
@ -92,6 +102,25 @@ module.exports = {
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "L");
assert.equal(command, null);
},
"test: adding a new command with the same name as an existing one should remove the old one first": function() {
var command = {
name: "gotoline",
bindKey: {
mac: "Command-L",
win: "Ctrl-L"
},
called: false,
exec: function(editor) { this.called = true; }
}
this.cm.addCommand(command);
this.cm.exec("gotoline");
assert.ok(command.called);
assert.ok(!this.command.called);
assert.equal(this.cm.findKeyCommand(keys.KEY_MODS.command, "L"), command);
}
};