text.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 node, text', () => {
  22. expect( text.is( 'node' ) ).to.be.true;
  23. expect( text.is( 'text' ) ).to.be.true;
  24. } );
  25. it( 'should return false for other accept values', () => {
  26. expect( text.is( 'textProxy' ) ).to.be.false;
  27. expect( text.is( 'element' ) ).to.be.false;
  28. expect( text.is( 'containerElement' ) ).to.be.false;
  29. expect( text.is( 'attributeElement' ) ).to.be.false;
  30. expect( text.is( 'uiElement' ) ).to.be.false;
  31. expect( text.is( 'emptyElement' ) ).to.be.false;
  32. expect( text.is( 'rootElement' ) ).to.be.false;
  33. expect( text.is( 'documentFragment' ) ).to.be.false;
  34. } );
  35. } );
  36. describe( '_clone()', () => {
  37. it( 'should return new text with same data', () => {
  38. const text = new Text( 'foo bar' );
  39. const clone = text._clone();
  40. expect( clone ).to.not.equal( text );
  41. expect( clone.data ).to.equal( text.data );
  42. } );
  43. } );
  44. describe( 'isSimilar', () => {
  45. const text = new Text( 'foo' );
  46. it( 'should return false when comparing to non-text', () => {
  47. expect( text.isSimilar( null ) ).to.be.false;
  48. expect( text.isSimilar( {} ) ).to.be.false;
  49. } );
  50. it( 'should return true when the same text node is provided', () => {
  51. expect( text.isSimilar( text ) ).to.be.true;
  52. } );
  53. it( 'should return true when data is the same', () => {
  54. const other = new Text( 'foo' );
  55. expect( text.isSimilar( other ) ).to.be.true;
  56. } );
  57. it( 'should return false when data is not the same', () => {
  58. const other = text._clone();
  59. other._data = 'not-foo';
  60. expect( text.isSimilar( other ) ).to.be.false;
  61. } );
  62. } );
  63. describe( 'setText', () => {
  64. it( 'should change the text', () => {
  65. const text = new Text( 'foo' );
  66. text._data = 'bar';
  67. expect( text.data ).to.equal( 'bar' );
  68. } );
  69. it( 'works when using addition assignment operator (+=)', () => {
  70. const foo = new Text( 'foo' );
  71. const bar = new Text( 'bar' );
  72. foo._data += bar.data;
  73. expect( foo.data ).to.equal( 'foobar' );
  74. } );
  75. } );
  76. } );