Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #90 from ckeditor/t/89
Browse files Browse the repository at this point in the history
Other: Aligned the use of the `Widget` plugin by the `Image`. Closes #89.
  • Loading branch information
Reinmar authored Apr 3, 2017
2 parents 016b68e + cfa3a4d commit 16f285d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 72 deletions.
8 changes: 0 additions & 8 deletions src/image/imageengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
import WidgetEngine from '@ckeditor/ckeditor5-widget/src/widgetengine';
import { viewToModelImage, createImageAttributeConverter } from './converters';
import { toImageWidget } from './utils';
import ViewContainerElement from '@ckeditor/ckeditor5-engine/src/view/containerelement';
Expand All @@ -23,13 +22,6 @@ import ViewEmptyElement from '@ckeditor/ckeditor5-engine/src/view/emptyelement';
* @extends module:core/plugin~Plugin
*/
export default class ImageEngine extends Plugin {
/**
* @inheritDoc
*/
static get requires() {
return [ WidgetEngine ];
}

/**
* @inheritDoc
*/
Expand Down
65 changes: 64 additions & 1 deletion tests/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -23,6 +26,8 @@ describe( 'Image', () => {
} )
.then( newEditor => {
editor = newEditor;
document = editor.document;
viewDocument = editor.editing.view;
} );
} );

Expand All @@ -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>]'
);
} );
} );
} );
59 changes: 0 additions & 59 deletions tests/image/imageengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils
import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
import { isImageWidget } from '../../src/image/utils';
import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';

describe( 'ImageEngine', () => {
let editor, document, viewDocument;
Expand Down Expand Up @@ -208,62 +207,4 @@ describe( 'ImageEngine', () => {
} );
} );
} );

describe( 'selection conversion', () => {
it( 'should convert 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>]'
);
} );
} );
} );
8 changes: 4 additions & 4 deletions tests/imagecaption/imagecaptionengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ describe( 'ImageCaptionEngine', () => {
setModelData( document, '[<image src=""><caption></caption></image>]' );

expect( getViewData( viewDocument ) ).to.equal(
'[<figure class="image ck-widget ck-widget_selected" contenteditable="false">' +
'[<figure class="image ck-widget" contenteditable="false">' +
'<img src=""></img>' +
'<figcaption class="ck-placeholder ck-editable" contenteditable="true" data-placeholder="Enter image caption">' +
'</figcaption>' +
Expand All @@ -322,7 +322,7 @@ describe( 'ImageCaptionEngine', () => {
setModelData( document, '[<image src=""><caption>foo bar</caption></image>]' );

expect( getViewData( viewDocument ) ).to.equal(
'[<figure class="image ck-widget ck-widget_selected" contenteditable="false">' +
'[<figure class="image ck-widget" contenteditable="false">' +
'<img src=""></img>' +
'<figcaption class="ck-editable" contenteditable="true" data-placeholder="Enter image caption">foo bar</figcaption>' +
'</figure>]'
Expand Down Expand Up @@ -372,7 +372,7 @@ describe( 'ImageCaptionEngine', () => {
} );

expect( getViewData( viewDocument ) ).to.equal(
'[<figure class="image ck-widget ck-widget_selected" contenteditable="false">' +
'[<figure class="image ck-widget" contenteditable="false">' +
'<img src=""></img>' +
'<figcaption class="ck-editable ck-placeholder" contenteditable="true" data-placeholder="Enter image caption"></figcaption>' +
'</figure>]'
Expand All @@ -392,7 +392,7 @@ describe( 'ImageCaptionEngine', () => {
'<img src=""></img>' +
'<figcaption class="ck-editable" contenteditable="true" data-placeholder="Enter image caption">foo bar</figcaption>' +
'</figure>' +
'[<figure class="image ck-widget ck-widget_selected" contenteditable="false">' +
'[<figure class="image ck-widget" contenteditable="false">' +
'<img src=""></img>' +
'<figcaption class="ck-placeholder ck-editable" contenteditable="true" data-placeholder="Enter image caption"></figcaption>' +
'</figure>]'
Expand Down

0 comments on commit 16f285d

Please sign in to comment.