8
0

utils.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import { getNodesAndText, jsonParseStringify, wrapInDelta } from '/tests/engine/model/_utils/utils.js';
  6. import Document from '/ckeditor5/engine/model/document.js';
  7. import Range from '/ckeditor5/engine/model/range.js';
  8. import Element from '/ckeditor5/engine/model/element.js';
  9. import Operation from '/ckeditor5/engine/model/operation/operation.js';
  10. import Delta from '/ckeditor5/engine/model/delta/delta.js';
  11. describe( 'getNodesAndText', () => {
  12. let doc, root, div, p;
  13. beforeEach( () => {
  14. doc = new Document();
  15. root = doc.createRoot();
  16. div = new Element( 'div', [], 'foobar' );
  17. p = new Element( 'p', [], 'abcxyz' );
  18. root.insertChildren( 0, [ div, p ] );
  19. } );
  20. it( 'reads two elements with text', () => {
  21. expect( getNodesAndText( Range.createFromElement( root ) ) ).to.equal( 'DIVfoobarDIVPabcxyzP' );
  22. } );
  23. } );
  24. describe( 'jsonParseStringify', () => {
  25. class Foo {
  26. constructor( ra ) {
  27. this.ra = ra;
  28. }
  29. }
  30. it( 'should return cleaned object', () => {
  31. let foo = new Foo( { bar: 'bar' } );
  32. let fooJsoned = jsonParseStringify( foo );
  33. expect( fooJsoned ).to.not.be.instanceOf( Foo );
  34. expect( fooJsoned ).to.deep.equal( { ra: { bar: 'bar' } } );
  35. } );
  36. } );
  37. describe( 'wrapInDelta', () => {
  38. it( 'should return given operation wrapped in a delta', () => {
  39. const op = new Operation( 0 );
  40. const wrapped = wrapInDelta( op );
  41. expect( wrapped ).to.equal( op );
  42. expect( wrapped.delta ).to.be.instanceof( Delta );
  43. } );
  44. } );