|
|
@@ -3,21 +3,26 @@
|
|
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
|
*/
|
|
|
|
|
|
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
+
|
|
|
import testUtils from './_utils/utils';
|
|
|
import VirtualTestEditor from './_utils/virtualtesteditor';
|
|
|
+import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
|
|
|
+import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
|
|
|
import RestrictedDocument from './../src/restricteddocument';
|
|
|
|
|
|
describe( 'RestrictedDocument', () => {
|
|
|
- let editor;
|
|
|
+ let editor, model;
|
|
|
|
|
|
testUtils.createSinonSandbox();
|
|
|
|
|
|
beforeEach( () => {
|
|
|
return VirtualTestEditor
|
|
|
- .create( { plugins: [ RestrictedDocument ] } )
|
|
|
+ .create( { plugins: [ Paragraph, RestrictedDocument ] } )
|
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
|
+ model = editor.model;
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
@@ -36,8 +41,6 @@ describe( 'RestrictedDocument', () => {
|
|
|
} );
|
|
|
|
|
|
it( 'should set proper schema rules', () => {
|
|
|
- const model = editor.model;
|
|
|
-
|
|
|
expect( model.schema.checkAttribute( [ '$root', '$text' ], 'nonRestricted' ) ).to.be.true;
|
|
|
|
|
|
expect( model.schema.checkAttribute( [ '$block', '$text' ], 'nonRestricted' ) ).to.be.true;
|
|
|
@@ -45,4 +48,28 @@ describe( 'RestrictedDocument', () => {
|
|
|
|
|
|
expect( model.schema.checkAttribute( [ '$block' ], 'nonRestricted' ) ).to.be.false;
|
|
|
} );
|
|
|
+
|
|
|
+ describe( 'conversion', () => {
|
|
|
+ describe( 'upcast', () => {
|
|
|
+ it( 'should convert <span class="ck-non-restricted"> to model attribute', () => {
|
|
|
+ editor.setData( '<p>foo <span class="ck-non-restricted">bar</span> baz</p>' );
|
|
|
+
|
|
|
+ expect( getModelData( model, { withoutSelection: true } ) )
|
|
|
+ .to.equal( '<paragraph>foo <$text nonRestricted="true">bar</$text> baz</paragraph>' );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( 'downcast', () => {
|
|
|
+ it( 'should convert model attribute to <span>', () => {
|
|
|
+ const expectedView = '<p>foo <span class="ck-non-restricted">bar</span> baz</p>';
|
|
|
+
|
|
|
+ setModelData( editor.model,
|
|
|
+ '<paragraph>foo <$text nonRestricted="true">bar</$text> baz</paragraph>'
|
|
|
+ );
|
|
|
+
|
|
|
+ expect( editor.getData() ).to.equal( expectedView );
|
|
|
+ expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
} );
|