@@ -24,6 +24,7 @@ import eventsEngine from 'common/core/events/core/events_engine';
2424import ariaAccessibilityTestHelper from '../../../helpers/ariaAccessibilityTestHelper.js' ;
2525
2626const LIST_ITEM_CLASS = 'dx-list-item' ;
27+ const LIST_ITEM_CONTENT_CLASS = 'dx-list-item-content' ;
2728const LIST_ITEMS_CLASS = 'dx-list-items' ;
2829const LIST_GROUP_CLASS = 'dx-list-group' ;
2930const LIST_GROUP_HEADER_CLASS = 'dx-list-group-header' ;
@@ -1139,29 +1140,6 @@ QUnit.module('options changed', moduleSetup, () => {
11391140 swipeItem ( ) ;
11401141 } ) ;
11411142
1142- QUnit . test ( 'onItemSwipe handler should not be triggered if "_swipeEnabled" is false on init' , function ( assert ) {
1143- assert . expect ( 0 ) ;
1144-
1145- const swipeHandler = ( ) => {
1146- assert . ok ( true , 'swipe handled' ) ;
1147- } ;
1148-
1149- this . element . dxList ( {
1150- items : [ 0 ] ,
1151- onItemSwipe : swipeHandler ,
1152- _swipeEnabled : false
1153- } ) . dxList ( 'instance' ) ;
1154-
1155- const item = $ . proxy ( function ( ) {
1156- return this . element . find ( `.${ LIST_ITEM_CLASS } ` ) . eq ( 0 ) ;
1157- } , this ) ;
1158- const swipeItem = ( ) => {
1159- pointerMock ( item ( ) ) . start ( ) . swipeStart ( ) . swipe ( 0.5 ) . swipeEnd ( 1 ) ;
1160- } ;
1161-
1162- swipeItem ( ) ;
1163- } ) ;
1164-
11651143 QUnit . test ( 'onItemSwipe - subscription by on method' , function ( assert ) {
11661144 assert . expect ( 2 ) ;
11671145
@@ -1188,7 +1166,7 @@ QUnit.module('options changed', moduleSetup, () => {
11881166 list . off ( 'itemSwipe' ) ;
11891167 swipeItem ( ) ;
11901168
1191- list . on ( 'itemSwipe' , swipeHandler ) ;
1169+ list . on ( { 'itemSwipe' : swipeHandler } ) ;
11921170 swipeItem ( ) ;
11931171 } ) ;
11941172
@@ -4792,6 +4770,94 @@ QUnit.module('Search', () => {
47924770 } ) ;
47934771} ) ;
47944772
4773+ QUnit . module ( 'Highlighting/selecting' , { ...moduleSetup , afterEach : function ( ) {
4774+ moduleSetup . afterEach . call ( this ) ;
4775+ window . getSelection ( ) . removeAllRanges ( ) ;
4776+ } } , ( ) => {
4777+
4778+ const selectTextNodePart = ( textNode , startOffset , endOffset ) => {
4779+ const selection = window . getSelection ( ) ;
4780+ const range = document . createRange ( ) ;
4781+ selection . removeAllRanges ( ) ;
4782+ range . setStart ( textNode , startOffset ) ;
4783+ range . setEnd ( textNode , endOffset ) ;
4784+ selection . addRange ( range ) ;
4785+ return selection ;
4786+ } ;
4787+
4788+ const getFirstListItemAndTextNode = ( $list ) => {
4789+ const $item = $list . find ( `.${ LIST_ITEM_CLASS } ` ) . eq ( 0 ) ;
4790+ const textNode = $item . find ( `.${ LIST_ITEM_CONTENT_CLASS } ` ) . eq ( 0 ) . get ( 0 ) . firstChild ;
4791+
4792+ return { $item, textNode } ;
4793+ } ;
4794+
4795+ QUnit . test ( 'text selection should not be cleared when dragging on list item without onItemSwipe' , function ( assert ) {
4796+ this . element . dxList ( {
4797+ items : [ 'Item 1' , 'Item 2' ] ,
4798+ } ) ;
4799+
4800+ const { $item, textNode } = getFirstListItemAndTextNode ( this . element ) ;
4801+ assert . strictEqual ( ! ! textNode , true , 'text node found in list item' ) ;
4802+
4803+ selectTextNodePart ( textNode , 0 , 4 ) ;
4804+ assert . strictEqual ( window . getSelection ( ) . toString ( ) , textNode . nodeValue . slice ( 0 , 4 ) , 'text selection exists before drag' ) ;
4805+
4806+ pointerMock ( $item ) . start ( ) . down ( 0 , 0 ) . move ( 50 , 0 ) . up ( ) ;
4807+
4808+ assert . strictEqual ( window . getSelection ( ) . toString ( ) , textNode . nodeValue . slice ( 0 , 4 ) , 'text selection exists after drag' ) ;
4809+ } ) ;
4810+
4811+ QUnit . test ( 'text selection should be preserved after onItemSwipe handler is removed from options' , function ( assert ) {
4812+ this . element . dxList ( {
4813+ items : [ 'Item 1' , 'Item 2' ] ,
4814+ onItemSwipe : sinon . spy ( ) ,
4815+ } ) ;
4816+ const list = this . element . dxList ( 'instance' ) ;
4817+
4818+ list . option ( 'onItemSwipe' , null ) ;
4819+
4820+ const { $item, textNode } = getFirstListItemAndTextNode ( this . element ) ;
4821+ assert . strictEqual ( ! ! textNode , true , 'text node found in list item' ) ;
4822+
4823+ selectTextNodePart ( textNode , 0 , 4 ) ;
4824+ assert . strictEqual ( window . getSelection ( ) . toString ( ) , textNode . nodeValue . slice ( 0 , 4 ) , 'text selection exists before drag' ) ;
4825+
4826+ pointerMock ( $item ) . start ( ) . down ( 0 , 0 ) . move ( 50 , 0 ) . up ( ) ;
4827+
4828+ assert . strictEqual ( window . getSelection ( ) . toString ( ) , textNode . nodeValue . slice ( 0 , 4 ) , 'text selection exists after drag' ) ;
4829+ } ) ;
4830+
4831+ QUnit . test ( 'text selection should reflect itemSwipe on/off subscription state' , function ( assert ) {
4832+ this . element . dxList ( {
4833+ items : [ 'Item 1' , 'Item 2' ] ,
4834+ } ) ;
4835+
4836+ const list = this . element . dxList ( 'instance' ) ;
4837+
4838+ const { $item, textNode } = getFirstListItemAndTextNode ( this . element ) ;
4839+ assert . strictEqual ( ! ! textNode , true , 'text node found in list item' ) ;
4840+
4841+ list . on ( 'itemSwipe' , sinon . spy ( ) ) ;
4842+
4843+ selectTextNodePart ( textNode , 0 , 4 ) ;
4844+ assert . strictEqual ( window . getSelection ( ) . toString ( ) , textNode . nodeValue . slice ( 0 , 4 ) , 'text selection exists before drag with subscribed swipe handler' ) ;
4845+
4846+ pointerMock ( $item ) . start ( ) . down ( 0 , 0 ) . move ( 50 , 0 ) . up ( ) ;
4847+
4848+ assert . strictEqual ( window . getSelection ( ) . toString ( ) , '' , 'text selection is cleared while swipe handler is attached' ) ;
4849+
4850+ list . off ( 'itemSwipe' ) ;
4851+
4852+ selectTextNodePart ( textNode , 0 , 4 ) ;
4853+ assert . strictEqual ( window . getSelection ( ) . toString ( ) , textNode . nodeValue . slice ( 0 , 4 ) , 'text selection exists before drag' ) ;
4854+
4855+ pointerMock ( $item ) . start ( ) . down ( 0 , 0 ) . move ( 50 , 0 ) . up ( ) ;
4856+
4857+ assert . strictEqual ( window . getSelection ( ) . toString ( ) , textNode . nodeValue . slice ( 0 , 4 ) , 'text selection exists after drag when swipe handler is removed' ) ;
4858+ } ) ;
4859+ } ) ;
4860+
47954861let helper ;
47964862if ( devices . real ( ) . deviceType === 'desktop' ) {
47974863 [ true , false ] . forEach ( ( searchEnabled ) => {
0 commit comments