8
0

boldengine.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import BoldEngine from '../src/boldengine';
  6. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  7. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  8. import AttributeCommand from '../src/attributecommand';
  9. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  10. import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  11. describe( 'BoldEngine', () => {
  12. let editor, doc;
  13. beforeEach( () => {
  14. return VirtualTestEditor.create( {
  15. plugins: [ Paragraph, BoldEngine ]
  16. } )
  17. .then( newEditor => {
  18. editor = newEditor;
  19. doc = editor.document;
  20. } );
  21. } );
  22. it( 'should be loaded', () => {
  23. expect( editor.plugins.get( BoldEngine ) ).to.be.instanceOf( BoldEngine );
  24. } );
  25. it( 'should set proper schema rules', () => {
  26. expect( doc.schema.check( { name: '$inline', attributes: [ 'bold' ], inside: '$root' } ) ).to.be.false;
  27. expect( doc.schema.check( { name: '$inline', attributes: [ 'bold' ], inside: '$block' } ) ).to.be.true;
  28. expect( doc.schema.check( { name: '$inline', attributes: [ 'bold' ], inside: '$clipboardHolder' } ) ).to.be.true;
  29. } );
  30. describe( 'command', () => {
  31. it( 'should register bold command', () => {
  32. const command = editor.commands.get( 'bold' );
  33. expect( command ).to.be.instanceOf( AttributeCommand );
  34. expect( command ).to.have.property( 'attributeKey', 'bold' );
  35. } );
  36. } );
  37. describe( 'data pipeline conversions', () => {
  38. it( 'should convert <strong> to bold attribute', () => {
  39. editor.setData( '<p><strong>foo</strong>bar</p>' );
  40. expect( getModelData( doc, { withoutSelection: true } ) )
  41. .to.equal( '<paragraph><$text bold="true">foo</$text>bar</paragraph>' );
  42. expect( editor.getData() ).to.equal( '<p><strong>foo</strong>bar</p>' );
  43. } );
  44. it( 'should convert <b> to bold attribute', () => {
  45. editor.setData( '<p><b>foo</b>bar</p>' );
  46. expect( getModelData( doc, { withoutSelection: true } ) )
  47. .to.equal( '<paragraph><$text bold="true">foo</$text>bar</paragraph>' );
  48. expect( editor.getData() ).to.equal( '<p><strong>foo</strong>bar</p>' );
  49. } );
  50. it( 'should convert font-weight:bold to bold attribute', () => {
  51. editor.setData( '<p><span style="font-weight: bold;">foo</span>bar</p>' );
  52. expect( getModelData( doc, { withoutSelection: true } ) )
  53. .to.equal( '<paragraph><$text bold="true">foo</$text>bar</paragraph>' );
  54. expect( editor.getData() ).to.equal( '<p><strong>foo</strong>bar</p>' );
  55. } );
  56. it( 'should be integrated with autoparagraphing', () => {
  57. // Incorrect results because autoparagraphing works incorrectly (issue in paragraph).
  58. // https://github.com/ckeditor/ckeditor5-paragraph/issues/10
  59. editor.setData( '<strong>foo</strong>bar' );
  60. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
  61. expect( editor.getData() ).to.equal( '<p>foobar</p>' );
  62. } );
  63. } );
  64. describe( 'editing pipeline conversion', () => {
  65. it( 'should convert attribute', () => {
  66. setModelData( doc, '<paragraph><$text bold="true">foo</$text>bar</paragraph>' );
  67. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p><strong>foo</strong>bar</p>' );
  68. } );
  69. } );
  70. } );