utils.js 1.7 KB

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