Skip to content

Commit 842de76

Browse files
committed
test(adv-filtering): expr/group add test #5496
1 parent 7c9ca7e commit 842de76

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed

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

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,181 @@ describe('IgxGrid - Advanced Filtering', () => {
12211221
verifyContextMenuVisibility(fix, false);
12221222
}));
12231223

1224+
it('Should display the adding buttons and the cancel button when trying to add a new condition/group to existing group.',
1225+
fakeAsync(() => {
1226+
// Apply advanced filter through API.
1227+
const tree = new FilteringExpressionsTree(FilteringLogic.And);
1228+
const orTree = new FilteringExpressionsTree(FilteringLogic.Or);
1229+
orTree.filteringOperands.push({
1230+
fieldName: 'ProductName', searchVal: 'angular', condition: IgxStringFilteringOperand.instance().condition('contains'),
1231+
ignoreCase: true
1232+
});
1233+
orTree.filteringOperands.push({
1234+
fieldName: 'ProductName', searchVal: 'script', condition: IgxStringFilteringOperand.instance().condition('contains'),
1235+
ignoreCase: true
1236+
});
1237+
tree.filteringOperands.push(orTree);
1238+
grid.advancedFilteringExpressionsTree = tree;
1239+
fix.detectChanges();
1240+
1241+
// Open Advanced Filtering dialog.
1242+
GridFunctions.clickAdvancedFilteringButton(fix);
1243+
fix.detectChanges();
1244+
1245+
// Select a chip from the child group.
1246+
GridFunctions.clickAdvancedFilteringTreeExpressionChip(fix, [0, 0]);
1247+
tick(200);
1248+
fix.detectChanges();
1249+
// Click the add icon to display the adding buttons.
1250+
GridFunctions.clickAdvancedFilteringTreeExpressionChipAddIcon(fix, [0, 0]);
1251+
fix.detectChanges();
1252+
1253+
// Verify the adding buttons and cancel button are visible and enabled.
1254+
const buttons = GridFunctions.getAdvancedFilteringTreeGroupButtons(fix, [0], 0);
1255+
expect(buttons.length).toBe(4);
1256+
for (const button of buttons) {
1257+
expect(button.classList.contains('igx-button--disabled')).toBe(false);
1258+
}
1259+
1260+
// Click the cancel button to hide the buttons.
1261+
const cancelButton = buttons[3];
1262+
cancelButton.click();
1263+
fix.detectChanges();
1264+
1265+
// Verify the adding buttons and cancel button are no longer visible.
1266+
const group = GridFunctions.getAdvancedFilteringTreeItem(fix, [0]);
1267+
const childrenContainer = group.querySelector('.igx-filter-tree__expression');
1268+
const buttonsContainers = childrenContainer.querySelectorAll(':scope > .igx-filter-tree__buttons');
1269+
expect(buttonsContainers.length).toBe(0, 'Adding buttons are visible.');
1270+
}));
1271+
1272+
it('Should add a new condition to existing group by using add buttons.', fakeAsync(() => {
1273+
// Apply advanced filter through API.
1274+
const tree = new FilteringExpressionsTree(FilteringLogic.And);
1275+
const orTree = new FilteringExpressionsTree(FilteringLogic.Or);
1276+
orTree.filteringOperands.push({
1277+
fieldName: 'ProductName', searchVal: 'angular', condition: IgxStringFilteringOperand.instance().condition('contains'),
1278+
ignoreCase: true
1279+
});
1280+
orTree.filteringOperands.push({
1281+
fieldName: 'ProductName', searchVal: 'script', condition: IgxStringFilteringOperand.instance().condition('contains'),
1282+
ignoreCase: true
1283+
});
1284+
tree.filteringOperands.push(orTree);
1285+
grid.advancedFilteringExpressionsTree = tree;
1286+
fix.detectChanges();
1287+
1288+
// Open Advanced Filtering dialog.
1289+
GridFunctions.clickAdvancedFilteringButton(fix);
1290+
fix.detectChanges();
1291+
1292+
// Verify group's children count before adding a new child.
1293+
let group = GridFunctions.getAdvancedFilteringTreeItem(fix, [0]);
1294+
let groupDirectChildren = GridFunctions.getAdvancedFilteringTreeChildItems(group);
1295+
expect(groupDirectChildren.length).toBe(2, 'incorrect direct children count of inner group');
1296+
1297+
// Select chip from group and click the add button.
1298+
GridFunctions.clickAdvancedFilteringTreeExpressionChip(fix, [0, 0]);
1299+
tick(200);
1300+
fix.detectChanges();
1301+
GridFunctions.clickAdvancedFilteringTreeExpressionChipAddIcon(fix, [0, 0]);
1302+
fix.detectChanges();
1303+
1304+
// Add new 'expression'.
1305+
const buttons = GridFunctions.getAdvancedFilteringTreeGroupButtons(fix, [0], 0);
1306+
buttons[0].click();
1307+
fix.detectChanges();
1308+
1309+
// Populate edit inputs.
1310+
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
1311+
selectOperatorInEditModeExpression(fix, 0); // Select 'Contains' operator.
1312+
const input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
1313+
sendInputNativeElement(fix, input, 'some value'); // Type filter value.
1314+
// Commit the populated expression.
1315+
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
1316+
fix.detectChanges();
1317+
1318+
// Verify group's children count before adding a new child.
1319+
group = GridFunctions.getAdvancedFilteringTreeItem(fix, [0]);
1320+
groupDirectChildren = GridFunctions.getAdvancedFilteringTreeChildItems(group);
1321+
expect(groupDirectChildren.length).toBe(3, 'incorrect direct children count of inner group');
1322+
}));
1323+
1324+
it('Should add a new group to existing group by using add buttons.', fakeAsync(() => {
1325+
// Apply advanced filter through API.
1326+
const tree = new FilteringExpressionsTree(FilteringLogic.And);
1327+
const orTree = new FilteringExpressionsTree(FilteringLogic.Or);
1328+
orTree.filteringOperands.push({
1329+
fieldName: 'ProductName', searchVal: 'angular', condition: IgxStringFilteringOperand.instance().condition('contains'),
1330+
ignoreCase: true
1331+
});
1332+
orTree.filteringOperands.push({
1333+
fieldName: 'ProductName', searchVal: 'script', condition: IgxStringFilteringOperand.instance().condition('contains'),
1334+
ignoreCase: true
1335+
});
1336+
tree.filteringOperands.push(orTree);
1337+
grid.advancedFilteringExpressionsTree = tree;
1338+
fix.detectChanges();
1339+
1340+
// Open Advanced Filtering dialog.
1341+
GridFunctions.clickAdvancedFilteringButton(fix);
1342+
fix.detectChanges();
1343+
1344+
// Verify group's children count before adding a new child.
1345+
let group = GridFunctions.getAdvancedFilteringTreeItem(fix, [0]);
1346+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(group, true).length).toBe(2,
1347+
'incorrect direct children count of group with path [0]');
1348+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(group, false).length).toBe(2,
1349+
'incorrect all children count of group with path [0]');
1350+
1351+
// Select chip from group and click the add button.
1352+
GridFunctions.clickAdvancedFilteringTreeExpressionChip(fix, [0, 0]);
1353+
tick(200);
1354+
fix.detectChanges();
1355+
GridFunctions.clickAdvancedFilteringTreeExpressionChipAddIcon(fix, [0, 0]);
1356+
fix.detectChanges();
1357+
1358+
// Add new 'and group'.
1359+
let buttons = GridFunctions.getAdvancedFilteringTreeGroupButtons(fix, [0], 0);
1360+
buttons[1].click();
1361+
fix.detectChanges();
1362+
1363+
// Populate edit inputs.
1364+
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
1365+
selectOperatorInEditModeExpression(fix, 0); // Select 'Contains' operator.
1366+
let input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
1367+
sendInputNativeElement(fix, input, 'some value'); // Type filter value.
1368+
// Commit the populated expression.
1369+
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
1370+
fix.detectChanges();
1371+
1372+
// Add new 'expression' to the newly added group.
1373+
buttons = GridFunctions.getAdvancedFilteringTreeGroupButtons(fix, [0, 1], 0);
1374+
buttons[0].click();
1375+
fix.detectChanges();
1376+
1377+
// Populate edit inputs.
1378+
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
1379+
selectOperatorInEditModeExpression(fix, 0); // Select 'Contains' operator.
1380+
input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
1381+
sendInputNativeElement(fix, input, 'another value'); // Type filter value.
1382+
// Commit the populated expression.
1383+
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
1384+
fix.detectChanges();
1385+
1386+
// End the newly added group.
1387+
buttons = GridFunctions.getAdvancedFilteringTreeGroupButtons(fix, [0, 1], 0);
1388+
buttons[3].click();
1389+
fix.detectChanges();
1390+
1391+
// Verify group's children count before adding a new child.
1392+
group = GridFunctions.getAdvancedFilteringTreeItem(fix, [0]);
1393+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(group, true).length).toBe(3,
1394+
'incorrect direct children count of group with path [0]');
1395+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(group, false).length).toBe(5,
1396+
'incorrect all children count of group with path [0]');
1397+
}));
1398+
12241399
describe('Localization', () => {
12251400
it('Should correctly change resource strings for Advanced Filtering dialog.', fakeAsync(() => {
12261401
fix = TestBed.createComponent(IgxGridAdvancedFilteringComponent);

0 commit comments

Comments
 (0)