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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
|
/* bender-tags: editor,unit */
/* bender-ckeditor-plugins: dialog */
CKEDITOR.on( 'instanceLoaded', function() {
CKEDITOR.dialog.add( 'testDialog1', function() {
return {
title: 'Test Dialog 1',
contents: [
{
id: 'info',
label: 'Test',
elements: [
{
type: 'text',
id: 'foo',
label: 'bar'
}
]
}
]
};
} );
CKEDITOR.dialog.add( 'testDialog2', '%TEST_DIR%_assets/testdialog.js' );
} );
bender.editor = {};
bender.test( {
'test open dialog from local': function() {
var ed = this.editor, tc = this;
ed.openDialog( 'testDialog1', function( dialog ) {
tc.resume( function() {
assert.isNotNull( dialog );
wait( function() {
dialog.getButton( 'cancel' ).click();
}, 100 );
} );
} );
tc.wait();
},
'test open dialog from url': function() {
var ed = this.editor, tc = this;
ed.openDialog( 'testDialog2', function( dialog ) {
tc.resume( function() {
assert.isNotNull( dialog );
wait( function() {
dialog.getButton( 'cancel' ).click();
}, 100 );
} );
} );
tc.wait();
},
// Code of this test is poor (checking isVisible and operations on DOM), but that's caused
// by very closed and poor dialog API.
'test dialog\'s field are disabled when not allowed': function() {
var ed = this.editor;
CKEDITOR.dialog.add( 'testDialog3', function() {
return {
title: 'Test Dialog 3',
contents: [
{
id: 'tab1',
label: 'Test 1',
elements: [
{
type: 'text',
id: 'foo',
label: 'foo',
requiredContent: 'p'
},
{
type: 'text',
id: 'bar',
label: 'bar',
requiredContent: 'x'
}
]
},
{
id: 'tab2',
label: 'Test 2',
elements: [
// vbox shouldn't be count as visible uielement,
// so entire tab2 should be hidden.
{
type: 'vbox',
children: [
{
type: 'text',
id: 'bom',
label: 'bom',
requiredContent: 'y'
}
]
}
]
},
{
id: 'tab3',
label: 'Test 3',
elements: [
{
type: 'text',
id: 'bim',
label: 'bim'
}
]
}
]
};
} );
ed.openDialog( 'testDialog3', function( dialog ) {
setTimeout( function() {
resume( function() {
// Tab 2 has no visible elements, so it should be hidden.
assert.areSame( 2, dialog.getPageCount() );
assert.isTrue( dialog.parts.tabs.getChild( 0 ).isVisible() );
assert.isFalse( dialog.parts.tabs.getChild( 1 ).isVisible() );
assert.isTrue( dialog.parts.tabs.getChild( 2 ).isVisible() );
assert.isTrue( dialog.getContentElement( 'tab1', 'foo' ).getInputElement().isVisible() );
assert.isFalse( dialog.getContentElement( 'tab1', 'bar' ).getInputElement().isVisible() );
assert.isFalse( dialog.getContentElement( 'tab2', 'bom' ).getInputElement().isVisible() );
// Element tab2:bom should be still invisible after switching to second tab.
dialog.selectPage( 'tab2' );
assert.isFalse( dialog.getContentElement( 'tab2', 'bom' ).getInputElement().isVisible() );
dialog.selectPage( 'tab3' );
assert.isTrue( dialog.getContentElement( 'tab3', 'bim' ).getInputElement().isVisible() );
wait( function() {
dialog.getButton( 'cancel' ).click();
}, 100 );
} );
}, 200 );
} );
wait();
},
// Code of this test is poor (checking isVisible and operations on DOM), but that's caused
// by very closed and poor dialog API.
// #12546
'test dialog\'s HTML field always count as allowed field unless requiredContent is specified': function() {
var ed = this.editor;
CKEDITOR.dialog.add( 'testDialog4', function() {
return {
title: 'Test Dialog 4',
contents: [
{
id: 'tab1',
label: 'Test 1',
elements: [
{
type: 'html',
id: 'field1',
html: 'foo'
}
]
},
{
id: 'tab2a',
label: 'Test 2a',
elements: [
{
type: 'html',
id: 'field2a',
html: 'foo',
requiredContent: 'x'
}
]
},
{
id: 'tab2b',
label: 'Test 2b',
elements: [
{
type: 'html',
id: 'field2b',
html: 'foo',
requiredContent: 'p'
}
]
},
{
id: 'tab3',
label: 'Test 3',
requiredContent: 'y',
elements: [
{
type: 'html',
id: 'field3',
html: 'foo'
}
]
}
]
};
} );
ed.openDialog( 'testDialog4', function( dialog ) {
setTimeout( function() {
resume( function() {
assert.areSame( 2, dialog.getPageCount() );
assert.isTrue( dialog.parts.tabs.getChild( 0 ).isVisible(), 'tab1' );
// Tab 2a is hidden.
assert.isFalse( dialog.parts.tabs.getChild( 1 ).isVisible(), 'tab2a' );
assert.isTrue( dialog.parts.tabs.getChild( 2 ).isVisible(), 'tab2b' );
// Tab 3 wasn't created at all.
assert.isNull( dialog.parts.tabs.getChild( 3 ), 'tab3' );
assert.isTrue( dialog.getContentElement( 'tab1', 'field1' ).getInputElement().isVisible(), 'field1' );
dialog.selectPage( 'tab2b' );
assert.isTrue( dialog.getContentElement( 'tab2b', 'field2b' ).getInputElement().isVisible(), 'field2b' );
wait( function() {
dialog.getButton( 'cancel' ).click();
}, 100 );
} );
}, 200 );
} );
wait();
},
'test dialog is triggered on doubleclick': function() {
var editor = this.editor,
openedDialog = null,
revert = bender.tools.replaceMethod( editor, 'openDialog', function( name ) {
openedDialog = name;
} );
editor.fire( 'doubleclick', { element: editor.editable() } );
assert.isNull( openedDialog, 'dialog was not opened' );
editor.once( 'doubleclick', function( evt ) {
evt.data.dialog = 'testdoubleclick';
} );
editor.fire( 'doubleclick', { element: editor.editable() } );
assert.areSame( 'testdoubleclick', openedDialog, 'dialog was opened on doubleclick' );
revert();
},
'test dialog setState': function() {
var stateEventFired = 0,
editor = this.editor;
CKEDITOR.dialog.add( 'testDialog5', function() {
return {
title: 'Test Dialog 5',
contents: [
{
id: 'tab1',
label: 'Test 1',
elements: [
{
type: 'text',
id: 'foo',
label: 'foo',
requiredContent: 'p'
}
]
}
]
};
} );
editor.addCommand( 'testDialog5', new CKEDITOR.dialogCommand( 'testDialog5' ) );
editor.once( 'dialogShow', function( evt ) {
var dialog = evt.data;
resume( function() {
try {
assert.isTrue( dialog.getButton( 'ok' ).isEnabled(), 'OK button is enabled.' );
assert.isUndefined( dialog.parts.spinner, 'By default dialog has no spinner' );
assert.areSame( CKEDITOR.DIALOG_STATE_IDLE, dialog.state, 'Default dialog state' );
var stateListener = dialog.on( 'state', function( evt ) {
try {
assert.areSame( CKEDITOR.DIALOG_STATE_BUSY, dialog.state, 'New dialog state' );
assert.isFalse( dialog.getButton( 'ok' ).isEnabled(), 'OK button is disabled' );
assert.isObject( dialog.parts.spinner, 'Dialog has a spinner element' );
++stateEventFired;
} catch ( e ) {
evt.removeListener();
throw e;
}
} );
// Change dialog's state and assert related properties.
dialog.setState( CKEDITOR.DIALOG_STATE_BUSY );
// Remove the listener because the dialog will be reopened and those assertions would be invalid.
stateListener.removeListener();
assert.areSame( 1, stateEventFired, 'State event has been fired' );
dialog.hide();
// Call the dialog again to tell what happens to the state and the UI once reopened.
editor.execCommand( 'testDialog5' );
editor.once( 'dialogShow', function( evt ) {
var dialog = evt.data;
resume( function() {
try {
assert.areSame( CKEDITOR.DIALOG_STATE_IDLE, dialog.state, 'Default dialog state after re–open' );
assert.isTrue( dialog.getButton( 'ok' ).isEnabled(), 'OK button is enabled after re–open' );
assert.isObject( dialog.parts.spinner, 'Dialog has been given a spinner before' );
} catch ( e ) {
throw e;
} finally {
dialog.hide();
}
} );
} );
wait();
} catch ( e ) {
throw e;
} finally {
dialog.hide();
}
} );
} );
editor.execCommand( 'testDialog5' );
wait();
}
} );
//]]>
|