Skip to content

Commit 17bb670

Browse files
committed
test(adv-filtering): hierarchical selection #5496
1 parent 63a21d6 commit 17bb670

File tree

2 files changed

+110
-2
lines changed

2 files changed

+110
-2
lines changed

Diff for: projects/igniteui-angular/src/lib/grids/filtering/advanced-filtering/advanced-filtering-dialog.component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ export class IgxAdvancedFilteringDialogComponent implements AfterViewInit, OnDes
249249
if (!this.contextMenuToggle.collapsed) {
250250
this.calculateContextMenuTarget();
251251
this.contextMenuToggle.reposition();
252-
// 'flex' should be changed '' when styling class is added to contextMenuToggle
253-
this.contextMenuToggle.element.style.display = 'flex';
252+
this.contextMenuToggle.element.style.display = '';
254253
}
255254
}
256255

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

+109
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { resizeObserverIgnoreError } from '../../test-utils/helper-utils.spec';
1919

2020
const ADVANCED_FILTERING_OPERATOR_LINE_AND_CSS_CLASS = 'igx-filter-tree__line--and';
2121
const ADVANCED_FILTERING_OPERATOR_LINE_OR_CSS_CLASS = 'igx-filter-tree__line--or';
22+
const ADVANCED_FILTERING_OPERATOR_LINE_SELECTED_CSS_CLASS = 'igx-filter-tree__line--selected';
2223

