@@ -3090,6 +3090,139 @@ describe('IgxQueryBuilder', () => {
30903090 }
30913091 }
30923092 } ) ) ;
3093+
3094+ it ( 'Should commit drop upon hitting \'Enter\' when keyboard dragged.' , fakeAsync ( ( ) => {
3095+ const draggedIndicator = fix . debugElement . queryAll ( By . css ( '.igx-drag-indicator' ) ) [ 4 ] ;
3096+ const tree = fix . debugElement . query ( By . css ( '.igx-filter-tree' ) ) ;
3097+
3098+ draggedIndicator . triggerEventHandler ( 'focus' , { } ) ;
3099+ draggedIndicator . nativeElement . focus ( ) ;
3100+
3101+ spyOn ( tree . nativeElement , 'dispatchEvent' ) . and . callThrough ( ) ;
3102+ const dropGhostContent = QueryBuilderFunctions . GetChipsContentAsArray ( fix ) [ 1 ] ;
3103+
3104+ tree . nativeElement . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' } ) ) ;
3105+ tick ( 20 ) ;
3106+ fix . detectChanges ( ) ;
3107+
3108+ tree . nativeElement . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'Enter' } ) ) ;
3109+ tick ( 20 ) ;
3110+ fix . detectChanges ( ) ;
3111+
3112+ //Verify that expressionTree is correct
3113+ const exprTree = JSON . stringify ( fix . componentInstance . queryBuilder . expressionTree , null , 2 ) ;
3114+ expect ( exprTree ) . toBe ( `{
3115+ "filteringOperands": [
3116+ {
3117+ "fieldName": "OrderName",
3118+ "condition": {
3119+ "name": "equals",
3120+ "isUnary": false,
3121+ "iconName": "filter_equal"
3122+ },
3123+ "conditionName": "equals",
3124+ "searchVal": "foo"
3125+ },
3126+ {
3127+ "fieldName": "OrderId",
3128+ "condition": {
3129+ "name": "inQuery",
3130+ "isUnary": false,
3131+ "isNestedQuery": true,
3132+ "iconName": "in"
3133+ },
3134+ "conditionName": "inQuery",
3135+ "searchTree": {
3136+ "filteringOperands": [
3137+ {
3138+ "fieldName": "Id",
3139+ "condition": {
3140+ "name": "equals",
3141+ "isUnary": false,
3142+ "iconName": "filter_equal"
3143+ },
3144+ "conditionName": "equals",
3145+ "searchVal": 123
3146+ },
3147+ {
3148+ "fieldName": "ProductName",
3149+ "condition": {
3150+ "name": "equals",
3151+ "isUnary": false,
3152+ "iconName": "filter_equal"
3153+ },
3154+ "conditionName": "equals",
3155+ "searchVal": "abc"
3156+ }
3157+ ],
3158+ "operator": 0,
3159+ "entity": "Products",
3160+ "returnFields": [
3161+ "OrderId"
3162+ ]
3163+ }
3164+ },
3165+ {
3166+ "filteringOperands": [
3167+ {
3168+ "fieldName": "OrderName",
3169+ "condition": {
3170+ "name": "endsWith",
3171+ "isUnary": false,
3172+ "iconName": "filter_ends_with"
3173+ },
3174+ "conditionName": "endsWith",
3175+ "searchVal": "a"
3176+ },
3177+ {
3178+ "fieldName": "OrderDate",
3179+ "condition": {
3180+ "name": "today",
3181+ "isUnary": true,
3182+ "iconName": "filter_today"
3183+ },
3184+ "conditionName": "today"
3185+ }
3186+ ],
3187+ "operator": 1,
3188+ "entity": "Orders",
3189+ "returnFields": [
3190+ "*"
3191+ ]
3192+ }
3193+ ],
3194+ "operator": 0,
3195+ "entity": "Orders",
3196+ "returnFields": [
3197+ "*"
3198+ ],
3199+ "fieldName": null
3200+ }` ) ;
3201+ } ) ) ;
3202+
3203+ it ( 'Should cancel drop upon hitting \'Escape\' when keyboard dragged.' , fakeAsync ( ( ) => {
3204+ const draggedIndicator = fix . debugElement . queryAll ( By . css ( '.igx-drag-indicator' ) ) [ 4 ] ;
3205+ const tree = fix . debugElement . query ( By . css ( '.igx-filter-tree' ) ) ;
3206+
3207+ draggedIndicator . triggerEventHandler ( 'focus' , { } ) ;
3208+ draggedIndicator . nativeElement . focus ( ) ;
3209+
3210+ spyOn ( tree . nativeElement , 'dispatchEvent' ) . and . callThrough ( ) ;
3211+ const dropGhostContent = QueryBuilderFunctions . GetChipsContentAsArray ( fix ) [ 1 ] ;
3212+
3213+ tree . nativeElement . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' } ) ) ;
3214+ tick ( 20 ) ;
3215+ fix . detectChanges ( ) ;
3216+
3217+ tree . nativeElement . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'Escape' } ) ) ;
3218+ tick ( 20 ) ;
3219+ fix . detectChanges ( ) ;
3220+
3221+ chipComponents = QueryBuilderFunctions . getVisibleChips ( fix ) ;
3222+ expect ( QueryBuilderFunctions . getChipContent ( chipComponents [ 2 ] . nativeElement ) ) . toBe ( "OrderName Ends With a" ) ;
3223+ expect ( QueryBuilderFunctions . getChipContent ( chipComponents [ 3 ] . nativeElement ) ) . toBe ( "OrderDate Today" ) ;
3224+ } ) ) ;
3225+
30933226 } ) ;
30943227} ) ;
30953228
0 commit comments