Skip to content

Commit 7d5f618

Browse files
committed
fix(query-builder): test improved drag ghost siblings
1 parent 75c9dc1 commit 7d5f618

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

projects/igniteui-angular/src/lib/query-builder/query-builder-drag.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ export class IgxQueryBuilderDragService {
278278
return false;
279279
}
280280

281-
const ghostHeight = dragGhostBounds.bottom - dragGhostBounds.top;
281+
const tolerance = dragGhostBounds.bottom - dragGhostBounds.top;
282282

283-
return !(dragGhostBounds.bottom < dropGhostBounds.top - ghostHeight || dragGhostBounds.top > dropGhostBounds.bottom + ghostHeight);
283+
return !(dragGhostBounds.bottom < dropGhostBounds.top - tolerance || dragGhostBounds.top > dropGhostBounds.bottom + tolerance);
284284
}
285285

286286
/** Checks if the dragged ghost is north or south of a target element's center*/

projects/igniteui-angular/src/lib/query-builder/query-builder-functions.spec.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ export class QueryBuilderFunctions {
865865
}
866866

867867
public static getChipContent(chip: Element): string {
868-
if (chip.checkVisibility()) {
868+
if (chip && chip.checkVisibility()) {
869869
let text: string = '';
870870

871871
Array.from(chip.querySelectorAll('span')).forEach(element => {
@@ -911,11 +911,25 @@ export class QueryBuilderFunctions {
911911
}
912912
}
913913

914-
public static getDropGhostAndItsSiblings(fixture: ComponentFixture<any>): [Element, string, string, string[]]{
914+
public static getDropGhostAndItsSiblings(fixture: ComponentFixture<any>): [Element, string, string, string[]] {
915915
const dropGhost = this.getDropGhost(fixture);
916-
const prevElement = dropGhost && dropGhost.previousElementSibling?.previousElementSibling ? QueryBuilderFunctions.getChipContent(dropGhost.previousElementSibling.previousElementSibling) : null;
917-
const nextElement = dropGhost && dropGhost.nextElementSibling?.nextElementSibling ? QueryBuilderFunctions.getChipContent(dropGhost.nextElementSibling.nextElementSibling) : null;
918916
const newChipContents = QueryBuilderFunctions.GetChipsContentAsArray(fixture);
917+
let prevElement: string, nextElement: string;
918+
919+
if (dropGhost) {
920+
if (dropGhost.previousElementSibling?.className &&
921+
dropGhost.previousElementSibling?.className?.indexOf(QueryBuilderSelectors.FILTER_TREE_SUBQUERY) !== -1) {
922+
prevElement = QueryBuilderFunctions.getChipContent(dropGhost.previousElementSibling.previousElementSibling);
923+
} else if (dropGhost.previousElementSibling?.previousElementSibling) {
924+
prevElement = QueryBuilderFunctions.getChipContent(dropGhost.previousElementSibling);
925+
}
926+
927+
nextElement = QueryBuilderFunctions.getChipContent(dropGhost.nextElementSibling?.nextElementSibling);
928+
nextElement ??= QueryBuilderFunctions.getChipContent(dropGhost.nextElementSibling?.nextElementSibling?.nextElementSibling?.nextElementSibling);
929+
}
930+
931+
prevElement ??= null;
932+
nextElement ??= null;
919933

920934
return [dropGhost, prevElement, nextElement, newChipContents];
921935
}

projects/igniteui-angular/src/lib/query-builder/query-builder.component.spec.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2977,24 +2977,24 @@ describe('IgxQueryBuilder', () => {
29772977
case i === 0:
29782978
expect(dropGhost).toBeDefined();
29792979
expect(prevElement).toBeNull();
2980-
expect(nextElement).toEqual("OrderName Ends With a");
2980+
expect(nextElement).toEqual('OrderName Ends With a');
29812981
expect(newChipContents[4]).toBe(dropGhostContent);
29822982
break;
29832983
case i === 1:
29842984
expect(dropGhost).toBeDefined();
2985-
expect(prevElement).toEqual("OrderName Ends With a");
2986-
expect(nextElement).toEqual("OrderDate Today");
2985+
expect(prevElement).toEqual('OrderName Ends With a');
2986+
expect(nextElement).toEqual('OrderDate Today');
29872987
expect(newChipContents[5]).toBe(dropGhostContent);
29882988
break;
29892989
case i === 2:
29902990
expect(dropGhost).toBeDefined();
2991-
expect(prevElement).toEqual("OrderDate Today");
2991+
expect(prevElement).toEqual('OrderDate Today');
29922992
expect(nextElement).toBeNull();
29932993
expect(newChipContents[6]).toBe(dropGhostContent);
29942994
break;
29952995
case i >= 3:
29962996
expect(dropGhost).toBeDefined();
2997-
expect(prevElement).toBeUndefined();
2997+
expect(prevElement).toEqual('or OrderName Ends With a OrderDate Today');
29982998
expect(nextElement).toBeNull();
29992999
expect(newChipContents[6]).toBe(dropGhostContent);
30003000
break;
@@ -3013,32 +3013,32 @@ describe('IgxQueryBuilder', () => {
30133013
switch (true) {
30143014
case i === 0:
30153015
expect(dropGhost).toBeDefined();
3016-
expect(prevElement).toEqual("OrderDate Today");
3016+
expect(prevElement).toEqual('OrderDate Today');
30173017
expect(nextElement).toBeNull();
30183018
expect(newChipContents[6]).toBe(dropGhostContent);
30193019
break;
30203020
case i === 1:
30213021
expect(dropGhost).toBeDefined();
3022-
expect(prevElement).toEqual("OrderName Ends With a");
3023-
expect(nextElement).toEqual("OrderDate Today");
3022+
expect(prevElement).toEqual('OrderName Ends With a');
3023+
expect(nextElement).toEqual('OrderDate Today');
30243024
expect(newChipContents[5]).toBe(dropGhostContent);
30253025
break;
30263026
case i === 2:
30273027
expect(dropGhost).toBeDefined();
30283028
expect(prevElement).toBeNull();
3029-
expect(nextElement).toEqual("OrderName Ends With a");
3029+
expect(nextElement).toEqual('OrderName Ends With a');
30303030
expect(newChipContents[4]).toBe(dropGhostContent);
30313031
break;
30323032
case i === 3:
30333033
expect(dropGhost).toBeDefined();
3034-
expect(prevElement).toEqual("OrderName Equals foo");
3035-
expect(nextElement).toBeUndefined();
3034+
expect(prevElement).toEqual('OrderName Equals foo');
3035+
expect(nextElement).toEqual('or OrderName Ends With a OrderDate Today');
30363036
expect(newChipContents[1]).toBe(dropGhostContent);
30373037
break;
30383038
case i >= 4:
30393039
expect(dropGhost).toBeDefined();
30403040
expect(prevElement).toBeNull();
3041-
expect(nextElement).toEqual("OrderName Equals foo");
3041+
expect(nextElement).toEqual('OrderName Equals foo');
30423042
expect(newChipContents[0]).toBe(dropGhostContent);
30433043
break;
30443044
}
@@ -3056,31 +3056,31 @@ describe('IgxQueryBuilder', () => {
30563056
switch (true) {
30573057
case i === 0:
30583058
expect(dropGhost).toBeDefined();
3059-
expect(prevElement).toEqual("OrderName Equals foo");
3060-
expect(nextElement).toBeUndefined();
3059+
expect(prevElement).toEqual('OrderName Equals foo');
3060+
expect(nextElement).toEqual('or OrderName Ends With a OrderDate Today');
30613061
expect(newChipContents[1]).toBe(dropGhostContent);
30623062
break;
30633063
case i === 1:
30643064
expect(dropGhost).toBeDefined();
30653065
expect(prevElement).toBeNull();
3066-
expect(nextElement).toEqual("OrderName Ends With a");
3066+
expect(nextElement).toEqual('OrderName Ends With a');
30673067
expect(newChipContents[4]).toBe(dropGhostContent);
30683068
break;
30693069
case i === 2:
30703070
expect(dropGhost).toBeDefined();
3071-
expect(prevElement).toEqual("OrderName Ends With a");
3072-
expect(nextElement).toEqual("OrderDate Today");
3071+
expect(prevElement).toEqual('OrderName Ends With a');
3072+
expect(nextElement).toEqual('OrderDate Today');
30733073
expect(newChipContents[5]).toBe(dropGhostContent);
30743074
break;
30753075
case i === 3:
30763076
expect(dropGhost).toBeDefined();
3077-
expect(prevElement).toEqual("OrderDate Today");
3077+
expect(prevElement).toEqual('OrderDate Today');
30783078
expect(nextElement).toBeNull();
30793079
expect(newChipContents[6]).toBe(dropGhostContent);
30803080
break;
30813081
case i >= 4:
30823082
expect(dropGhost).toBeDefined();
3083-
expect(prevElement).toBeUndefined();
3083+
expect(prevElement).toEqual('or OrderName Ends With a OrderDate Today');
30843084
expect(nextElement).toBeNull();
30853085
expect(newChipContents[6]).toBe(dropGhostContent);
30863086
break;

0 commit comments

Comments
 (0)