strikethroughengine.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import StrikethroughEngine from '../src/strikethroughengine';
  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( 'StrikethroughEngine', () => {
  12. let editor, model;
  13. beforeEach( () => {
  14. return VirtualTestEditor
  15. .create( {
  16. plugins: [ Paragraph, StrikethroughEngine ]
  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( StrikethroughEngine ) ).to.be.instanceOf( StrikethroughEngine );
  28. } );
  29. it( 'should set proper schema rules', () => {
  30. expect( model.schema.checkAttribute( [ '$root', '$block', '$text' ], 'strikethrough' ) ).to.be.true;
  31. expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'strikethrough' ) ).to.be.true;
  32. } );
  33. describe( 'command', () => {
  34. it( 'should register strikethrough command', () => {
  35. const command = editor.commands.get( 'strikethrough' );
  36. expect( command ).to.be.instanceOf( AttributeCommand );
  37. expect( command ).to.have.property( 'attributeKey', 'strikethrough' );
  38. } );
  39. } );
  40. describe( 'data pipeline conversions', () => {
  41. it( 'should convert <strike> to strikethrough attribute', () => {
  42. editor.setData( '<p><strike>foo</strike>bar</p>' );
  43. expect( getModelData( model, { withoutSelection: true } ) )
  44. .to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' );
  45. expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
  46. } );
  47. it( 'should convert <del> to strikethrough attribute', () => {
  48. editor.setData( '<p><del>foo</del>bar</p>' );
  49. expect( getModelData( model, { withoutSelection: true } ) )
  50. .to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' );
  51. expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
  52. } );
  53. it( 'should convert <s> to strikethrough attribute', () => {
  54. editor.setData( '<p><s>foo</s>bar</p>' );
  55. expect( getModelData( model, { withoutSelection: true } ) )
  56. .to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' );
  57. expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
  58. } );
  59. it( 'should convert text-decoration:line-through to strikethrough attribute', () => {
  60. editor.setData( '<p><span style="text-decoration: line-through;">foo</span>bar</p>' );
  61. expect( getModelData( model, { withoutSelection: true } ) )
  62. .to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' );
  63. expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
  64. } );
  65. it( 'should be integrated with autoparagraphing', () => {
  66. editor.setData( '<s>foo</s>bar' );
  67. expect( getModelData( model, { withoutSelection: true } ) )
  68. .to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' );
  69. expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
  70. } );
  71. } );
  72. describe( 'editing pipeline conversion', () => {
  73. it( 'should convert attribute', () => {
  74. setModelData( model, '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' );
  75. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p><s>foo</s>bar</p>' );
  76. } );
  77. } );
  78. } );