emptyelement.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. it( 'should throw if child elements are passed to constructor', () => {
  20. expect( () => {
  21. new EmptyElement( 'img', null, [ new Element( 'i' ) ] );
  22. } ).to.throw( CKEditorError, 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
  23. } );
  24. describe( 'appendChildren', () => {
  25. it( 'should throw when try to append new child element', () => {
  26. expect( () => {
  27. emptyElement.appendChildren( element );
  28. } ).to.throw( CKEditorError, 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
  29. } );
  30. } );
  31. describe( 'insertChildren', () => {
  32. it( 'should throw when try to insert new child element', () => {
  33. expect( () => {
  34. emptyElement.insertChildren( 0, element );
  35. } ).to.throw( CKEditorError, 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
  36. } );
  37. } );
  38. describe( 'clone', () => {
  39. it( 'should be cloned properly', () => {
  40. const newEmptyElement = emptyElement.clone();
  41. expect( newEmptyElement.name ).to.equal( 'img' );
  42. expect( newEmptyElement.getAttribute( 'alt' ) ).to.equal( 'alternative text' );
  43. expect( newEmptyElement.getStyle( 'border' ) ).to.equal( '1px solid red' );
  44. expect( newEmptyElement.getStyle( 'color' ) ).to.equal( 'white' );
  45. expect( newEmptyElement.hasClass( 'image' ) ).to.be.true;
  46. expect( newEmptyElement.hasClass( 'big' ) ).to.be.true;
  47. expect( newEmptyElement.isSimilar( emptyElement ) ).to.be.true;
  48. } );
  49. } );
  50. describe( 'getFillerOffset', () => {
  51. it( 'should return null', () => {
  52. expect( emptyElement.getFillerOffset() ).to.be.null;
  53. } );
  54. } );
  55. } );