textnode.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: treemodel */
  6. 'use strict';
  7. const modules = bender.amd.require(
  8. 'core/treemodel/node',
  9. 'core/treemodel/element',
  10. 'core/treemodel/text',
  11. 'core/treemodel/textnode',
  12. 'core/treemodel/attribute',
  13. 'core/treemodel/attributelist'
  14. );
  15. describe( 'TextNode', () => {
  16. let Node, Element, Text, TextNode, Attribute, AttributeList;
  17. let text, element, textNode;
  18. before( () => {
  19. Node = modules[ 'core/treemodel/node' ];
  20. Element = modules[ 'core/treemodel/element' ];
  21. Text = modules[ 'core/treemodel/text' ];
  22. TextNode = modules[ 'core/treemodel/textnode' ];
  23. Attribute = modules[ 'core/treemodel/attribute' ];
  24. AttributeList = modules[ 'core/treemodel/attribute' ];
  25. text = new Text( 'foobar', [ new Attribute( 'foo', true ) ] );
  26. element = new Element( 'div', [], [ new Element( 'p' ), 'abc', text, new Element( 'p' ) ] );
  27. } );
  28. beforeEach( () => {
  29. textNode = new TextNode( text, 2, 3 );
  30. } );
  31. it( 'should extend Node class', () => {
  32. expect( textNode ).to.be.instanceof( Node );
  33. } );
  34. it( 'should have text property basing on passed Text instance', () => {
  35. expect( textNode ).to.have.property( 'text' ).that.equals( 'oba' );
  36. } );
  37. it( 'should have parent property basing on passed Text instance', () => {
  38. expect( textNode ).to.have.property( 'parent' ).that.equals( element );
  39. } );
  40. it( 'should have attributes list equal to passed Text instance', () => {
  41. expect( textNode.attrs.isEqual( text.attrs ) ).to.be.true;
  42. } );
  43. it( 'should have correct start property', () => {
  44. expect( textNode._start ).to.equal( 2 );
  45. } );
  46. it( 'should not change original Text instance when changed', () => {
  47. textNode.text = 'ab';
  48. textNode._start = 0;
  49. textNode.parent = new Element( 'p' );
  50. textNode.attrs = new AttributeList();
  51. expect( text.text ).to.equal( 'foobar' );
  52. expect( text.parent ).to.equal( element );
  53. expect( text.attrs.size ).to.equal( 1 );
  54. } );
  55. it( 'getIndex should return value with text node offset in original Text instance', () => {
  56. expect( textNode.getIndex() ).to.equal( 6 );
  57. } );
  58. it( 'should have nextSibling property which is a node/character placed after the last character from text node', () => {
  59. expect( textNode ).to.have.property( 'nextSibling' );
  60. expect( textNode.nextSibling.text ).to.equal( 'r' );
  61. } );
  62. } );