8
0

utils.js 1.6 KB

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