8
0
Pārlūkot izejas kodu

Tests: added missing tests.

Szymon Cofalik 9 gadi atpakaļ
vecāks
revīzija
70c9b77978

+ 8 - 0
packages/ckeditor5-engine/tests/tickets/401/1.html

@@ -0,0 +1,8 @@
+<head>
+	<meta charset="utf-8">
+	<link rel="stylesheet" href="%APPS_DIR%ckeditor/build/modules/amd/theme/ckeditor.css">
+</head>
+
+<div id="editor">
+	<p>Lorem <strong>ipsum</strong> dol &nbsp; &nbsp;or<strong> sit </strong>amet.</p>
+</div>

+ 14 - 0
packages/ckeditor5-engine/tests/tickets/401/1.js

@@ -0,0 +1,14 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals document */
+
+import ClassicEditor from '/ckeditor5/editor-classic/classic.js';
+import Bold from '/ckeditor5/basic-styles/bold.js';
+
+ClassicEditor.create( document.getElementById( 'editor' ), {
+	features: [ 'enter', 'typing', 'paragraph', Bold ],
+	toolbar: [ 'bold' ]
+} );

+ 16 - 0
packages/ckeditor5-engine/tests/tickets/401/1.md

@@ -0,0 +1,16 @@
+@bender-ui: collapsed
+@bender-tags: ticket, 401, 0.4.0, iteration4
+
+### Selection direction manual test [#401](https://github.com/ckeditor/ckeditor5-engine/issues/401)
+
+1. Click somewhere in word "amet".
+2. Drag slowly to the beginning of text, selecting all other words.
+
+Expected result: selection from "Lorem" to "amet" is made.
+Unexpected result: selection got broken or is incorrect.
+
+1. Focus somewhere in word "amet".
+2. Using <kbd>left arrow</kbd> and <kbd>shift</kbd> expand selection to the beginning of the text.
+
+Expected result: selection from "Lorem" to "amet" is made.
+Unexpected result: selection got broken or is incorrect.

+ 29 - 2
packages/ckeditor5-engine/tests/view/domconverter/dom-to-view.js

@@ -570,7 +570,7 @@ describe( 'DomConverter', () => {
 	} );
 
 	describe( 'domSelectionToView', () => {
-		it( 'should converter selection', () => {
+		it( 'should convert selection', () => {
 			const domFoo = document.createTextNode( 'foo' );
 			const domBar = document.createTextNode( 'bar' );
 			const domB = createElement( document, 'b', null, domBar );
@@ -597,7 +597,7 @@ describe( 'DomConverter', () => {
 			expect( stringify( viewP, viewSelection.getFirstRange() ) ).to.equal( '<p>f{oo<b>ba}r</b></p>' );
 		} );
 
-		it( 'should converter empty selection to empty selection', () => {
+		it( 'should convert empty selection to empty selection', () => {
 			const domSelection = document.getSelection();
 			domSelection.removeAllRanges();
 
@@ -606,6 +606,33 @@ describe( 'DomConverter', () => {
 			expect( viewSelection.rangeCount ).to.equal( 0 );
 		} );
 
+		it( 'should handle selection direction', () => {
+			const domFoo = document.createTextNode( 'foo' );
+			const domP = createElement( document, 'p', null, [ domFoo ] );
+
+			const viewP = parse( '<p>foo</p>' );
+
+			converter.bindElements( domP, viewP );
+
+			document.body.appendChild( domP );
+
+			const domRange = new Range();
+			domRange.setStart( domFoo, 2 );
+			domRange.collapse( true );
+
+			const domSelection = document.getSelection();
+			domSelection.removeAllRanges();
+			domSelection.addRange( domRange );
+			domSelection.extend( domFoo, 1 );
+
+			const viewSelection = converter.domSelectionToView( domSelection );
+
+			expect( viewSelection.rangeCount ).to.equal( 1 );
+			expect( viewSelection.anchor.offset ).to.equal( 2 );
+			expect( viewSelection.focus.offset ).to.equal( 1 );
+			expect( viewSelection.isBackward ).to.be.true;
+		} );
+
 		it( 'should not add null ranges', () => {
 			const domFoo = document.createTextNode( 'foo' );
 			const domBar = document.createTextNode( 'bar' );