more command manager tests
This commit is contained in:
parent
e910138acd
commit
fc220d0363
2 changed files with 32 additions and 3 deletions
|
|
@ -32,7 +32,7 @@ var CommandManager = function(platform, commands) {
|
||||||
command = this.commands[name];
|
command = this.commands[name];
|
||||||
delete 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
|
// not a performance critical operation this should be OK
|
||||||
var ckb = this.commmandKeyBinding;
|
var ckb = this.commmandKeyBinding;
|
||||||
for (var hashId in ckb) {
|
for (var hashId in ckb) {
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,16 @@ module.exports = {
|
||||||
assert.equal(command, this.command);
|
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() {
|
"test: remove command by name": function() {
|
||||||
this.cm.removeCommand("gotoline");
|
this.cm.removeCommand("gotoline");
|
||||||
|
|
||||||
|
|
@ -92,6 +102,25 @@ module.exports = {
|
||||||
|
|
||||||
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "L");
|
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "L");
|
||||||
assert.equal(command, null);
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue