@@ -2917,64 +2917,144 @@ describe('IgxQueryBuilder', () => {
29172917 expect ( QueryBuilderFunctions . getChipContent ( newGroupConditions [ 0 ] ) ) . toBe ( "OrderDate Today" ) ;
29182918 } ) ;
29192919
2920- it ( 'should render drop ghost properly when keyboard dragged.' , async ( ) => {
2920+ it ( 'should render drop ghost properly when keyboard dragged.' , ( ) => {
29212921 const draggedIndicator = fix . debugElement . queryAll ( By . css ( '.igx-drag-indicator' ) ) [ 1 ] ;
29222922 const tree = fix . debugElement . query ( By . css ( '.igx-filter-tree' ) ) ;
2923- let keyPress = new KeyboardEvent ( 'keydown' , { code : 'ArrowDown' } ) ;
2924-
2923+
29252924 draggedIndicator . triggerEventHandler ( 'focus' , { } ) ;
29262925 draggedIndicator . nativeElement . focus ( ) ;
2927-
2926+
29282927 spyOn ( tree . nativeElement , 'dispatchEvent' ) . and . callThrough ( ) ;
29292928 const dropGhostContent = QueryBuilderFunctions . GetChipsContentAsArray ( fix ) [ 1 ] ;
2930-
2929+
2930+ //pass 1 down to bottom
2931+ let keyPress = new KeyboardEvent ( 'keydown' , { code : 'ArrowDown' } ) ;
29312932 for ( let i = 0 ; i <= 5 ; i ++ ) {
29322933 tree . nativeElement . dispatchEvent ( keyPress ) ;
2933- await wait ( ) ;
2934+ wait ( ) ;
29342935 fix . detectChanges ( ) ;
29352936
2937+ const dropGhost = QueryBuilderFunctions . getDropGhost ( fix ) ;
2938+ const prevElement = dropGhost && dropGhost . previousElementSibling ? QueryBuilderFunctions . getChipContent ( dropGhost . previousElementSibling ) : null ;
2939+ const nextElement = dropGhost && dropGhost . nextElementSibling ? QueryBuilderFunctions . getChipContent ( dropGhost . nextElementSibling ) : null ;
29362940 const newChipContents = QueryBuilderFunctions . GetChipsContentAsArray ( fix ) ;
29372941
29382942 switch ( true ) {
29392943 case i === 0 :
2944+ expect ( dropGhost ) . toBeDefined ( ) ;
2945+ expect ( prevElement ) . toBeNull ( ) ;
2946+ expect ( nextElement ) . toEqual ( "OrderName Ends With a" ) ;
29402947 expect ( newChipContents [ 4 ] ) . toBe ( dropGhostContent ) ;
29412948 break ;
29422949 case i === 1 :
2950+ expect ( dropGhost ) . toBeDefined ( ) ;
2951+ expect ( prevElement ) . toEqual ( "OrderName Ends With a" ) ;
2952+ expect ( nextElement ) . toBeUndefined ( ) ;
29432953 expect ( newChipContents [ 5 ] ) . toBe ( dropGhostContent ) ;
29442954 break ;
2945- case i >= 2 :
2955+ case i === 2 :
2956+ expect ( dropGhost ) . toBeDefined ( ) ;
2957+ expect ( prevElement ) . toEqual ( "OrderDate Today" ) ;
2958+ expect ( nextElement ) . toBeUndefined ( ) ;
2959+ expect ( newChipContents [ 6 ] ) . toBe ( dropGhostContent ) ;
2960+ break ;
2961+ case i >= 3 :
2962+ expect ( dropGhost ) . toBeDefined ( ) ;
2963+ expect ( prevElement ) . toEqual ( "or OrderName Ends With a OrderDate Today" ) ;
2964+ expect ( nextElement ) . toBeNull ( ) ;
29462965 expect ( newChipContents [ 6 ] ) . toBe ( dropGhostContent ) ;
29472966 break ;
29482967 }
29492968 }
29502969
2970+ //pass 2 up to top
29512971 keyPress = new KeyboardEvent ( 'keydown' , { code : 'ArrowUp' } ) ;
2952-
29532972 for ( let i = 0 ; i <= 10 ; i ++ ) {
29542973 tree . nativeElement . dispatchEvent ( keyPress ) ;
2955- await wait ( ) ;
2974+ wait ( ) ;
29562975 fix . detectChanges ( ) ;
29572976
2977+ const dropGhost = QueryBuilderFunctions . getDropGhost ( fix ) ;
2978+ const prevElement = dropGhost && dropGhost . previousElementSibling ? QueryBuilderFunctions . getChipContent ( dropGhost . previousElementSibling ) : null ;
2979+ const nextElement = dropGhost && dropGhost . nextElementSibling ? QueryBuilderFunctions . getChipContent ( dropGhost . nextElementSibling ) : null ;
29582980 const newChipContents = QueryBuilderFunctions . GetChipsContentAsArray ( fix ) ;
29592981
29602982 switch ( true ) {
29612983 case i === 0 :
2984+ expect ( dropGhost ) . toBeDefined ( ) ;
2985+ expect ( prevElement ) . toEqual ( "OrderDate Today" ) ;
2986+ expect ( nextElement ) . toBeUndefined ( ) ;
29622987 expect ( newChipContents [ 6 ] ) . toBe ( dropGhostContent ) ;
29632988 break ;
29642989 case i === 1 :
2990+ expect ( dropGhost ) . toBeDefined ( ) ;
2991+ expect ( prevElement ) . toBeUndefined ( ) ;
2992+ expect ( nextElement ) . toEqual ( "OrderDate Today" ) ;
29652993 expect ( newChipContents [ 5 ] ) . toBe ( dropGhostContent ) ;
29662994 break ;
29672995 case i === 2 :
2996+ expect ( dropGhost ) . toBeDefined ( ) ;
2997+ expect ( prevElement ) . toBeNull ( ) ;
2998+ expect ( nextElement ) . toEqual ( "OrderName Ends With a" ) ;
29682999 expect ( newChipContents [ 4 ] ) . toBe ( dropGhostContent ) ;
29693000 break ;
29703001 case i === 3 :
3002+ expect ( dropGhost ) . toBeDefined ( ) ;
3003+ expect ( prevElement ) . toBeUndefined ( ) ;
3004+ expect ( nextElement ) . toEqual ( "or OrderName Ends With a OrderDate Today" ) ;
29713005 expect ( newChipContents [ 4 ] ) . toBe ( dropGhostContent ) ;
29723006 break ;
2973- case i === 4 :
3007+ case i >= 4 :
3008+ expect ( dropGhost ) . toBeDefined ( ) ;
3009+ expect ( prevElement ) . toBeNull ( ) ;
3010+ expect ( nextElement ) . toEqual ( "OrderName Equals foo" ) ;
29743011 expect ( newChipContents [ 0 ] ) . toBe ( dropGhostContent ) ;
29753012 break ;
2976- case i >= 5 :
2977- expect ( newChipContents [ 0 ] ) . toBe ( dropGhostContent ) ;
3013+ }
3014+ }
3015+
3016+ //pass 3 down to bottom again
3017+ keyPress = new KeyboardEvent ( 'keydown' , { code : 'ArrowDown' } ) ;
3018+ for ( let i = 0 ; i <= 10 ; i ++ ) {
3019+ tree . nativeElement . dispatchEvent ( keyPress ) ;
3020+ wait ( ) ;
3021+ fix . detectChanges ( ) ;
3022+
3023+ const dropGhost = QueryBuilderFunctions . getDropGhost ( fix ) ;
3024+ const prevElement = dropGhost && dropGhost . previousElementSibling ? QueryBuilderFunctions . getChipContent ( dropGhost . previousElementSibling ) : null ;
3025+ const nextElement = dropGhost && dropGhost . nextElementSibling ? QueryBuilderFunctions . getChipContent ( dropGhost . nextElementSibling ) : null ;
3026+ const newChipContents = QueryBuilderFunctions . GetChipsContentAsArray ( fix ) ;
3027+
3028+ switch ( true ) {
3029+ case i === 0 :
3030+ expect ( dropGhost ) . toBeDefined ( ) ;
3031+ expect ( prevElement ) . toEqual ( "OrderName Equals foo" ) ;
3032+ expect ( nextElement ) . toBeUndefined ( ) ;
3033+ expect ( newChipContents [ 1 ] ) . toBe ( dropGhostContent ) ;
3034+ break ;
3035+ case i === 1 :
3036+ expect ( dropGhost ) . toBeDefined ( ) ;
3037+ expect ( prevElement ) . toBeNull ( ) ;
3038+ expect ( nextElement ) . toEqual ( "OrderName Ends With a" ) ;
3039+ expect ( newChipContents [ 4 ] ) . toBe ( dropGhostContent ) ;
3040+ break ;
3041+ case i === 2 :
3042+ expect ( dropGhost ) . toBeDefined ( ) ;
3043+ expect ( prevElement ) . toEqual ( "OrderName Ends With a" ) ;
3044+ expect ( nextElement ) . toBeUndefined ( ) ;
3045+ expect ( newChipContents [ 5 ] ) . toBe ( dropGhostContent ) ;
3046+ break ;
3047+ case i === 3 :
3048+ expect ( dropGhost ) . toBeDefined ( ) ;
3049+ expect ( prevElement ) . toEqual ( "OrderDate Today" ) ;
3050+ expect ( nextElement ) . toBeUndefined ( ) ;
3051+ expect ( newChipContents [ 6 ] ) . toBe ( dropGhostContent ) ;
3052+ break ;
3053+ case i >= 4 :
3054+ expect ( dropGhost ) . toBeDefined ( ) ;
3055+ expect ( prevElement ) . toEqual ( "or OrderName Ends With a OrderDate Today" ) ;
3056+ expect ( nextElement ) . toBeNull ( ) ;
3057+ expect ( newChipContents [ 6 ] ) . toBe ( dropGhostContent ) ;
29783058 break ;
29793059 }
29803060 }
0 commit comments