Ver Fonte

Tests: Add some integration tests and remove skipped.

Maciej Gołaszewski há 8 anos atrás
pai
commit
75bb1306ba

+ 19 - 0
packages/ckeditor5-highlight/tests/highlightcommand.js

@@ -71,6 +71,25 @@ describe( 'HighlightCommand', () => {
 			expect( getData( doc ) ).to.equal( '<paragraph>a[<$text highlight="marker">bcfo]obar</$text>xyz</paragraph>' );
 		} );
 
+		it( 'should add highlight attribute on selected nodes nodes when passed as parameter (multiple nodes)', () => {
+			setData(
+				doc,
+				'<paragraph>abcabc[abc</paragraph>' +
+				'<paragraph>foofoofoo</paragraph>' +
+				'<paragraph>barbar]bar</paragraph>'
+			);
+
+			command.execute( { class: 'marker' } );
+
+			expect( command.value ).to.equal( 'marker' );
+
+			expect( getData( doc ) ).to.equal(
+				'<paragraph>abcabc[<$text highlight="marker">abc</$text></paragraph>' +
+				'<paragraph><$text highlight="marker">foofoofoo</$text></paragraph>' +
+				'<paragraph><$text highlight="marker">barbar</$text>]bar</paragraph>'
+			);
+		} );
+
 		it( 'should set highlight attribute on selected nodes when passed as parameter', () => {
 			setData( doc, '<paragraph>abc[<$text highlight="marker">foo]bar</$text>xyz</paragraph>' );
 

+ 0 - 22
packages/ckeditor5-highlight/tests/highlightediting.js

@@ -34,28 +34,6 @@ describe( 'HighlightEditing', () => {
 		expect( editor.commands.get( 'highlight' ) ).to.be.instanceOf( HighlightCommand );
 	} );
 
-	it.skip( 'allows for highlight in $blocks', () => {
-		expect( doc.schema.check( { name: '$text', inside: '$root', attributes: 'highlight' } ) ).to.be.true;
-	} );
-
-	describe.skip( 'integration', () => {
-		beforeEach( () => {
-			return VirtualTestEditor
-				.create( {
-					plugins: [ HighlightEditing, Paragraph ]
-				} )
-				.then( newEditor => {
-					editor = newEditor;
-
-					doc = editor.document;
-				} );
-		} );
-
-		it( 'is allowed inside paragraph', () => {
-			expect( doc.schema.check( { name: 'paragraph', attributes: 'highlight' } ) ).to.be.true;
-		} );
-	} );
-
 	describe( 'data pipeline conversions', () => {
 		it( 'should convert defined marker classes', () => {
 			const data = '<p>f<mark class="marker">o</mark>o</p>';

+ 69 - 0
packages/ckeditor5-highlight/tests/integration.js

@@ -0,0 +1,69 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global document */
+
+import Highlight from '../src/highlight';
+import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+import Heading from '@ckeditor/ckeditor5-heading/src/heading';
+import Image from '@ckeditor/ckeditor5-image/src/image';
+import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
+import List from '@ckeditor/ckeditor5-list/src/list';
+import Enter from '@ckeditor/ckeditor5-enter/src/enter';
+import Delete from '@ckeditor/ckeditor5-typing/src/delete';
+
+import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
+import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+
+describe( 'Highlight', () => {
+	let editor, doc, element;
+
+	beforeEach( () => {
+		element = document.createElement( 'div' );
+		document.body.appendChild( element );
+
+		return ClassicTestEditor
+			.create( element, {
+				plugins: [ Highlight, BlockQuote, Paragraph, Heading, Image, ImageCaption, List, Enter, Delete ]
+			} )
+			.then( newEditor => {
+				editor = newEditor;
+				doc = editor.document;
+			} );
+	} );
+
+	afterEach( () => {
+		element.remove();
+
+		return editor.destroy();
+	} );
+
+	describe( 'compatibility with images', () => {
+		it( 'does not work inside image caption', () => {
+			setModelData( doc, '<image src="foo.png"><caption>foo[bar]baz</caption></image>' );
+
+			editor.execute( 'highlight', { class: 'marker' } );
+
+			expect( getModelData( doc ) )
+				.to.equal( '<image src="foo.png"><caption>foo[<$text highlight="marker">bar</$text>]baz</caption></image>' );
+		} );
+
+		it( 'does not work on selection with image', () => {
+			setModelData(
+				doc,
+				'<paragraph>foo[foo</paragraph><image src="foo.png"><caption>abc</caption></image><paragraph>bar]bar</paragraph>'
+			);
+
+			editor.execute( 'highlight', { class: 'marker' } );
+
+			expect( getModelData( doc ) ).to.equal(
+				'<paragraph>foo[<$text highlight="marker">foo</$text></paragraph>' +
+				'<image src="foo.png"><caption><$text highlight="marker">abc</$text></caption></image>' +
+				'<paragraph><$text highlight="marker">bar</$text>]bar</paragraph>'
+			);
+		} );
+	} );
+} );