1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
/* bender-tags: editor */
CKEDITOR.replaceClass = 'ckeditor';
bender.editor = true;
var keyCombo1 = CKEDITOR.CTRL + 10,
keyCombo2 = CKEDITOR.ALT + 20,
keyCombo3 = CKEDITOR.SHIFT + CKEDITOR.ALT + 30,
command1 = 'command#1',
command2 = 'command#2',
command3 = 'command#3WithCapitalLetters';
bender.test(
{
setUp: function() {
var keystrokes = this.editor.keystrokeHandler.keystrokes,
commands = this.editor.commands;
delete keystrokes[ keyCombo1 ];
delete keystrokes[ keyCombo2 ];
delete commands[ command1 ];
delete commands[ command2 ];
this.editor.addCommand( 'command_with_keystrokes', {
exec: function() {}
} );
this.editor.addCommand( 'command_with_fake_keystrokes', {
exec: function() {},
fakeKeystroke: 77
} );
this.editor.setKeystroke( 75, 'command_with_keystrokes' );
this.editor.setKeystroke( 76, 'command_with_keystrokes' );
this.editor.addCommand( 'command_without_keystrokes', {
exec: function() {}
} );
},
'test getCommandKeystroke': function() {
assert.isNull( this.editor.getCommandKeystroke( 'command_without_keystrokes' ), 'Command without keystroke' );
assert.areEqual( 75, this.editor.getCommandKeystroke( 'command_with_keystrokes' ), 'Command with keystroke.' );
},
// (#2493)
'test getCommandKeystroke multiple keystrokes': function() {
arrayAssert.isEmpty( this.editor.getCommandKeystroke( 'command_without_keystrokes', true ), 'Command without keystrokes.' );
arrayAssert.itemsAreEqual( [ 75, 76 ], this.editor.getCommandKeystroke( 'command_with_keystrokes', true ), 'Command with keystrokes.' );
},
'test getCommandKeystroke in commands with fake keystrokes': function() {
assert.areSame( 77, this.editor.getCommandKeystroke( 'command_with_fake_keystrokes' ), 'Single keystroke result.' );
// (#2493)
var ret = this.editor.getCommandKeystroke( 'command_with_fake_keystrokes', true );
assert.isInstanceOf( Array, ret, 'Return type.' );
arrayAssert.itemsAreEqual( [ 77 ], ret, 'Multiple keystrokes result.' );
},
'test keystroke assignment': function() {
var editor = this.editor,
keystrokes = editor.keystrokeHandler.keystrokes,
keystroke;
editor.addCommand( command1, {} );
editor.setKeystroke( keyCombo1, command1 );
assert.areEqual( command1, keystrokes[ keyCombo1 ] );
// Get by command instance.
keystroke = editor.getCommandKeystroke( editor.getCommand( command1 ) );
assert.areEqual( keyCombo1, keystroke, 'Keystrokes should be equal (command).' );
// Get by command name.
keystroke = editor.getCommandKeystroke( command1 );
assert.areEqual( keyCombo1, keystroke, 'Keystrokes should be equal (command name).' );
},
'test keystroke array assignment': function() {
var editor = this.editor,
keystrokes = editor.keystrokeHandler.keystrokes,
keystroke1,
keystroke2;
editor.addCommand( command1, {} );
editor.addCommand( command2, {} );
editor.setKeystroke(
[
[ keyCombo1, command1 ],
[ keyCombo2, command2 ]
] );
assert.areEqual( command1, keystrokes[ keyCombo1 ] );
assert.areEqual( command2, keystrokes[ keyCombo2 ] );
// Get by command instance.
keystroke1 = editor.getCommandKeystroke( editor.getCommand( command1 ) );
keystroke2 = editor.getCommandKeystroke( editor.getCommand( command2 ) );
assert.areEqual( keyCombo1, keystroke1, 'Keystrokes should be equal (command).' );
assert.areEqual( keyCombo2, keystroke2, 'Keystrokes should be equal (command).' );
// Get by command name.
keystroke1 = editor.getCommandKeystroke( command1 );
keystroke2 = editor.getCommandKeystroke( command2 );
assert.areEqual( keyCombo1, keystroke1, 'Keystrokes should be equal (command name).' );
assert.areEqual( keyCombo2, keystroke2, 'Keystrokes should be equal (command name).' );
},
'test editor#key event': function() {
var fired = 0,
evtData = null;
this.editor.on( 'key', function( evt ) {
fired += 1;
evtData = evt.data;
} );
this.editor.editable().fire( 'keydown', new CKEDITOR.dom.event( {
keyCode: 66,
ctrlKey: true,
shiftKey: true
} ) );
assert.areSame( 1, fired, 'editor#key has been fired once' );
assert.areSame( CKEDITOR.CTRL + CKEDITOR.SHIFT + 66, evtData.keyCode, 'keyCode' );
assert.isInstanceOf( CKEDITOR.dom.event, evtData.domEvent, 'domEvent' );
assert.areSame( 66, evtData.domEvent.getKey(), 'domEvent.getKey()' );
},
'test editor#getCommandKeystroke with empty name': function() {
var editor = this.editor;
assert.isNull( editor.getCommandKeystroke( '' ), 'Returned keystroke.' );
},
// #523
'test keystroke with capital letters': function() {
var editor = this.editor,
keystrokes = editor.keystrokeHandler.keystrokes,
keystroke;
editor.addCommand( command3, {} );
editor.setKeystroke( keyCombo3, command3 );
assert.areEqual( command3, keystrokes[ keyCombo3 ] );
// Get by command instance.
keystroke = editor.getCommandKeystroke( editor.getCommand( command3 ) );
assert.areEqual( keyCombo3, keystroke, 'Keystrokes should be equal (command).' );
// Get by command name.
keystroke = editor.getCommandKeystroke( command3 );
assert.areEqual( keyCombo3, keystroke, 'Keystrokes should be equal (command name).' );
}
} );
|