utils.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 Operation from '/ckeditor5/engine/model/operation/operation.js';
  11. import Delta from '/ckeditor5/engine/model/delta/delta.js';
  12. describe( 'getNodesAndText', () => {
  13. let doc, root, div, p;
  14. beforeEach( () => {
  15. doc = new Document();
  16. root = doc.createRoot();
  17. div = new Element( 'div', [], 'foobar' );
  18. p = new Element( 'p', [], 'abcxyz' );
  19. root.insertChildren( 0, [ div, p ] );
  20. } );
  21. it( 'reads two elements with text', () => {
  22. expect( getNodesAndText( Range.createFromElement( root ) ) ).to.equal( 'DIVfoobarDIVPabcxyzP' );
  23. } );
  24. } );
  25. describe( 'jsonParseStringify', () => {
  26. class Foo {
  27. constructor( ra ) {
  28. this.ra = ra;
  29. }
  30. }
  31. it( 'should return cleaned object', () => {
  32. let foo = new Foo( { bar: 'bar' } );
  33. let fooJsoned = jsonParseStringify( foo );
  34. expect( fooJsoned ).to.not.be.instanceOf( Foo );
  35. expect( fooJsoned ).to.deep.equal( { ra: { bar: 'bar' } } );
  36. } );
  37. } );
  38. describe( 'wrapInDelta', () => {
  39. it( 'should return given operation wrapped in a delta', () => {
  40. const op = new Operation( 0 );
  41. const wrapped = wrapInDelta( op );
  42. expect( wrapped ).to.equal( op );
  43. expect( wrapped.delta ).to.be.instanceof( Delta );
  44. } );
  45. } );