text.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Node from 'ckeditor5-engine/src/view/node';
  6. import Text from 'ckeditor5-engine/src/view/text';
  7. describe( 'Element', () => {
  8. describe( 'constructor()', () => {
  9. it( 'should create element without attributes', () => {
  10. const text = new Text( 'foo' );
  11. expect( text ).to.be.an.instanceof( Node );
  12. expect( text.data ).to.equal( 'foo' );
  13. expect( text ).to.have.property( 'parent' ).that.is.null;
  14. } );
  15. } );
  16. describe( 'clone', () => {
  17. it( 'should return new text with same data', () => {
  18. const text = new Text( 'foo bar' );
  19. const clone = text.clone();
  20. expect( clone ).to.not.equal( text );
  21. expect( clone.data ).to.equal( text.data );
  22. } );
  23. } );
  24. describe( 'isSimilar', () => {
  25. const text = new Text( 'foo' );
  26. it( 'should return false when comparing to non-text', () => {
  27. expect( text.isSimilar( null ) ).to.be.false;
  28. expect( text.isSimilar( {} ) ).to.be.false;
  29. } );
  30. it( 'should return true when the same text node is provided', () => {
  31. expect( text.isSimilar( text ) ).to.be.true;
  32. } );
  33. it( 'should return true when data is the same', () => {
  34. const other = new Text( 'foo' );
  35. expect( text.isSimilar( other ) ).to.be.true;
  36. } );
  37. it( 'should return false when data is not the same', () => {
  38. const other = text.clone();
  39. other.data = 'not-foo';
  40. expect( text.isSimilar( other ) ).to.be.false;
  41. } );
  42. } );
  43. describe( 'setText', () => {
  44. it( 'should change the text', () => {
  45. const text = new Text( 'foo' );
  46. text.data = 'bar';
  47. expect( text.data ).to.equal( 'bar' );
  48. } );
  49. } );
  50. } );