Skip to content

Commit 63a21d6

Browse files
committed
test(adv-filtering): more tests #5496
1 parent ec9287c commit 63a21d6

File tree

1 file changed

+142
-1
lines changed

1 file changed

+142
-1
lines changed

projects/igniteui-angular/src/lib/grids/grid/grid-filtering-advanced.spec.ts

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,126 @@ describe('IgxGrid - Advanced Filtering', () => {
13741374
'incorrect all children count of group with path [0]');
13751375
}));
13761376

1377+
it('Should remove a condition from an existing group by using delete icon of respective chip.', fakeAsync(() => {
1378+
// Apply advanced filter through API.
1379+
const tree = new FilteringExpressionsTree(FilteringLogic.And);
1380+
tree.filteringOperands.push({
1381+
fieldName: 'Downloads', searchVal: 100, condition: IgxNumberFilteringOperand.instance().condition('greaterThan')
1382+
});
1383+
const orTree = new FilteringExpressionsTree(FilteringLogic.Or);
1384+
orTree.filteringOperands.push({
1385+
fieldName: 'ProductName', searchVal: 'angular', condition: IgxStringFilteringOperand.instance().condition('contains'),
1386+
ignoreCase: true
1387+
});
1388+
orTree.filteringOperands.push({
1389+
fieldName: 'ProductName', searchVal: 'script', condition: IgxStringFilteringOperand.instance().condition('contains'),
1390+
ignoreCase: true
1391+
});
1392+
tree.filteringOperands.push(orTree);
1393+
grid.advancedFilteringExpressionsTree = tree;
1394+
fix.detectChanges();
1395+
1396+
// Open Advanced Filtering dialog.
1397+
GridFunctions.clickAdvancedFilteringButton(fix);
1398+
fix.detectChanges();
1399+
1400+
// Verify tree layout before deleting chips.
1401+
let rootGroup = GridFunctions.getAdvancedFilteringTreeRootGroup(fix);
1402+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup, true).length).toBe(2);
1403+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup, false).length).toBe(4);
1404+
1405+
// Delete a chip and verify layout.
1406+
GridFunctions.clickAdvancedFilteringTreeExpressionChipRemoveIcon(fix, [0]);
1407+
tick(100);
1408+
fix.detectChanges();
1409+
1410+
rootGroup = GridFunctions.getAdvancedFilteringTreeRootGroup(fix);
1411+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup, true).length).toBe(1);
1412+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup, false).length).toBe(3);
1413+
1414+
// Delete a chip and verify layout.
1415+
GridFunctions.clickAdvancedFilteringTreeExpressionChipRemoveIcon(fix, [0, 1]);
1416+
tick(100);
1417+
fix.detectChanges();
1418+
rootGroup = GridFunctions.getAdvancedFilteringTreeRootGroup(fix);
1419+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup, true).length).toBe(1);
1420+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup, false).length).toBe(2);
1421+
1422+
// Verify remaining chip's content.
1423+
verifyExpressionChipContent(fix, [0, 0], 'ProductName', 'Contains', 'angular');
1424+
}));
1425+
1426+
it('Should select/deselect a condition when its respective chip is clicked.', fakeAsync(() => {
1427+
// Apply advanced filter through API.
1428+
const tree = new FilteringExpressionsTree(FilteringLogic.Or);
1429+
tree.filteringOperands.push({
1430+
fieldName: 'ProductName', searchVal: 'angular', condition: IgxStringFilteringOperand.instance().condition('contains'),
1431+
ignoreCase: true
1432+
});
1433+
tree.filteringOperands.push({
1434+
fieldName: 'ProductName', searchVal: 'script', condition: IgxStringFilteringOperand.instance().condition('contains'),
1435+
ignoreCase: true
1436+
});
1437+
grid.advancedFilteringExpressionsTree = tree;
1438+
fix.detectChanges();
1439+
1440+
// Open Advanced Filtering dialog.
1441+
GridFunctions.clickAdvancedFilteringButton(fix);
1442+
fix.detectChanges();
1443+
1444+
// Verify first chip is not selected.
1445+
verifyExpressionChipSelection(fix, [0], false);
1446+
1447+
// Click first chip and verify it is selected.
1448+
GridFunctions.clickAdvancedFilteringTreeExpressionChip(fix, [0]);
1449+
tick(200);
1450+
fix.detectChanges();
1451+
verifyExpressionChipSelection(fix, [0], true);
1452+
1453+
// Click first chip again and verify it is not selected.
1454+
GridFunctions.clickAdvancedFilteringTreeExpressionChip(fix, [0]);
1455+
tick(200);
1456+
fix.detectChanges();
1457+
verifyExpressionChipSelection(fix, [0], false);
1458+
}));
1459+
1460+
it('Should display edit and add buttons when hovering a chip.', fakeAsync(() => {
1461+
// Apply advanced filter through API.
1462+
const tree = new FilteringExpressionsTree(FilteringLogic.Or);
1463+
tree.filteringOperands.push({
1464+
fieldName: 'ProductName', searchVal: 'angular', condition: IgxStringFilteringOperand.instance().condition('contains'),
1465+
ignoreCase: true
1466+
});
1467+
tree.filteringOperands.push({
1468+
fieldName: 'ProductName', searchVal: 'script', condition: IgxStringFilteringOperand.instance().condition('contains'),
1469+
ignoreCase: true
1470+
});
1471+
grid.advancedFilteringExpressionsTree = tree;
1472+
fix.detectChanges();
1473+
1474+
// Open Advanced Filtering dialog.
1475+
GridFunctions.clickAdvancedFilteringButton(fix);
1476+
fix.detectChanges();
1477+
1478+
// Verify actions container is not visible. (This container contains the 'edit' and the 'add' buttons.)
1479+
expect(GridFunctions.getAdvancedFilteringTreeExpressionActionsContainer(fix, [0]))
1480+
.toBeNull('actions container is visible');
1481+
1482+
// Hover the first chip and verify actions container is visible.
1483+
hoverElement(GridFunctions.getAdvancedFilteringTreeItem(fix, [0]));
1484+
tick(50);
1485+
fix.detectChanges();
1486+
expect(GridFunctions.getAdvancedFilteringTreeExpressionActionsContainer(fix, [0]))
1487+
.not.toBeNull('actions container is not visible');
1488+
1489+
// Unhover the first chip and verify actions container is not visible.
1490+
unhoverElement(GridFunctions.getAdvancedFilteringTreeItem(fix, [0]));
1491+
tick(50);
1492+
fix.detectChanges();
1493+
expect(GridFunctions.getAdvancedFilteringTreeExpressionActionsContainer(fix, [0]))
1494+
.toBeNull('actions container is visible');
1495+
}));
1496+
13771497
describe('Context Menu', () => {
13781498
it('Should discard added group when clicking its operator line without having a single expression.', fakeAsync(() => {
13791499
// Open Advanced Filtering dialog.
@@ -2136,6 +2256,14 @@ function sendInputNativeElement(fix, nativeElement, text) {
21362256
fix.detectChanges();
21372257
}
21382258

2259+
function hoverElement(element: HTMLElement, bubbles: boolean = false) {
2260+
element.dispatchEvent(new MouseEvent('mouseenter', { bubbles: bubbles }));
2261+
}
2262+
2263+
function unhoverElement(element: HTMLElement, bubbles: boolean = false) {
2264+
element.dispatchEvent(new MouseEvent('mouseleave', { bubbles: bubbles }));
2265+
}
2266+
21392267
/**
21402268
* Verifies the type of the operator line ('and' or 'or').
21412269
* (NOTE: The 'operator' argument must be a string with a value that is either 'and' or 'or'.)
@@ -2154,7 +2282,6 @@ function verifyOperatorLine(operatorLine: HTMLElement, operator: string) {
21542282

21552283
function verifyExpressionChipContent(fix, path: number[], columnText: string, operatorText: string, valueText: string) {
21562284
const chip = GridFunctions.getAdvancedFilteringTreeExpressionChip(fix, path);
2157-
// const columnNameContainer = chip.querySelector('.igx-filter-tree__expression-column');
21582285
const chipSpans = GridFunctions.sortNativeElementsHorizontally(Array.from(chip.querySelectorAll('span')));
21592286
const columnSpan = chipSpans[0];
21602287
const operatorSpan = chipSpans[1];
@@ -2164,6 +2291,20 @@ function verifyExpressionChipContent(fix, path: number[], columnText: string, op
21642291
expect(valueSpan.innerText.toLowerCase().trim()).toBe(valueText.toLowerCase(), 'incorrect chip filter value');
21652292
}
21662293

2294+
function verifyExpressionChipSelection(fix, path: number[], shouldBeSelected: boolean) {
2295+
const chip = GridFunctions.getAdvancedFilteringTreeExpressionChip(fix, path);
2296+
const chipItem = chip.querySelector('.igx-chip__item');
2297+
if (shouldBeSelected) {
2298+
expect(chipItem.classList.contains('igx-chip__item--selected')).toBe(true, 'chip is not selected');
2299+
expect(chipItem.querySelector('.igx-chip__select')).not.toBeNull();
2300+
expect(chipItem.querySelector('.igx-chip__select--hidden')).toBeNull();
2301+
} else {
2302+
expect(chipItem.classList.contains('igx-chip__item--selected')).toBe(false, 'chip is selected');
2303+
expect(chipItem.querySelector('.igx-chip__select')).toBeNull();
2304+
expect(chipItem.querySelector('.igx-chip__select--hidden')).not.toBeNull();
2305+
}
2306+
}
2307+
21672308
function verifyEditModeExpressionInputStates(fix,
21682309
columnSelectEnabled: boolean,
21692310
operatorSelectEnabled: boolean,

0 commit comments

Comments
 (0)