2324
describe('IgxGrid - Advanced Filtering', () => {
2425
configureTestSuite();
@@ -1494,6 +1495,66 @@ describe('IgxGrid - Advanced Filtering', () => {
14941495
.toBeNull('actions container is visible');
14951496
}));
14961497

1498+
it('Should select/deselect all child conditions and groups when clicking a group\'s operator line.', fakeAsync(() => {
1499+
// Apply advanced filter through API.
1500+
const tree = new FilteringExpressionsTree(FilteringLogic.And);
1501+
tree.filteringOperands.push({
1502+
fieldName: 'Downloads', searchVal: 100, condition: IgxNumberFilteringOperand.instance().condition('greaterThan')
1503+
});
1504+
const orTree = new FilteringExpressionsTree(FilteringLogic.Or);
1505+
orTree.filteringOperands.push({
1506+
fieldName: 'ProductName', searchVal: 'angular', condition: IgxStringFilteringOperand.instance().condition('contains'),
1507+
ignoreCase: true
1508+
});
1509+
orTree.filteringOperands.push({
1510+
fieldName: 'ProductName', searchVal: 'script', condition: IgxStringFilteringOperand.instance().condition('contains'),
1511+
ignoreCase: true
1512+
});
1513+
const andTree = new FilteringExpressionsTree(FilteringLogic.Or);
1514+
andTree.filteringOperands.push({
1515+
fieldName: 'ProductName', searchVal: 'a', condition: IgxStringFilteringOperand.instance().condition('contains'),
1516+
ignoreCase: true
1517+
});
1518+
andTree.filteringOperands.push({
1519+
fieldName: 'ProductName', searchVal: 's', condition: IgxStringFilteringOperand.instance().condition('contains'),
1520+
ignoreCase: true
1521+
});
1522+
orTree.filteringOperands.push(andTree);
1523+
tree.filteringOperands.push(orTree);
1524+
grid.advancedFilteringExpressionsTree = tree;
1525+
fix.detectChanges();
1526+
1527+
// Open Advanced Filtering dialog.
1528+
GridFunctions.clickAdvancedFilteringButton(fix);
1529+
fix.detectChanges();
1530+
1531+
// Click root group's operator line and verify that the root group and all of its children become selected.
1532+
let rootOperatorLine = GridFunctions.getAdvancedFilteringTreeRootGroupOperatorLine(fix);
1533+
rootOperatorLine.click();
1534+
tick(200);
1535+
fix.detectChanges();
1536+
verifyChildrenSelection(GridFunctions.getAdvancedFilteringExpressionsContainer(fix), true);
1537+
1538+
// Click root group's operator line again and verify that the root group and all of its children become unselected.
1539+
rootOperatorLine = GridFunctions.getAdvancedFilteringTreeRootGroupOperatorLine(fix);
1540+
rootOperatorLine.click();
1541+
tick(200);
1542+
fix.detectChanges();
1543+
verifyChildrenSelection(GridFunctions.getAdvancedFilteringExpressionsContainer(fix), false);
1544+
1545+
// Click an inner group's operator line and verify its children become selected.
1546+
GridFunctions.clickAdvancedFilteringTreeGroupOperatorLine(fix, [1]);
1547+
tick(200);
1548+
fix.detectChanges();
1549+
verifyChildrenSelection(GridFunctions.getAdvancedFilteringTreeItem(fix, [1]), true);
1550+
1551+
// Click an inner group's operator line again and verify its children become unselected.
1552+
GridFunctions.clickAdvancedFilteringTreeGroupOperatorLine(fix, [1]);
1553+
tick(200);
1554+
fix.detectChanges();
1555+
verifyChildrenSelection(GridFunctions.getAdvancedFilteringTreeItem(fix, [1]), false);
1556+
}));
1557+
14971558
describe('Context Menu', () => {
14981559
it('Should discard added group when clicking its operator line without having a single expression.', fakeAsync(() => {
14991560
// Open Advanced Filtering dialog.
@@ -1917,6 +1978,31 @@ describe('IgxGrid - Advanced Filtering', () => {
19171978
}
19181979
}));
19191980

1981+
it('Ungroup button of the root group\'s context menu should be disabled.',
1982+
fakeAsync(() => {
1983+
// Apply advanced filter through API.
1984+
const tree = new FilteringExpressionsTree(FilteringLogic.And);
1985+
tree.filteringOperands.push({
1986+
fieldName: 'Downloads', searchVal: 100, condition: IgxNumberFilteringOperand.instance().condition('greaterThan')
1987+
});
1988+
grid.advancedFilteringExpressionsTree = tree;
1989+
fix.detectChanges();
1990+
1991+
// Open Advanced Filtering dialog.
1992+
GridFunctions.clickAdvancedFilteringButton(fix);
1993+
fix.detectChanges();
1994+
1995+
// Click root group's operator line.
1996+
const rootOperatorLine = GridFunctions.getAdvancedFilteringTreeRootGroupOperatorLine(fix);
1997+
rootOperatorLine.click();
1998+
tick(200);
1999+
fix.detectChanges();
2000+
2001+
// Verify the ungroup button is disabled.
2002+
const ungroupButton = GridFunctions.getAdvancedFilteringContextMenuButtons(fix)[1];
2003+
expect(ungroupButton.classList.contains('igx-button--disabled')).toBe(true);
2004+
}));
2005+
19202006
it('Should delete the group from the tree when click \'delete\' from context menu.',
19212007
fakeAsync(() => {
19222008
// Apply advanced filter through API.
@@ -2280,6 +2366,11 @@ function verifyOperatorLine(operatorLine: HTMLElement, operator: string) {
22802366
}
22812367
}
22822368

2369+
function verifyOperatorLineSelection(operatorLine: HTMLElement, shouldBeSelected: boolean) {
2370+
expect(operatorLine.classList.contains(ADVANCED_FILTERING_OPERATOR_LINE_SELECTED_CSS_CLASS))
2371+
.toBe(shouldBeSelected, 'incorrect selection state of the operator line');
2372+
}
2373+
22832374
function verifyExpressionChipContent(fix, path: number[], columnText: string, operatorText: string, valueText: string) {
22842375
const chip = GridFunctions.getAdvancedFilteringTreeExpressionChip(fix, path);
22852376
const chipSpans = GridFunctions.sortNativeElementsHorizontally(Array.from(chip.querySelectorAll('span')));
@@ -2293,6 +2384,10 @@ function verifyExpressionChipContent(fix, path: number[], columnText: string, op
22932384

22942385
function verifyExpressionChipSelection(fix, path: number[], shouldBeSelected: boolean) {
22952386
const chip = GridFunctions.getAdvancedFilteringTreeExpressionChip(fix, path);
2387+
verifyExpressionChipSelectionByChip(chip, shouldBeSelected);
2388+
}
2389+
2390+
function verifyExpressionChipSelectionByChip(chip: HTMLElement, shouldBeSelected: boolean) {
22962391
const chipItem = chip.querySelector('.igx-chip__item');
22972392
if (shouldBeSelected) {
22982393
expect(chipItem.classList.contains('igx-chip__item--selected')).toBe(true, 'chip is not selected');
@@ -2305,6 +2400,20 @@ function verifyExpressionChipSelection(fix, path: number[], shouldBeSelected: bo
23052400
}
23062401
}
23072402

2403+
/**
2404+
* Verifies that all children (operator lines and expression chips) of the provided 'parent' are selected.
2405+
*/
2406+
function verifyChildrenSelection(parent: HTMLElement, shouldBeSelected: boolean) {
2407+
const allOperatorLines: any[] = Array.from(parent.querySelectorAll('.igx-filter-tree__line'));
2408+
const allExpressionChips: any[] = Array.from(parent.querySelectorAll('.igx-filter-tree__expression-item'));
2409+
for (const operatorLine of allOperatorLines) {
2410+
verifyOperatorLineSelection(operatorLine, shouldBeSelected);
2411+
}
2412+
for (const expressionChip of allExpressionChips) {
2413+
verifyExpressionChipSelectionByChip(expressionChip, shouldBeSelected);
2414+
}
2415+
}
2416+
23082417
function verifyEditModeExpressionInputStates(fix,
23092418
columnSelectEnabled: boolean,
23102419
operatorSelectEnabled: boolean,

0 commit comments

Comments
 (0)