|
| 1 | +/** |
| 2 | + * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. |
| 3 | + * For licensing, see LICENSE.md. |
| 4 | + */ |
| 5 | + |
| 6 | +import StrikethroughEngine from '../src/strikethroughengine'; |
| 7 | + |
| 8 | +import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor'; |
| 9 | +import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; |
| 10 | +import AttributeCommand from '../src/attributecommand'; |
| 11 | + |
| 12 | +import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model'; |
| 13 | +import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view'; |
| 14 | + |
| 15 | +describe( 'StrikethroughEngine', () => { |
| 16 | + let editor, doc; |
| 17 | + |
| 18 | + beforeEach( () => { |
| 19 | + return VirtualTestEditor |
| 20 | + .create( { |
| 21 | + plugins: [ Paragraph, StrikethroughEngine ] |
| 22 | + } ) |
| 23 | + .then( newEditor => { |
| 24 | + editor = newEditor; |
| 25 | + |
| 26 | + doc = editor.document; |
| 27 | + } ); |
| 28 | + } ); |
| 29 | + |
| 30 | + afterEach( () => { |
| 31 | + return editor.destroy(); |
| 32 | + } ); |
| 33 | + |
| 34 | + it( 'should be loaded', () => { |
| 35 | + expect( editor.plugins.get( StrikethroughEngine ) ).to.be.instanceOf( StrikethroughEngine ); |
| 36 | + } ); |
| 37 | + |
| 38 | + it( 'should set proper schema rules', () => { |
| 39 | + expect( doc.schema.check( { name: '$inline', attributes: 'strikethrough', inside: '$root' } ) ).to.be.false; |
| 40 | + expect( doc.schema.check( { name: '$inline', attributes: 'strikethrough', inside: '$block' } ) ).to.be.true; |
| 41 | + expect( doc.schema.check( { name: '$inline', attributes: 'strikethrough', inside: '$clipboardHolder' } ) ).to.be.true; |
| 42 | + } ); |
| 43 | + |
| 44 | + describe( 'command', () => { |
| 45 | + it( 'should register strikethrough command', () => { |
| 46 | + const command = editor.commands.get( 'strikethrough' ); |
| 47 | + |
| 48 | + expect( command ).to.be.instanceOf( AttributeCommand ); |
| 49 | + expect( command ).to.have.property( 'attributeKey', 'strikethrough' ); |
| 50 | + } ); |
| 51 | + } ); |
| 52 | + |
| 53 | + describe( 'data pipeline conversions', () => { |
| 54 | + it( 'should convert <strike> to strikethrough attribute', () => { |
| 55 | + editor.setData( '<p><strike>foo</strike>bar</p>' ); |
| 56 | + |
| 57 | + expect( getModelData( doc, { withoutSelection: true } ) ) |
| 58 | + .to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' ); |
| 59 | + |
| 60 | + expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' ); |
| 61 | + } ); |
| 62 | + it( 'should convert <del> to strikethrough attribute', () => { |
| 63 | + editor.setData( '<p><del>foo</del>bar</p>' ); |
| 64 | + |
| 65 | + expect( getModelData( doc, { withoutSelection: true } ) ) |
| 66 | + .to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' ); |
| 67 | + |
| 68 | + expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' ); |
| 69 | + } ); |
| 70 | + |
| 71 | + it( 'should convert <s> to strikethrough attribute', () => { |
| 72 | + editor.setData( '<p><s>foo</s>bar</p>' ); |
| 73 | + |
| 74 | + expect( getModelData( doc, { withoutSelection: true } ) ) |
| 75 | + .to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' ); |
| 76 | + |
| 77 | + expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' ); |
| 78 | + } ); |
| 79 | + |
| 80 | + it( 'should convert text-decoration:line-through to strikethrough attribute', () => { |
| 81 | + editor.setData( '<p><span style="text-decoration: line-through;">foo</span>bar</p>' ); |
| 82 | + |
| 83 | + expect( getModelData( doc, { withoutSelection: true } ) ) |
| 84 | + .to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' ); |
| 85 | + |
| 86 | + expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' ); |
| 87 | + } ); |
| 88 | + |
| 89 | + it( 'should be integrated with autoparagraphing', () => { |
| 90 | + // Incorrect results because autoparagraphing works incorrectly (issue in paragraph). |
| 91 | + // https://github.com/ckeditor/ckeditor5-paragraph/issues/10 |
| 92 | + |
| 93 | + editor.setData( '<s>foo</s>bar' ); |
| 94 | + |
| 95 | + expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' ); |
| 96 | + |
| 97 | + expect( editor.getData() ).to.equal( '<p>foobar</p>' ); |
| 98 | + } ); |
| 99 | + } ); |
| 100 | + |
| 101 | + describe( 'editing pipeline conversion', () => { |
| 102 | + it( 'should convert attribute', () => { |
| 103 | + setModelData( doc, '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' ); |
| 104 | + |
| 105 | + expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p><s>foo</s>bar</p>' ); |
| 106 | + } ); |
| 107 | + } ); |
| 108 | +} ); |
0 commit comments