text.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. // This is same set of tests as in engine.model.Text tests. Look there for comments on tests.
  52. describe( 'unicode support', () => {
  53. it( 'should normalize strings kept in data', () => {
  54. let dataCombined = '\u006E\u0303';
  55. let textN = new Text( dataCombined );
  56. expect( textN.data ).to.equal( '\u00F1' );
  57. expect( textN.data.length ).to.equal( 1 );
  58. } );
  59. } );
  60. } );