uielement.js 2.5 KB

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