boldengine.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. import AttributeCommand from '/ckeditor5/command/attributecommand.js';
  13. describe( 'BoldEngine', () => {
  14. let editor, document;
  15. beforeEach( () => {
  16. editor = new Editor( null, {
  17. creator: StandardCreator,
  18. features: [ BoldEngine ]
  19. } );
  20. return editor.init().then( () => {
  21. document = editor.document;
  22. document.createRoot( 'main' );
  23. // Register some block element for tests.
  24. document.schema.registerItem( 'p', '$block' );
  25. // Build converter from model to view for data and editing pipelines.
  26. BuildModelConverterFor( editor.data.modelToView )
  27. .fromElement( 'p' )
  28. .toElement( 'p' );
  29. // Build converter from view to model for data and editing pipelines.
  30. BuildViewConverterFor( editor.data.viewToModel )
  31. .fromElement( 'p' )
  32. .toElement( 'p' );
  33. } );
  34. } );
  35. it( 'should be loaded', () => {
  36. expect( editor.plugins.get( BoldEngine ) ).to.be.instanceOf( BoldEngine );
  37. } );
  38. it( 'should set proper schema rules', () => {
  39. expect( document.schema.check( { name: '$inline', attributes: [ 'bold' ] } ) ).to.be.true;
  40. } );
  41. it( 'should register bold command', () => {
  42. expect( editor.commands.has( 'bold' ) ).to.be.true;
  43. const command = editor.commands.get( 'bold' );
  44. expect( command ).to.be.instanceOf( AttributeCommand );
  45. expect( command.attributeKey ).to.equal( 'bold' );
  46. } );
  47. it( 'should convert <strong> to bold attribute', () => {
  48. editor.setData( '<p><strong>foobar</strong></p>' );
  49. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<p><$text bold=true>foobar</$text></p>' );
  50. expect( editor.getData() ).to.equal( '<p><strong>foobar</strong></p>' );
  51. } );
  52. it( 'should convert <b> to bold attribute', () => {
  53. editor.setData( '<p><b>foobar</b></p>' );
  54. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<p><$text bold=true>foobar</$text></p>' );
  55. expect( editor.getData() ).to.equal( '<p><strong>foobar</strong></p>' );
  56. } );
  57. it( 'should convert font-weight:bold to bold attribute', () => {
  58. editor.setData( '<p><span style="font-weight: bold;">foobar</span></p>' );
  59. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<p><$text bold=true>foobar</$text></p>' );
  60. expect( editor.getData() ).to.equal( '<p><strong>foobar</strong></p>' );
  61. } );
  62. } );