containerelement.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import ContainerElement from '../../src/view/containerelement';
  6. import Element from '../../src/view/element';
  7. import { parse } from '../../src/dev-utils/view';
  8. describe( 'ContainerElement', () => {
  9. describe( 'constructor()', () => {
  10. it( 'should create element with default priority', () => {
  11. const el = new ContainerElement( 'p' );
  12. expect( el ).to.be.an.instanceof( ContainerElement );
  13. expect( el ).to.be.an.instanceof( Element );
  14. expect( el ).to.have.property( 'name' ).that.equals( 'p' );
  15. } );
  16. } );
  17. describe( 'is', () => {
  18. let el;
  19. before( () => {
  20. el = new ContainerElement( 'p' );
  21. } );
  22. it( 'should return true for containerElement/element, also with correct name and element name', () => {
  23. expect( el.is( 'containerElement' ) ).to.be.true;
  24. expect( el.is( 'containerElement', 'p' ) ).to.be.true;
  25. expect( el.is( 'element' ) ).to.be.true;
  26. expect( el.is( 'element', 'p' ) ).to.be.true;
  27. expect( el.is( 'p' ) ).to.be.true;
  28. } );
  29. it( 'should return false for other accept values', () => {
  30. expect( el.is( 'containerElement', 'span' ) ).to.be.false;
  31. expect( el.is( 'element', 'span' ) ).to.be.false;
  32. expect( el.is( 'span' ) ).to.be.false;
  33. expect( el.is( 'text' ) ).to.be.false;
  34. expect( el.is( 'textProxy' ) ).to.be.false;
  35. expect( el.is( 'attributeElement' ) ).to.be.false;
  36. expect( el.is( 'uiElement' ) ).to.be.false;
  37. expect( el.is( 'emptyElement' ) ).to.be.false;
  38. expect( el.is( 'rootElement' ) ).to.be.false;
  39. expect( el.is( 'documentFragment' ) ).to.be.false;
  40. } );
  41. } );
  42. describe( 'getFillerOffset', () => {
  43. it( 'should return position 0 if element is empty', () => {
  44. expect( parse( '<container:p></container:p>' ).getFillerOffset() ).to.equals( 0 );
  45. } );
  46. it( 'should return offset after all children if element contains only ui elements', () => {
  47. expect( parse( '<container:p><ui:span></ui:span><ui:span></ui:span></container:p>' ).getFillerOffset() ).to.equals( 2 );
  48. } );
  49. it( 'should return null if element is not empty', () => {
  50. expect( parse( '<container:p>foo</container:p>' ).getFillerOffset() ).to.be.null;
  51. } );
  52. } );
  53. } );