utils.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import AttributeElement from '@ckeditor/ckeditor5-engine/src/view/attributeelement';
  6. import ContainerElement from '@ckeditor/ckeditor5-engine/src/view/containerelement';
  7. import Text from '@ckeditor/ckeditor5-engine/src/view/text';
  8. import { createLinkElement, isLinkElement } from '../src/utils';
  9. describe( 'utils', () => {
  10. describe( 'isLinkElement', () => {
  11. it( 'should return true for elements created by createLinkElement', () => {
  12. const element = createLinkElement( 'http://ckeditor.com' );
  13. expect( isLinkElement( element ) ).to.be.true;
  14. } );
  15. it( 'should return false for other AttributeElements', () => {
  16. expect( isLinkElement( new AttributeElement( 'a' ) ) ).to.be.false;
  17. } );
  18. it( 'should return false for ContainerElements', () => {
  19. expect( isLinkElement( new ContainerElement( 'p' ) ) ).to.be.false;
  20. } );
  21. it( 'should return false for text nodes', () => {
  22. expect( isLinkElement( new Text( 'foo' ) ) ).to.be.false;
  23. } );
  24. } );
  25. describe( 'createLinkElement', () => {
  26. it( 'should create link AttributeElement', () => {
  27. const element = createLinkElement( 'http://cksource.com' );
  28. expect( isLinkElement( element ) ).to.be.true;
  29. expect( element.priority ).to.equal( 5 );
  30. expect( element.getAttribute( 'href' ) ).to.equal( 'http://cksource.com' );
  31. expect( element.name ).to.equal( 'a' );
  32. } );
  33. } );
  34. } );