emptyelement.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import EmptyElement from '../../src/view/emptyelement';
  6. import Element from '../../src/view/element';
  7. import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  8. describe( 'EmptyElement', () => {
  9. let element, emptyElement;
  10. beforeEach( () => {
  11. element = new Element( 'b' );
  12. emptyElement = new EmptyElement( 'img', {
  13. alt: 'alternative text',
  14. style: 'border: 1px solid red;color: white;',
  15. class: 'image big'
  16. } );
  17. } );
  18. it( 'should throw if child elements are passed to constructor', () => {
  19. expect( () => {
  20. new EmptyElement( 'img', null, [ new Element( 'i' ) ] );
  21. } ).to.throw( CKEditorError, 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
  22. } );
  23. describe( 'appendChildren', () => {
  24. it( 'should throw when try to append new child element', () => {
  25. expect( () => {
  26. emptyElement.appendChildren( element );
  27. } ).to.throw( CKEditorError, 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
  28. } );
  29. } );
  30. describe( 'insertChildren', () => {
  31. it( 'should throw when try to insert new child element', () => {
  32. expect( () => {
  33. emptyElement.insertChildren( 0, element );
  34. } ).to.throw( CKEditorError, 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
  35. } );
  36. } );
  37. describe( 'clone', () => {
  38. it( 'should be cloned properly', () => {
  39. const newEmptyElement = emptyElement.clone();
  40. expect( newEmptyElement.name ).to.equal( 'img' );
  41. expect( newEmptyElement.getAttribute( 'alt' ) ).to.equal( 'alternative text' );
  42. expect( newEmptyElement.getStyle( 'border' ) ).to.equal( '1px solid red' );
  43. expect( newEmptyElement.getStyle( 'color' ) ).to.equal( 'white' );
  44. expect( newEmptyElement.hasClass( 'image' ) ).to.be.true;
  45. expect( newEmptyElement.hasClass( 'big' ) ).to.be.true;
  46. expect( newEmptyElement.isSimilar( emptyElement ) ).to.be.true;
  47. } );
  48. } );
  49. describe( 'getFillerOffset', () => {
  50. it( 'should return null', () => {
  51. expect( emptyElement.getFillerOffset() ).to.be.null;
  52. } );
  53. } );
  54. } );