8
0

superscriptediting.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import SuperEditing from '../../src/superscript/superscriptediting';
  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( 'SuperEditing', () => {
  12. let editor, model;
  13. beforeEach( () => {
  14. return VirtualTestEditor
  15. .create( {
  16. plugins: [ Paragraph, SuperEditing ]
  17. } )
  18. .then( newEditor => {
  19. editor = newEditor;
  20. model = editor.model;
  21. } );
  22. } );
  23. afterEach( () => {
  24. return editor.destroy();
  25. } );
  26. it( 'should have pluginName', () => {
  27. expect( SuperEditing.pluginName ).to.equal( 'SuperscriptEditing' );
  28. } );
  29. it( 'should be loaded', () => {
  30. expect( editor.plugins.get( SuperEditing ) ).to.be.instanceOf( SuperEditing );
  31. } );
  32. it( 'should set proper schema rules', () => {
  33. expect( model.schema.checkAttribute( [ '$root', '$block', '$text' ], 'superscript' ) ).to.be.true;
  34. expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'superscript' ) ).to.be.true;
  35. } );
  36. it( 'should be marked with a formatting property', () => {
  37. expect( model.schema.getAttributeProperties( 'superscript' ) ).to.include( {
  38. isFormatting: true
  39. } );
  40. } );
  41. it( 'its attribute is marked with a copOnEnter property', () => {
  42. expect( model.schema.getAttributeProperties( 'superscript' ) ).to.include( {
  43. copyOnEnter: true
  44. } );
  45. } );
  46. describe( 'command', () => {
  47. it( 'should register superscript command', () => {
  48. const command = editor.commands.get( 'superscript' );
  49. expect( command ).to.be.instanceOf( AttributeCommand );
  50. expect( command ).to.have.property( 'attributeKey', 'superscript' );
  51. } );
  52. } );
  53. describe( 'data pipeline conversions', () => {
  54. it( 'should convert <sup> to superscript attribute', () => {
  55. editor.setData( '<p><sup>foo</sup>bar</p>' );
  56. expect( getModelData( model, { withoutSelection: true } ) )
  57. .to.equal( '<paragraph><$text superscript="true">foo</$text>bar</paragraph>' );
  58. expect( editor.getData() ).to.equal( '<p><sup>foo</sup>bar</p>' );
  59. } );
  60. it( 'should convert vertical-align:super to super attribute', () => {
  61. editor.setData( '<p><span style="vertical-align: super;">foo</span>bar</p>' );
  62. expect( getModelData( model, { withoutSelection: true } ) )
  63. .to.equal( '<paragraph><$text superscript="true">foo</$text>bar</paragraph>' );
  64. expect( editor.getData() ).to.equal( '<p><sup>foo</sup>bar</p>' );
  65. } );
  66. it( 'should be integrated with autoparagraphing', () => {
  67. editor.setData( '<sup>foo</sup>bar' );
  68. expect( getModelData( model, { withoutSelection: true } ) )
  69. .to.equal( '<paragraph><$text superscript="true">foo</$text>bar</paragraph>' );
  70. expect( editor.getData() ).to.equal( '<p><sup>foo</sup>bar</p>' );
  71. } );
  72. } );
  73. describe( 'editing pipeline conversion', () => {
  74. it( 'should convert attribute', () => {
  75. setModelData( model, '<paragraph><$text superscript="true">foo</$text>bar</paragraph>' );
  76. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p><sup>foo</sup>bar</p>' );
  77. } );
  78. } );
  79. } );