|
|
@@ -10,9 +10,12 @@ import Image from '../src/image';
|
|
|
import ImageEngine from '../src/image/imageengine';
|
|
|
import Widget from '@ckeditor/ckeditor5-widget/src/widget';
|
|
|
import ImageTextAlternative from '../src/imagetextalternative';
|
|
|
+import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
+import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
|
|
|
+import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
|
|
|
|
|
|
describe( 'Image', () => {
|
|
|
- let editor;
|
|
|
+ let editor, document, viewDocument;
|
|
|
|
|
|
beforeEach( () => {
|
|
|
const editorElement = window.document.createElement( 'div' );
|
|
|
@@ -23,6 +26,8 @@ describe( 'Image', () => {
|
|
|
} )
|
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
|
+ document = editor.document;
|
|
|
+ viewDocument = editor.editing.view;
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
@@ -41,4 +46,62 @@ describe( 'Image', () => {
|
|
|
it( 'should load ImageTextAlternative plugin', () => {
|
|
|
expect( editor.plugins.get( ImageTextAlternative ) ).to.instanceOf( ImageTextAlternative );
|
|
|
} );
|
|
|
+
|
|
|
+ describe( 'selection', () => {
|
|
|
+ it( 'should create fake selection', () => {
|
|
|
+ setModelData( document, '[<image alt="alt text" src="foo.png"></image>]' );
|
|
|
+
|
|
|
+ expect( getViewData( viewDocument ) ).to.equal(
|
|
|
+ '[<figure class="image ck-widget ck-widget_selected" contenteditable="false">' +
|
|
|
+ '<img alt="alt text" src="foo.png"></img>' +
|
|
|
+ '</figure>]'
|
|
|
+ );
|
|
|
+
|
|
|
+ expect( viewDocument.selection.isFake ).to.be.true;
|
|
|
+ expect( viewDocument.selection.fakeSelectionLabel ).to.equal( 'alt text image widget' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should create proper fake selection label when alt attribute is empty', () => {
|
|
|
+ setModelData( document, '[<image src="foo.png" alt=""></image>]' );
|
|
|
+
|
|
|
+ expect( getViewData( viewDocument ) ).to.equal(
|
|
|
+ '[<figure class="image ck-widget ck-widget_selected" contenteditable="false">' +
|
|
|
+ '<img alt="" src="foo.png"></img>' +
|
|
|
+ '</figure>]'
|
|
|
+ );
|
|
|
+
|
|
|
+ expect( viewDocument.selection.isFake ).to.be.true;
|
|
|
+ expect( viewDocument.selection.fakeSelectionLabel ).to.equal( 'image widget' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should remove selected class from previously selected element', () => {
|
|
|
+ setModelData( document,
|
|
|
+ '[<image src="foo.png" alt="alt text"></image>]' +
|
|
|
+ '<image src="foo.png" alt="alt text"></image>'
|
|
|
+ );
|
|
|
+
|
|
|
+ expect( getViewData( viewDocument ) ).to.equal(
|
|
|
+ '[<figure class="image ck-widget ck-widget_selected" contenteditable="false">' +
|
|
|
+ '<img alt="alt text" src="foo.png"></img>' +
|
|
|
+ '</figure>]' +
|
|
|
+ '<figure class="image ck-widget" contenteditable="false">' +
|
|
|
+ '<img alt="alt text" src="foo.png"></img>' +
|
|
|
+ '</figure>'
|
|
|
+ );
|
|
|
+
|
|
|
+ document.enqueueChanges( () => {
|
|
|
+ const secondImage = document.getRoot().getChild( 1 );
|
|
|
+ document.selection.setRanges( [ ModelRange.createOn( secondImage ) ] );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getViewData( viewDocument ) ).to.equal(
|
|
|
+ '<figure class="image ck-widget" contenteditable="false">' +
|
|
|
+ '<img alt="alt text" src="foo.png"></img>' +
|
|
|
+ '</figure>' +
|
|
|
+ '[<figure class="image ck-widget ck-widget_selected" contenteditable="false">' +
|
|
|
+ '<img alt="alt text" src="foo.png"></img>' +
|
|
|
+ '</figure>]'
|
|
|
+ );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
} );
|