text.js 1.7 KB

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