8
0

utils.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 } 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. describe( 'getNodesAndText', () => {
  11. let doc, root, div, p;
  12. beforeEach( () => {
  13. doc = new Document();
  14. root = doc.createRoot( '$root', 'root' );
  15. div = new Element( 'div', [], 'foobar' );
  16. p = new Element( 'p', [], 'abcxyz' );
  17. root.insertChildren( 0, [ div, p ] );
  18. } );
  19. it( 'reads two elements with text', () => {
  20. expect( getNodesAndText( Range.createFromElement( root ) ) ).to.equal( 'DIVfoobarDIVPabcxyzP' );
  21. } );
  22. } );
  23. describe( 'jsonParseStringify', () => {
  24. class Foo {
  25. constructor( ra ) {
  26. this.ra = ra;
  27. }
  28. }
  29. it( 'should return cleaned object', () => {
  30. let foo = new Foo( { bar: 'bar' } );
  31. let fooJsoned = jsonParseStringify( foo );
  32. expect( fooJsoned ).to.not.be.instanceOf( Foo );
  33. expect( fooJsoned ).to.deep.equal( { ra: { bar: 'bar' } } );
  34. } );
  35. } );