strikeengine.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Rémy Hubscher. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import StrikeEngine from '../src/strikeengine';
  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( 'StrikeEngine', () => {
  12. let editor, doc;
  13. beforeEach( () => {
  14. return VirtualTestEditor
  15. .create( {
  16. plugins: [ Paragraph, StrikeEngine ]
  17. } )
  18. .then( newEditor => {
  19. editor = newEditor;
  20. doc = editor.document;
  21. } );
  22. } );
  23. afterEach( () => {
  24. return editor.destroy();
  25. } );
  26. it( 'should be loaded', () => {
  27. expect( editor.plugins.get( StrikeEngine ) ).to.be.instanceOf( StrikeEngine );
  28. } );
  29. it( 'should set proper schema rules', () => {
  30. expect( doc.schema.check( { name: '$inline', attributes: 'strike', inside: '$root' } ) ).to.be.false;
  31. expect( doc.schema.check( { name: '$inline', attributes: 'strike', inside: '$block' } ) ).to.be.true;
  32. expect( doc.schema.check( { name: '$inline', attributes: 'strike', inside: '$clipboardHolder' } ) ).to.be.true;
  33. } );
  34. describe( 'command', () => {
  35. it( 'should register strike command', () => {
  36. const command = editor.commands.get( 'strike' );
  37. expect( command ).to.be.instanceOf( AttributeCommand );
  38. expect( command ).to.have.property( 'attributeKey', 'strike' );
  39. } );
  40. } );
  41. describe( 'data pipeline conversions', () => {
  42. it( 'should convert <strike> to strike attribute', () => {
  43. editor.setData( '<p><strike>foo</strike>bar</p>' );
  44. expect( getModelData( doc, { withoutSelection: true } ) )
  45. .to.equal( '<paragraph><$text strike="true">foo</$text>bar</paragraph>' );
  46. expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
  47. } );
  48. it( 'should convert <del> to strike attribute', () => {
  49. editor.setData( '<p><del>foo</del>bar</p>' );
  50. expect( getModelData( doc, { withoutSelection: true } ) )
  51. .to.equal( '<paragraph><$text strike="true">foo</$text>bar</paragraph>' );
  52. expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
  53. } );
  54. it( 'should convert <s> to strike attribute', () => {
  55. editor.setData( '<p><s>foo</s>bar</p>' );
  56. expect( getModelData( doc, { withoutSelection: true } ) )
  57. .to.equal( '<paragraph><$text strike="true">foo</$text>bar</paragraph>' );
  58. expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
  59. } );
  60. it( 'should convert text-decoration:line-through to strike attribute', () => {
  61. editor.setData( '<p><span style="text-decoration: line-through;">foo</span>bar</p>' );
  62. expect( getModelData( doc, { withoutSelection: true } ) )
  63. .to.equal( '<paragraph><$text strike="true">foo</$text>bar</paragraph>' );
  64. expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
  65. } );
  66. it( 'should be integrated with autoparagraphing', () => {
  67. // Incorrect results because autoparagraphing works incorrectly (issue in paragraph).
  68. // https://github.com/ckeditor/ckeditor5-paragraph/issues/10
  69. editor.setData( '<s>foo</s>bar' );
  70. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
  71. expect( editor.getData() ).to.equal( '<p>foobar</p>' );
  72. } );
  73. } );
  74. describe( 'editing pipeline conversion', () => {
  75. it( 'should convert attribute', () => {
  76. setModelData( doc, '<paragraph><$text strike="true">foo</$text>bar</paragraph>' );
  77. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p><s>foo</s>bar</p>' );
  78. } );
  79. } );
  80. } );