text.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. 'use strict';
  7. import ViewNode from '/ckeditor5/engine/view/node.js';
  8. import ViewText from '/ckeditor5/engine/view/text.js';
  9. describe( 'Element', () => {
  10. describe( 'constructor', () => {
  11. it( 'should create element without attributes', () => {
  12. const text = new ViewText( 'foo' );
  13. expect( text ).to.be.an.instanceof( ViewNode );
  14. expect( text.data ).to.equal( 'foo' );
  15. expect( text ).to.have.property( 'parent' ).that.is.null;
  16. } );
  17. } );
  18. describe( 'clone', () => {
  19. it( 'should return new text with same data', () => {
  20. const text = new ViewText( 'foo bar' );
  21. const clone = text.clone();
  22. expect( clone ).to.not.equal( text );
  23. expect( clone.data ).to.equal( text.data );
  24. } );
  25. } );
  26. describe( 'isSimilar', () => {
  27. const text = new ViewText( 'foo' );
  28. it( 'should return false when comparing to non-text', () => {
  29. expect( text.isSimilar( null ) ).to.be.false;
  30. expect( text.isSimilar( {} ) ).to.be.false;
  31. } );
  32. it( 'should return true when the same text node is provided', () => {
  33. expect( text.isSimilar( text ) ).to.be.true;
  34. } );
  35. it( 'sould return true when data is the same', () => {
  36. const other = new ViewText( 'foo' );
  37. expect( text.isSimilar( other ) ).to.be.true;
  38. } );
  39. it( 'sould return false when data is not the same', () => {
  40. const other = text.clone();
  41. other.data = 'not-foo';
  42. expect( text.isSimilar( other ) ).to.be.false;
  43. } );
  44. } );
  45. describe( 'setText', () => {
  46. it( 'should change the text', () => {
  47. const text = new ViewText( 'foo' );
  48. text.data = 'bar';
  49. expect( text.data ).to.equal( 'bar' );
  50. } );
  51. } );
  52. } );