strikethroughediting.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import StrikethroughEditing from '../../src/strikethrough/strikethroughediting';
  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( 'StrikethroughEditing', () => {
  12. let editor, model;
  13. beforeEach( () => {
  14. return VirtualTestEditor
  15. .create( {
  16. plugins: [ Paragraph, StrikethroughEditing ]
  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( StrikethroughEditing ) ).to.be.instanceOf( StrikethroughEditing );
  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. it( 'should be marked with a formatting property', () => {
  34. expect( model.schema.getAttributeProperties( 'strikethrough' ) ).to.include( {
  35. isFormatting: true
  36. } );
  37. } );
  38. it( 'its attribute is marked with a copOnEnter property', () => {
  39. expect( model.schema.getAttributeProperties( 'strikethrough' ) ).to.include( {
  40. copyOnEnter: true
  41. } );
  42. } );
  43. describe( 'command', () => {
  44. it( 'should register strikethrough command', () => {
  45. const command = editor.commands.get( 'strikethrough' );
  46. expect( command ).to.be.instanceOf( AttributeCommand );
  47. expect( command ).to.have.property( 'attributeKey', 'strikethrough' );
  48. } );
  49. } );
  50. describe( 'data pipeline conversions', () => {
  51. it( 'should convert <strike> to strikethrough attribute', () => {
  52. editor.setData( '<p><strike>foo</strike>bar</p>' );
  53. expect( getModelData( model, { withoutSelection: true } ) )
  54. .to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' );
  55. expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
  56. } );
  57. it( 'should convert <del> to strikethrough attribute', () => {
  58. editor.setData( '<p><del>foo</del>bar</p>' );
  59. expect( getModelData( model, { withoutSelection: true } ) )
  60. .to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' );
  61. expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
  62. } );
  63. it( 'should convert <s> to strikethrough attribute', () => {
  64. editor.setData( '<p><s>foo</s>bar</p>' );
  65. expect( getModelData( model, { withoutSelection: true } ) )
  66. .to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' );
  67. expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
  68. } );
  69. it( 'should convert text-decoration:line-through to strikethrough attribute', () => {
  70. editor.setData( '<p><span style="text-decoration: line-through;">foo</span>bar</p>' );
  71. expect( getModelData( model, { withoutSelection: true } ) )
  72. .to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' );
  73. expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
  74. } );
  75. it( 'should be integrated with autoparagraphing', () => {
  76. editor.setData( '<s>foo</s>bar' );
  77. expect( getModelData( model, { withoutSelection: true } ) )
  78. .to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' );
  79. expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
  80. } );
  81. } );
  82. describe( 'editing pipeline conversion', () => {
  83. it( 'should convert attribute', () => {
  84. setModelData( model, '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' );
  85. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p><s>foo</s>bar</p>' );
  86. } );
  87. } );
  88. } );