8
0

upcastwriter.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import DocumentFragment from '../../src/view/documentfragment';
  6. import Element from '../../src/view/element';
  7. import Text from '../../src/view/text';
  8. import UpcastWriter from '../../src/view/upcastwriter';
  9. import HtmlDataProcessor from '../../src/dataprocessor/htmldataprocessor';
  10. import ViewPosition from '../../src/view/position';
  11. import ViewRange from '../../src/view/range';
  12. import ViewSelection from '../../src/view/selection';
  13. import Document from '../../src/view/document';
  14. import { StylesProcessor } from '../../src/view/stylesmap';
  15. describe( 'UpcastWriter', () => {
  16. let writer, view, dataprocessor, document;
  17. beforeEach( () => {
  18. document = new Document( new StylesProcessor() );
  19. writer = new UpcastWriter( document );
  20. dataprocessor = new HtmlDataProcessor( document );
  21. const html = '' +
  22. '<h1 style="color:blue;position:fixed;">Heading <strong>1</strong></h1>' +
  23. '<p class="foo1 bar2" style="text-align:left;" data-attr="abc">Foo <i>Bar</i> <strong>Bold</strong></p>' +
  24. '<p><u>Some underlined</u> text</p>' +
  25. '<ul>' +
  26. '<li class="single">Item 1</li>' +
  27. '<li><span>Item <s>1</s></span></li>' +
  28. '<li><h2>Item 1</h2></li>' +
  29. '</ul>';
  30. view = dataprocessor.toView( html );
  31. } );
  32. describe( 'createDocumentFragment', () => {
  33. it( 'should create empty document fragment', () => {
  34. const df = writer.createDocumentFragment();
  35. expect( df ).to.instanceOf( DocumentFragment );
  36. expect( df.childCount ).to.equal( 0 );
  37. } );
  38. it( 'should create document fragment with children', () => {
  39. const df = writer.createDocumentFragment( [ view.getChild( 0 ), view.getChild( 1 ) ] );
  40. expect( df ).to.instanceOf( DocumentFragment );
  41. expect( df.childCount ).to.equal( 2 );
  42. } );
  43. } );
  44. describe( 'createElement', () => {
  45. it( 'should create empty element', () => {
  46. const el = writer.createElement( 'p' );
  47. expect( el ).to.instanceOf( Element );
  48. expect( el.name ).to.equal( 'p' );
  49. expect( Array.from( el.getAttributes() ).length ).to.equal( 0 );
  50. expect( el.childCount ).to.equal( 0 );
  51. } );
  52. it( 'should create element with attributes', () => {
  53. const el = writer.createElement( 'a', { 'class': 'editor', 'contentEditable': 'true' } );
  54. expect( el ).to.instanceOf( Element );
  55. expect( el.name ).to.equal( 'a' );
  56. expect( Array.from( el.getAttributes() ).length ).to.equal( 2 );
  57. expect( el.childCount ).to.equal( 0 );
  58. } );
  59. it( 'should create element with children', () => {
  60. const el = writer.createElement( 'div', null, [ view.getChild( 0 ) ] );
  61. expect( el ).to.instanceOf( Element );
  62. expect( el.name ).to.equal( 'div' );
  63. expect( Array.from( el.getAttributes() ).length ).to.equal( 0 );
  64. expect( el.childCount ).to.equal( 1 );
  65. } );
  66. it( 'should create element with attributes and children', () => {
  67. const el = writer.createElement( 'blockquote',
  68. { 'class': 'editor', 'contentEditable': 'true' },
  69. view.getChild( 2 ) );
  70. expect( el ).to.instanceOf( Element );
  71. expect( el.name ).to.equal( 'blockquote' );
  72. expect( Array.from( el.getAttributes() ).length ).to.equal( 2 );
  73. expect( el.childCount ).to.equal( 1 );
  74. } );
  75. } );
  76. describe( 'createText', () => {
  77. it( 'should create text', () => {
  78. const text = writer.createText( 'FooBar' );
  79. expect( text ).to.instanceOf( Text );
  80. expect( text.data ).to.equal( 'FooBar' );
  81. } );
  82. } );
  83. describe( 'clone', () => {
  84. it( 'should clone simple element', () => {
  85. const el = view.getChild( 0 );
  86. const clone = writer.clone( el );
  87. expect( clone ).to.not.equal( el );
  88. expect( clone.isSimilar( el ) ).to.true;
  89. expect( clone.childCount ).to.equal( 0 );
  90. } );
  91. it( 'should clone element with all attributes', () => {
  92. const el = view.getChild( 1 );
  93. const clone = writer.clone( el );
  94. expect( clone ).to.not.equal( el );
  95. expect( clone.isSimilar( el ) ).to.true;
  96. expect( clone.childCount ).to.equal( 0 );
  97. } );
  98. it( 'should deep clone element', () => {
  99. const el = view.getChild( 0 );
  100. const clone = writer.clone( el, true );
  101. expect( clone ).to.not.equal( el );
  102. expect( clone.isSimilar( el ) ).to.true;
  103. expect( clone.childCount ).to.equal( el.childCount );
  104. } );
  105. } );
  106. describe( 'appendChild', () => {
  107. it( 'should append inline child to paragraph', () => {
  108. const el = view.getChild( 2 );
  109. const newChild = new Element( 'span' );
  110. const appended = writer.appendChild( newChild, el );
  111. expect( appended ).to.equal( 1 );
  112. expect( newChild.parent ).to.equal( el );
  113. expect( el.childCount ).to.equal( 3 );
  114. } );
  115. it( 'should append block children to paragraph', () => {
  116. const el = view.getChild( 2 );
  117. const newChild1 = new Element( 'p' );
  118. const newChild2 = new Element( 'h2' );
  119. const appended = writer.appendChild( [ newChild1, newChild2 ], el );
  120. expect( appended ).to.equal( 2 );
  121. expect( newChild1.parent ).to.equal( el );
  122. expect( newChild2.parent ).to.equal( el );
  123. expect( el.childCount ).to.equal( 4 );
  124. } );
  125. it( 'should append list item to the list', () => {
  126. const el = view.getChild( 3 );
  127. const newChild = new Element( 'li' );
  128. const appended = writer.appendChild( newChild, el );
  129. expect( appended ).to.equal( 1 );
  130. expect( newChild.parent ).to.equal( el );
  131. expect( el.childCount ).to.equal( 4 );
  132. } );
  133. it( 'should append element to DocumentFragment element', () => {
  134. const newChild = new Element( 'p' );
  135. const appended = writer.appendChild( newChild, view );
  136. expect( appended ).to.equal( 1 );
  137. expect( newChild.parent ).to.equal( view );
  138. expect( view.childCount ).to.equal( 5 );
  139. } );
  140. } );
  141. describe( 'insertChild', () => {
  142. it( 'should insert inline child into the paragraph on the first position', () => {
  143. const el = view.getChild( 2 );
  144. const newChild = new Element( 'span' );
  145. const inserted = writer.insertChild( 0, newChild, el );
  146. expect( inserted ).to.equal( 1 );
  147. expect( newChild.parent ).to.equal( el );
  148. expect( el.getChild( 0 ) ).to.equal( newChild );
  149. expect( el.childCount ).to.equal( 3 );
  150. } );
  151. it( 'should insert block children into the paragraph on the last position', () => {
  152. const el = view.getChild( 2 );
  153. const newChild1 = new Element( 'blockquote' );
  154. const newChild2 = new Element( 'h2' );
  155. const inserted = writer.insertChild( 2, [ newChild1, newChild2 ], el );
  156. expect( inserted ).to.equal( 2 );
  157. expect( newChild1.parent ).to.equal( el );
  158. expect( newChild2.parent ).to.equal( el );
  159. expect( el.getChild( 2 ) ).to.equal( newChild1 );
  160. expect( el.getChild( 3 ) ).to.equal( newChild2 );
  161. expect( el.childCount ).to.equal( 4 );
  162. } );
  163. it( 'should insert list item into the list element', () => {
  164. const el = view.getChild( 3 );
  165. const newChild = new Element( 'li' );
  166. const inserted = writer.insertChild( 1, newChild, el );
  167. expect( inserted ).to.equal( 1 );
  168. expect( newChild.parent ).to.equal( el );
  169. expect( el.getChild( 1 ) ).to.equal( newChild );
  170. expect( el.childCount ).to.equal( 4 );
  171. } );
  172. it( 'should insert element to DocumentFragment element', () => {
  173. const newChild = new Element( 'p' );
  174. const inserted = writer.insertChild( 4, newChild, view );
  175. expect( inserted ).to.equal( 1 );
  176. expect( newChild.parent ).to.equal( view );
  177. expect( view.getChild( 4 ) ).to.equal( newChild );
  178. expect( view.childCount ).to.equal( 5 );
  179. } );
  180. } );
  181. describe( 'removeChildren', () => {
  182. it( 'should remove child from the beginning of the paragraph', () => {
  183. const el = view.getChild( 1 );
  184. const toRemove = el.getChild( 0 );
  185. const removed = writer.removeChildren( 0, 1, el );
  186. expect( removed.length ).to.equal( 1 );
  187. expect( removed[ 0 ] ).to.equal( toRemove );
  188. expect( el.childCount ).to.equal( 3 );
  189. } );
  190. it( 'should remove two last list items from the list element', () => {
  191. const el = view.getChild( 3 );
  192. const toRemove1 = el.getChild( 1 );
  193. const toRemove2 = el.getChild( 2 );
  194. const removed = writer.removeChildren( 1, 2, el );
  195. expect( removed.length ).to.equal( 2 );
  196. expect( removed[ 0 ] ).to.equal( toRemove1 );
  197. expect( removed[ 1 ] ).to.equal( toRemove2 );
  198. expect( el.childCount ).to.equal( 1 );
  199. } );
  200. it( 'should remove child from DocumentFragment element', () => {
  201. const toRemove = view.getChild( 2 );
  202. const removed = writer.removeChildren( 2, 1, view );
  203. expect( removed.length ).to.equal( 1 );
  204. expect( removed[ 0 ] ).to.equal( toRemove );
  205. expect( view.childCount ).to.equal( 3 );
  206. } );
  207. } );
  208. describe( 'remove', () => {
  209. it( 'should remove list item from the list element', () => {
  210. const toRemove = view.getChild( 3 ).getChild( 1 );
  211. const removed = writer.remove( toRemove );
  212. expect( removed.length ).to.equal( 1 );
  213. expect( removed[ 0 ] ).to.equal( toRemove );
  214. expect( view.getChild( 3 ).childCount ).to.equal( 2 );
  215. } );
  216. it( 'should have no effect on detached elements', () => {
  217. const newChild = new Element( 'h2' );
  218. const removed = writer.remove( newChild );
  219. expect( removed.length ).to.equal( 0 );
  220. expect( view.childCount ).to.equal( 4 );
  221. } );
  222. it( 'should remove direct root (DocumentFragment) child', () => {
  223. const toRemove = view.getChild( 3 );
  224. const removed = writer.remove( toRemove );
  225. expect( removed.length ).to.equal( 1 );
  226. expect( removed[ 0 ] ).to.equal( toRemove );
  227. expect( view.childCount ).to.equal( 3 );
  228. } );
  229. } );
  230. describe( 'replace', () => {
  231. it( 'should replace single element', () => {
  232. const el = view.getChild( 0 ).getChild( 1 );
  233. const newChild = new Element( 'span' );
  234. const replacement = writer.replace( el, newChild );
  235. expect( replacement ).to.true;
  236. expect( view.getChild( 0 ).getChild( 1 ) ).to.equal( newChild );
  237. expect( view.getChild( 0 ).childCount ).to.equal( 2 );
  238. } );
  239. it( 'should replace element with children', () => {
  240. const el = view.getChild( 3 );
  241. const newChild = new Element( 'ol' );
  242. const replacement = writer.replace( el, newChild );
  243. expect( replacement ).to.true;
  244. expect( view.getChild( 3 ) ).to.equal( newChild );
  245. expect( view.childCount ).to.equal( 4 );
  246. } );
  247. it( 'should have no effect on detached elements', () => {
  248. const oldChild = new Element( 'h2' );
  249. const newChild = new Element( 'h2' );
  250. const replacement = writer.replace( oldChild, newChild );
  251. expect( replacement ).to.false;
  252. expect( view.childCount ).to.equal( 4 );
  253. } );
  254. } );
  255. describe( 'unwrapElement', () => {
  256. it( 'should unwrap simple element', () => {
  257. const documentFragment = dataprocessor.toView( '<ul><li><p>foo</p></li></ul>' );
  258. const paragraph = documentFragment.getChild( 0 ).getChild( 0 ).getChild( 0 );
  259. writer.unwrapElement( paragraph );
  260. expect( dataprocessor.toData( documentFragment ) ).to.equal( '<ul><li>foo</li></ul>' );
  261. } );
  262. it( 'should unwrap element with children', () => {
  263. const documentFragment = dataprocessor.toView(
  264. '<p><span style="color:red"><strong>foo</strong><a href="example.com">example</a>bar</span></p>' );
  265. const span = documentFragment.getChild( 0 ).getChild( 0 );
  266. writer.unwrapElement( span );
  267. expect( dataprocessor.toData( documentFragment ) ).to.equal(
  268. '<p><strong>foo</strong><a href="example.com">example</a>bar</p>' );
  269. } );
  270. it( 'should do nothing for elements without parent', () => {
  271. const element = new Element( document, 'p', null, 'foo' );
  272. writer.unwrapElement( element );
  273. expect( dataprocessor.toData( element ) ).to.equal( '<p>foo</p>' );
  274. } );
  275. } );
  276. describe( 'rename', () => {
  277. it( 'should rename simple element', () => {
  278. const el = view.getChild( 0 ).getChild( 1 );
  279. const renamed = writer.rename( 'i', el );
  280. expect( renamed ).to.not.equal( el );
  281. expect( renamed ).to.equal( view.getChild( 0 ).getChild( 1 ) );
  282. expect( renamed.name ).to.equal( 'i' );
  283. expect( view.getChild( 0 ).childCount ).to.equal( 2 );
  284. } );
  285. it( 'should rename direct root (DocumentFragment) child element', () => {
  286. const el = view.getChild( 1 );
  287. const renamed = writer.rename( 'h3', el );
  288. expect( renamed ).to.not.equal( el );
  289. expect( renamed ).to.equal( view.getChild( 1 ) );
  290. expect( renamed.name ).to.equal( 'h3' );
  291. expect( view.childCount ).to.equal( 4 );
  292. } );
  293. it( 'should have no effect on detached element', () => {
  294. const el = new Element( document, 'h2' );
  295. const renamed = writer.rename( 'h3', el );
  296. expect( renamed ).to.null;
  297. expect( view.childCount ).to.equal( 4 );
  298. } );
  299. } );
  300. describe( 'setAttribute', () => {
  301. it( 'should add new attribute', () => {
  302. const el = view.getChild( 0 );
  303. writer.setAttribute( 'testAttr', 'testVal', el );
  304. expect( el.getAttribute( 'testAttr' ) ).to.equal( 'testVal' );
  305. } );
  306. it( 'should update existing attribute', () => {
  307. const el = view.getChild( 1 );
  308. writer.setAttribute( 'data-attr', 'foo', el );
  309. expect( el.getAttribute( 'data-attr' ) ).to.equal( 'foo' );
  310. } );
  311. } );
  312. describe( 'removeAttribute', () => {
  313. it( 'should remove existing attribute', () => {
  314. const el = view.getChild( 1 );
  315. writer.removeAttribute( 'data-attr', el );
  316. expect( el.hasAttribute( 'data-attr' ) ).to.false;
  317. } );
  318. it( 'should have no effect if attribute does not exists', () => {
  319. const el = view.getChild( 0 );
  320. writer.removeAttribute( 'non-existent', el );
  321. expect( el.hasAttribute( 'non-existent' ) ).to.false;
  322. } );
  323. } );
  324. describe( 'addClass', () => {
  325. it( 'should add new classes if no classes', () => {
  326. const el = view.getChild( 2 );
  327. writer.addClass( [ 'foo', 'bar' ], el );
  328. expect( el.hasClass( 'foo' ) ).to.true;
  329. expect( el.hasClass( 'bar' ) ).to.true;
  330. expect( Array.from( el.getClassNames() ).length ).to.equal( 2 );
  331. } );
  332. it( 'should add new class to existing classes', () => {
  333. const el = view.getChild( 1 );
  334. writer.addClass( 'newClass', el );
  335. expect( el.hasClass( 'newClass' ) ).to.true;
  336. expect( Array.from( el.getClassNames() ).length ).to.equal( 3 );
  337. } );
  338. } );
  339. describe( 'removeClass', () => {
  340. it( 'should remove existing class', () => {
  341. const el = view.getChild( 3 ).getChild( 0 );
  342. writer.removeClass( 'single', el );
  343. expect( el.hasClass( 'single' ) ).to.false;
  344. expect( Array.from( el.getClassNames() ).length ).to.equal( 0 );
  345. } );
  346. it( 'should remove existing class from many classes', () => {
  347. const el = view.getChild( 1 );
  348. writer.removeClass( 'foo1', el );
  349. expect( el.hasClass( 'foo1' ) ).to.false;
  350. expect( el.hasClass( 'bar2' ) ).to.true;
  351. expect( Array.from( el.getClassNames() ).length ).to.equal( 1 );
  352. } );
  353. it( 'should have no effect if there are no classes', () => {
  354. const el = view.getChild( 0 );
  355. writer.removeClass( 'non-existent', el );
  356. expect( el.hasClass( 'non-existent' ) ).to.false;
  357. expect( Array.from( el.getClassNames() ).length ).to.equal( 0 );
  358. } );
  359. } );
  360. describe( 'setStyle', () => {
  361. it( 'should add new style', () => {
  362. const el = view.getChild( 2 );
  363. writer.setStyle( {
  364. color: 'red',
  365. position: 'fixed'
  366. }, el );
  367. expect( el.getStyle( 'color' ) ).to.equal( 'red' );
  368. expect( el.getStyle( 'position' ) ).to.equal( 'fixed' );
  369. expect( Array.from( el.getStyleNames() ).length ).to.equal( 2 );
  370. } );
  371. it( 'should update existing styles', () => {
  372. const el = view.getChild( 1 );
  373. writer.setStyle( 'text-align', 'center', el );
  374. expect( el.getStyle( 'text-align' ) ).to.equal( 'center' );
  375. expect( Array.from( el.getStyleNames() ).length ).to.equal( 1 );
  376. } );
  377. } );
  378. describe( 'removeStyle', () => {
  379. it( 'should remove existing style', () => {
  380. const el = view.getChild( 0 );
  381. writer.removeStyle( [ 'color', 'position' ], el );
  382. expect( el.hasStyle( 'color' ) ).to.be.false;
  383. expect( el.hasStyle( 'position' ) ).to.be.false;
  384. expect( Array.from( el.getStyleNames() ).length ).to.equal( 0 );
  385. } );
  386. it( 'should remove value from existing styles', () => {
  387. const el = view.getChild( 0 );
  388. writer.removeStyle( 'position', el );
  389. expect( el.hasStyle( 'color' ) ).to.true;
  390. expect( el.hasStyle( 'position' ) ).to.false;
  391. expect( Array.from( el.getStyleNames() ).length ).to.equal( 1 );
  392. } );
  393. it( 'should have no effect if styles does not exists', () => {
  394. const el = view.getChild( 2 );
  395. writer.removeStyle( [ 'color', 'position' ], el );
  396. expect( el.hasStyle( 'color' ) ).to.false;
  397. expect( el.hasStyle( 'position' ) ).to.false;
  398. expect( Array.from( el.getStyleNames() ).length ).to.equal( 0 );
  399. } );
  400. } );
  401. describe( 'setCustomProperty', () => {
  402. it( 'should add or update custom property', () => {
  403. const el = new Element( 'span' );
  404. writer.setCustomProperty( 'prop1', 'foo', el );
  405. writer.setCustomProperty( 'prop2', 'bar', el );
  406. expect( el.getCustomProperty( 'prop1' ) ).to.equal( 'foo' );
  407. expect( el.getCustomProperty( 'prop2' ) ).to.equal( 'bar' );
  408. expect( Array.from( el.getCustomProperties() ).length ).to.equal( 2 );
  409. const objectProperty = { foo: 'bar' };
  410. writer.setCustomProperty( 'prop2', objectProperty, el );
  411. expect( el.getCustomProperty( 'prop1' ) ).to.equal( 'foo' );
  412. expect( el.getCustomProperty( 'prop2' ) ).to.equal( objectProperty );
  413. expect( Array.from( el.getCustomProperties() ).length ).to.equal( 2 );
  414. } );
  415. } );
  416. describe( 'removeCustomProperty', () => {
  417. it( 'should remove existing custom property', () => {
  418. const el = new Element( 'p' );
  419. writer.setCustomProperty( 'prop1', 'foo', el );
  420. expect( el.getCustomProperty( 'prop1' ) ).to.equal( 'foo' );
  421. expect( Array.from( el.getCustomProperties() ).length ).to.equal( 1 );
  422. writer.removeCustomProperty( 'prop1', el );
  423. expect( el.getCustomProperty( 'prop1' ) ).to.undefined;
  424. expect( Array.from( el.getCustomProperties() ).length ).to.equal( 0 );
  425. } );
  426. it( 'should have no effect if custom property does not exists', () => {
  427. const el = new Element( 'h1' );
  428. writer.removeCustomProperty( 'prop1', el );
  429. expect( el.getCustomProperty( 'prop1' ) ).to.undefined;
  430. expect( Array.from( el.getCustomProperties() ).length ).to.equal( 0 );
  431. } );
  432. } );
  433. describe( 'createPositionAt()', () => {
  434. it( 'should return instance of Position', () => {
  435. const span = new Element( document, 'span' );
  436. expect( writer.createPositionAt( span, 0 ) ).to.be.instanceof( ViewPosition );
  437. } );
  438. } );
  439. describe( 'createPositionAfter()', () => {
  440. it( 'should return instance of Position', () => {
  441. const span = new Element( document, 'span', undefined, new Element( document, 'span' ) );
  442. expect( writer.createPositionAfter( span.getChild( 0 ) ) ).to.be.instanceof( ViewPosition );
  443. } );
  444. } );
  445. describe( 'createPositionBefore()', () => {
  446. it( 'should return instance of Position', () => {
  447. const span = new Element( document, 'span', undefined, new Element( document, 'span' ) );
  448. expect( writer.createPositionBefore( span.getChild( 0 ) ) ).to.be.instanceof( ViewPosition );
  449. } );
  450. } );
  451. describe( 'createRange()', () => {
  452. it( 'should return instance of Range', () => {
  453. expect( writer.createRange( writer.createPositionAt( new Element( document, 'span' ), 0 ) ) ).to.be.instanceof( ViewRange );
  454. } );
  455. } );
  456. describe( 'createRangeIn()', () => {
  457. it( 'should return instance of Range', () => {
  458. const span = new Element( document, 'span', undefined, new Element( document, 'span' ) );
  459. expect( writer.createRangeIn( span.getChild( 0 ) ) ).to.be.instanceof( ViewRange );
  460. } );
  461. } );
  462. describe( 'createRangeOn()', () => {
  463. it( 'should return instance of Range', () => {
  464. const span = new Element( document, 'span', undefined, new Element( document, 'span' ) );
  465. expect( writer.createRangeOn( span.getChild( 0 ) ) ).to.be.instanceof( ViewRange );
  466. } );
  467. } );
  468. describe( 'createSelection()', () => {
  469. it( 'should return instance of Selection', () => {
  470. expect( writer.createSelection() ).to.be.instanceof( ViewSelection );
  471. } );
  472. } );
  473. } );