8
0

text.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Node from '../../src/view/node';
  6. import Text from '../../src/view/text';
  7. describe( 'Text', () => {
  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( 'is', () => {
  17. let text;
  18. before( () => {
  19. text = new Text( 'foo' );
  20. } );
  21. it( 'should return true for text', () => {
  22. expect( text.is( 'text' ) ).to.be.true;
  23. } );
  24. it( 'should return false for other accept values', () => {
  25. expect( text.is( 'textProxy' ) ).to.be.false;
  26. expect( text.is( 'element' ) ).to.be.false;
  27. expect( text.is( 'containerElement' ) ).to.be.false;
  28. expect( text.is( 'attributeElement' ) ).to.be.false;
  29. expect( text.is( 'uiElement' ) ).to.be.false;
  30. expect( text.is( 'emptyElement' ) ).to.be.false;
  31. expect( text.is( 'rootElement' ) ).to.be.false;
  32. expect( text.is( 'documentFragment' ) ).to.be.false;
  33. } );
  34. } );
  35. describe( '_clone()', () => {
  36. it( 'should return new text with same data', () => {
  37. const text = new Text( 'foo bar' );
  38. const clone = text._clone();
  39. expect( clone ).to.not.equal( text );
  40. expect( clone.data ).to.equal( text.data );
  41. } );
  42. } );
  43. describe( 'isSimilar', () => {
  44. const text = new Text( 'foo' );
  45. it( 'should return false when comparing to non-text', () => {
  46. expect( text.isSimilar( null ) ).to.be.false;
  47. expect( text.isSimilar( {} ) ).to.be.false;
  48. } );
  49. it( 'should return true when the same text node is provided', () => {
  50. expect( text.isSimilar( text ) ).to.be.true;
  51. } );
  52. it( 'should return true when data is the same', () => {
  53. const other = new Text( 'foo' );
  54. expect( text.isSimilar( other ) ).to.be.true;
  55. } );
  56. it( 'should return false when data is not the same', () => {
  57. const other = text._clone();
  58. other._data = 'not-foo';
  59. expect( text.isSimilar( other ) ).to.be.false;
  60. } );
  61. } );
  62. describe( 'setText', () => {
  63. it( 'should change the text', () => {
  64. const text = new Text( 'foo' );
  65. text._data = 'bar';
  66. expect( text.data ).to.equal( 'bar' );
  67. } );
  68. it( 'works when using addition assignment operator (+=)', () => {
  69. const foo = new Text( 'foo' );
  70. const bar = new Text( 'bar' );
  71. foo._data += bar.data;
  72. expect( foo.data ).to.equal( 'foobar' );
  73. } );
  74. } );
  75. } );