From cfa3a4d3827bcd7789d658b4fb10ca8aff755d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kup=C5=9B?= Date: Mon, 3 Apr 2017 10:41:17 +0200 Subject: [PATCH] Stop using WidgetEngine as its merged into Widget. --- src/image/imageengine.js | 8 --- tests/image.js | 65 +++++++++++++++++++++++- tests/image/imageengine.js | 59 --------------------- tests/imagecaption/imagecaptionengine.js | 8 +-- 4 files changed, 68 insertions(+), 72 deletions(-) diff --git a/src/image/imageengine.js b/src/image/imageengine.js index 00c23b2a..c88b0a01 100644 --- a/src/image/imageengine.js +++ b/src/image/imageengine.js @@ -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'; @@ -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 */ diff --git a/tests/image.js b/tests/image.js index b20c1550..ff5f01e5 100644 --- a/tests/image.js +++ b/tests/image.js @@ -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, '[alt text]' ); + + expect( getViewData( viewDocument ) ).to.equal( + '[
' + + 'alt text' + + '
]' + ); + + 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, '[]' ); + + expect( getViewData( viewDocument ) ).to.equal( + '[
' + + '' + + '
]' + ); + + 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, + '[alt text]' + + 'alt text' + ); + + expect( getViewData( viewDocument ) ).to.equal( + '[
' + + 'alt text' + + '
]' + + '
' + + 'alt text' + + '
' + ); + + document.enqueueChanges( () => { + const secondImage = document.getRoot().getChild( 1 ); + document.selection.setRanges( [ ModelRange.createOn( secondImage ) ] ); + } ); + + expect( getViewData( viewDocument ) ).to.equal( + '
' + + 'alt text' + + '
' + + '[
' + + 'alt text' + + '
]' + ); + } ); + } ); } ); diff --git a/tests/image/imageengine.js b/tests/image/imageengine.js index ebb9d2e4..745b8fa6 100644 --- a/tests/image/imageengine.js +++ b/tests/image/imageengine.js @@ -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; @@ -208,62 +207,4 @@ describe( 'ImageEngine', () => { } ); } ); } ); - - describe( 'selection conversion', () => { - it( 'should convert selection', () => { - setModelData( document, '[alt text]' ); - - expect( getViewData( viewDocument ) ).to.equal( - '[
' + - 'alt text' + - '
]' - ); - - 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, '[]' ); - - expect( getViewData( viewDocument ) ).to.equal( - '[
' + - '' + - '
]' - ); - - 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, - '[alt text]' + - 'alt text' - ); - - expect( getViewData( viewDocument ) ).to.equal( - '[
' + - 'alt text' + - '
]' + - '
' + - 'alt text' + - '
' - ); - - document.enqueueChanges( () => { - const secondImage = document.getRoot().getChild( 1 ); - document.selection.setRanges( [ ModelRange.createOn( secondImage ) ] ); - } ); - - expect( getViewData( viewDocument ) ).to.equal( - '
' + - 'alt text' + - '
' + - '[
' + - 'alt text' + - '
]' - ); - } ); - } ); } ); diff --git a/tests/imagecaption/imagecaptionengine.js b/tests/imagecaption/imagecaptionengine.js index ba807845..0b6d3c46 100644 --- a/tests/imagecaption/imagecaptionengine.js +++ b/tests/imagecaption/imagecaptionengine.js @@ -298,7 +298,7 @@ describe( 'ImageCaptionEngine', () => { setModelData( document, '[]' ); expect( getViewData( viewDocument ) ).to.equal( - '[
' + + '[
' + '' + '
' + '
' + @@ -322,7 +322,7 @@ describe( 'ImageCaptionEngine', () => { setModelData( document, '[foo bar]' ); expect( getViewData( viewDocument ) ).to.equal( - '[
' + + '[
' + '' + '
foo bar
' + '
]' @@ -372,7 +372,7 @@ describe( 'ImageCaptionEngine', () => { } ); expect( getViewData( viewDocument ) ).to.equal( - '[
' + + '[
' + '' + '
' + '
]' @@ -392,7 +392,7 @@ describe( 'ImageCaptionEngine', () => { '' + '
foo bar
' + '
' + - '[
' + + '[
' + '' + '
' + '
]'