8
0

emptyelement.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 EmptyElement from '/ckeditor5/engine/view/emptyelement.js';
  7. import Element from '/ckeditor5/engine/view/element.js';
  8. import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
  9. describe( 'EmptyElement', () => {
  10. let element, emptyElement;
  11. beforeEach( () => {
  12. element = new Element( 'b' );
  13. emptyElement = new EmptyElement( 'img', {
  14. alt: 'alternative text',
  15. style: 'border: 1px solid red;color: white;',
  16. class: 'image big'
  17. } );
  18. } );
  19. describe( 'appendChildren', () => {
  20. it( 'should throw when try to append new child element', () => {
  21. expect( () => {
  22. emptyElement.appendChildren( element );
  23. } ).to.throw( CKEditorError, 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
  24. } );
  25. } );
  26. describe( 'insertChildren', () => {
  27. it( 'should throw when try to insert new child element', () => {
  28. expect( () => {
  29. emptyElement.insertChildren( 0, element );
  30. } ).to.throw( CKEditorError, 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
  31. } );
  32. } );
  33. describe( 'clone', () => {
  34. it( 'should be cloned properly', () => {
  35. const newEmptyElement = emptyElement.clone();
  36. expect( newEmptyElement.name ).to.equal( 'img' );
  37. expect( newEmptyElement.getAttribute( 'alt' ) ).to.equal( 'alternative text' );
  38. expect( newEmptyElement.getStyle( 'border' ) ).to.equal( '1px solid red' );
  39. expect( newEmptyElement.getStyle( 'color' ) ).to.equal( 'white' );
  40. expect( newEmptyElement.hasClass( 'image' ) ).to.be.true;
  41. expect( newEmptyElement.hasClass( 'big' ) ).to.be.true;
  42. expect( newEmptyElement.isSimilar( emptyElement ) ).to.be.true;
  43. } );
  44. } );
  45. describe( 'getFillerOffset', () => {
  46. it( 'should return null', () => {
  47. expect( emptyElement.getFillerOffset() ).to.be.null;
  48. } );
  49. } );
  50. } );