-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
124 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* bender-tags: editor,unit */ | ||
|
||
'use strict'; | ||
|
||
bender.editor = { | ||
creator: 'inline', | ||
config: { | ||
allowedContent: true | ||
} | ||
}; | ||
|
||
bender.test( { | ||
'test getSelectedHtml': function() { | ||
var editor = this.editor; | ||
bender.tools.selection.setWithHtml( editor, '<p>fo{ob}ar</p>' ); | ||
|
||
var frag = editor.getSelectedHtml(); | ||
|
||
assert.isInstanceOf( CKEDITOR.dom.documentFragment, frag ); | ||
assert.areSame( 'ob', frag.getHtml() ); | ||
}, | ||
|
||
'test getSelectedHtml with toString option': function() { | ||
var editor = this.editor; | ||
bender.tools.selection.setWithHtml( editor, '<p>fo{ob}ar</p>' ); | ||
|
||
assert.areSame( 'ob', editor.getSelectedHtml( true ) ); | ||
}, | ||
|
||
'test extractSelectedHtml': function() { | ||
var editor = this.editor; | ||
bender.tools.selection.setWithHtml( editor, '<p>fo{ob}ar</p>' ); | ||
|
||
// We need to precisely check if selection was set, because | ||
// after the selected part of the DOM is extracted browser would | ||
// make a similar selection in similar place. This way we're distinguishing who made it. | ||
sinon.spy( CKEDITOR.dom.selection.prototype, 'selectRanges' ); | ||
|
||
var frag = editor.extractSelectedHtml(), | ||
selectionWasSetOnce = CKEDITOR.dom.selection.prototype.selectRanges.calledOnce; | ||
|
||
CKEDITOR.dom.selection.prototype.selectRanges.restore(); | ||
|
||
assert.areSame( 'ob', frag.getHtml(), 'extracted HTML' ); | ||
assert.isTrue( selectionWasSetOnce, 'new selection has been set' ); | ||
assert.isInnerHtmlMatching( '<p>fo^ar@</p>', bender.tools.selection.getWithHtml( editor ), | ||
{ compareSelection: true, normalizeSelection: true }, 'contents of the editor' ); | ||
}, | ||
|
||
'test extractSelectedHtml with toString option': function() { | ||
var editor = this.editor; | ||
bender.tools.selection.setWithHtml( editor, '<p>fo{ob}ar</p>' ); | ||
|
||
assert.areSame( 'ob', editor.extractSelectedHtml( true ) ); | ||
assert.isInnerHtmlMatching( '<p>fo^ar@</p>', bender.tools.selection.getWithHtml( editor ), | ||
{ compareSelection: true, normalizeSelection: true }, 'contents of the editor' ); | ||
} | ||
} ); |