8
0

utils.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import ViewElement from '@ckeditor/ckeditor5-engine/src/view/element';
  6. import { widgetize, isWidget, WIDGET_CLASS_NAME, setFakeSelectionLabel, getFakeSelectionLabel } from '../../src/widget/utils';
  7. describe( 'widget utils', () => {
  8. let element;
  9. beforeEach( () => {
  10. element = new ViewElement( 'div' );
  11. widgetize( element );
  12. } );
  13. describe( 'widgetize()', () => {
  14. it( 'should set contenteditable to false', () => {
  15. expect( element.getAttribute( 'contenteditable' ) ).to.be.false;
  16. } );
  17. it( 'should define getFillerOffset method', () => {
  18. expect( element.getFillerOffset ).to.be.function;
  19. expect( element.getFillerOffset() ).to.be.null;
  20. } );
  21. it( 'should add proper CSS class', () => {
  22. expect( element.hasClass( WIDGET_CLASS_NAME ) ).to.be.true;
  23. } );
  24. } );
  25. describe( 'isWidget()', () => {
  26. it( 'should return true for widgetized elements', () => {
  27. expect( isWidget( element ) ).to.be.true;
  28. } );
  29. it( 'should return false for non-widgetized elements', () => {
  30. expect( isWidget( new ViewElement( 'p' ) ) ).to.be.false;
  31. } );
  32. } );
  33. describe( 'fake selection label utils', () => {
  34. it( 'should allow to set fake selection for element', () => {
  35. const element = new ViewElement( 'p' );
  36. setFakeSelectionLabel( element, 'foo bar baz' );
  37. expect( getFakeSelectionLabel( element ) ).to.equal( 'foo bar baz' );
  38. } );
  39. it( 'should return undefined for elements without fake selection label', () => {
  40. const element = new ViewElement( 'div' );
  41. expect( getFakeSelectionLabel( element ) ).to.be.undefined;
  42. } );
  43. it( 'should allow to use a function as label creator', () => {
  44. const element = new ViewElement( 'p' );
  45. let caption = 'foo';
  46. setFakeSelectionLabel( element, () => caption );
  47. expect( getFakeSelectionLabel( element ) ).to.equal( 'foo' );
  48. caption = 'bar';
  49. expect( getFakeSelectionLabel( element ) ).to.equal( 'bar' );
  50. } );
  51. } );
  52. } );