boldengine.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. import BoldEngine from '/ckeditor5/basic-styles/boldengine.js';
  7. import Editor from '/ckeditor5/editor.js';
  8. import StandardCreator from '/ckeditor5/creator/standardcreator.js';
  9. import { getData } from '/tests/engine/_utils/model.js';
  10. import BuildModelConverterFor from '/ckeditor5/engine/conversion/model-converter-builder.js';
  11. import BuildViewConverterFor from '/ckeditor5/engine/conversion/view-converter-builder.js';
  12. describe( 'BoldEngine', () => {
  13. let editor, document;
  14. beforeEach( () => {
  15. editor = new Editor( null, {
  16. creator: StandardCreator,
  17. features: [ BoldEngine ]
  18. } );
  19. return editor.init().then( () => {
  20. document = editor.document;
  21. document.createRoot( 'main' );
  22. // Register some block element for tests.
  23. document.schema.registerItem( 'p', '$block' );
  24. // Build converter from model to view for data and editing pipelines.
  25. BuildModelConverterFor( editor.data.modelToView )
  26. .fromElement( 'p' )
  27. .toElement( 'p' );
  28. // Build converter from view to model for data and editing pipelines.
  29. BuildViewConverterFor( editor.data.viewToModel )
  30. .fromElement( 'p' )
  31. .toElement( 'p' );
  32. } );
  33. } );
  34. it( 'should be loaded', () => {
  35. expect( editor.plugins.get( BoldEngine ) ).to.be.instanceOf( BoldEngine );
  36. } );
  37. it( 'should set proper schema rules', () => {
  38. expect( document.schema.check( { name: '$inline', attributes: [ 'bold' ], inside: '$block' } ) ).to.be.true;
  39. } );
  40. it( 'should convert <strong> to bold attribute', () => {
  41. editor.setData( '<p><strong>foobar</strong></p>' );
  42. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<p><$text bold=true>foobar</$text></p>' );
  43. expect( editor.getData() ).to.equal( '<p><strong>foobar</strong></p>' );
  44. } );
  45. it( 'should convert <b> to bold attribute', () => {
  46. editor.setData( '<p><b>foobar</b></p>' );
  47. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<p><$text bold=true>foobar</$text></p>' );
  48. expect( editor.getData() ).to.equal( '<p><strong>foobar</strong></p>' );
  49. } );
  50. it( 'should convert font-weight:bold to bold attribute', () => {
  51. editor.setData( '<p style="font-weight: bold;">foobar</p>' );
  52. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<p><$text bold=true>foobar</$text></p>' );
  53. expect( editor.getData() ).to.equal( '<p><strong>foobar</strong></p>' );
  54. } );
  55. } );