underlineengine.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import UnderlineEngine from '../src/underlineengine';
  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( 'UnderlineEngine', () => {
  12. let editor, model;
  13. beforeEach( () => {
  14. return VirtualTestEditor
  15. .create( {
  16. plugins: [ Paragraph, UnderlineEngine ]
  17. } )
  18. .then( newEditor => {
  19. editor = newEditor;
  20. model = editor.model;
  21. } );
  22. } );
  23. afterEach( () => {
  24. return editor.destroy();
  25. } );
  26. it( 'should be loaded', () => {
  27. expect( editor.plugins.get( UnderlineEngine ) ).to.be.instanceOf( UnderlineEngine );
  28. } );
  29. it( 'should set proper schema rules', () => {
  30. expect( model.schema.checkAttribute( [ '$root', '$block', '$text' ], 'underline' ) ).to.be.true;
  31. expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'underline' ) ).to.be.true;
  32. } );
  33. describe( 'command', () => {
  34. it( 'should register underline command', () => {
  35. const command = editor.commands.get( 'underline' );
  36. expect( command ).to.be.instanceOf( AttributeCommand );
  37. expect( command ).to.have.property( 'attributeKey', 'underline' );
  38. } );
  39. } );
  40. describe( 'data pipeline conversions', () => {
  41. it( 'should convert <u> to underline attribute', () => {
  42. editor.setData( '<p><u>foo</u>bar</p>' );
  43. expect( getModelData( model, { withoutSelection: true } ) )
  44. .to.equal( '<paragraph><$text underline="true">foo</$text>bar</paragraph>' );
  45. expect( editor.getData() ).to.equal( '<p><u>foo</u>bar</p>' );
  46. } );
  47. it( 'should convert text-decoration:underline to underline attribute', () => {
  48. editor.setData( '<p><span style="text-decoration: underline;">foo</span>bar</p>' );
  49. expect( getModelData( model, { withoutSelection: true } ) )
  50. .to.equal( '<paragraph><$text underline="true">foo</$text>bar</paragraph>' );
  51. expect( editor.getData() ).to.equal( '<p><u>foo</u>bar</p>' );
  52. } );
  53. it( 'should be integrated with autoparagraphing', () => {
  54. editor.setData( '<u>foo</u>bar' );
  55. expect( getModelData( model, { withoutSelection: true } ) )
  56. .to.equal( '<paragraph><$text underline="true">foo</$text>bar</paragraph>' );
  57. expect( editor.getData() ).to.equal( '<p><u>foo</u>bar</p>' );
  58. } );
  59. } );
  60. describe( 'editing pipeline conversion', () => {
  61. it( 'should convert attribute', () => {
  62. setModelData( model, '<paragraph><$text underline="true">foo</$text>bar</paragraph>' );
  63. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p><u>foo</u>bar</p>' );
  64. } );
  65. } );
  66. } );