character.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: treemodel */
  6. 'use strict';
  7. import coreTestUtils from '/tests/core/_utils/utils.js';
  8. import Character from '/ckeditor5/core/treemodel/character.js';
  9. import Node from '/ckeditor5/core/treemodel/node.js';
  10. import Element from '/ckeditor5/core/treemodel/element.js';
  11. import Attribute from '/ckeditor5/core/treemodel/attribute.js';
  12. const getIteratorCount = coreTestUtils.getIteratorCount;
  13. describe( 'Character', () => {
  14. describe( 'constructor', () => {
  15. it( 'should create character without attributes', () => {
  16. let character = new Character( 'f' );
  17. let parent = new Element( 'parent', [], character );
  18. expect( character ).to.be.an.instanceof( Node );
  19. expect( character ).to.have.property( 'character' ).that.equals( 'f' );
  20. expect( character ).to.have.property( 'parent' ).that.equals( parent );
  21. expect( getIteratorCount( character.getAttrs() ) ).to.equal( 0 );
  22. } );
  23. it( 'should create character with attributes', () => {
  24. let attr = new Attribute( 'foo', 'bar' );
  25. let character = new Character( 'f', [ attr ] );
  26. let parent = new Element( 'parent', [], character );
  27. expect( character ).to.be.an.instanceof( Node );
  28. expect( character ).to.have.property( 'character' ).that.equals( 'f' );
  29. expect( character ).to.have.property( 'parent' ).that.equals( parent );
  30. expect( getIteratorCount( character.getAttrs() ) ).to.equal( 1 );
  31. expect( character.getAttr( attr.key ) ).to.equal( attr.value );
  32. } );
  33. } );
  34. } );