8
0

title-integration.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* global document */
  6. import Title from '../src/title';
  7. import Heading from '../src/heading.js';
  8. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  9. import Enter from '@ckeditor/ckeditor5-enter/src/enter';
  10. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
  11. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  12. import { getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  13. describe( 'Title integration', () => {
  14. let editor, model, doc, element;
  15. beforeEach( () => {
  16. element = document.createElement( 'div' );
  17. document.body.appendChild( element );
  18. return ClassicTestEditor
  19. .create( element, {
  20. plugins: [ Paragraph, Heading, Enter, Bold, Title ]
  21. } )
  22. .then( newEditor => {
  23. editor = newEditor;
  24. model = editor.model;
  25. doc = model.document;
  26. } );
  27. } );
  28. afterEach( () => {
  29. element.remove();
  30. return editor.destroy();
  31. } );
  32. describe( 'with basic styles', () => {
  33. // See: https://github.com/ckeditor/ckeditor5/issues/6427
  34. it( 'should work when basic styles are applied to the content', () => {
  35. editor.setData( '<h1>Title</h1><p>Foo</p>' );
  36. editor.model.change( writer => {
  37. writer.setSelection( doc.getRoot().getChild( 1 ), 'on' );
  38. } );
  39. editor.execute( 'bold' );
  40. expect( editor.plugins.get( Title ).getBody() ).to.equal(
  41. '<p><strong>Foo</strong></p>'
  42. );
  43. expect( getModelData( model ) ).to.equal(
  44. '<title><title-content>Title</title-content></title><paragraph>[<$text bold="true">Foo</$text>]</paragraph>'
  45. );
  46. } );
  47. } );
  48. } );