igniteui-angular-sovn
Version:
Ignite UI for Angular is a dependency-free Angular toolkit for building modern web apps
1,030 lines (830 loc) • 165 kB
text/typescript
import { fakeAsync, TestBed, tick, flush, ComponentFixture } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { IgxGridComponent } from './grid.component';
import { UIInteractions } from '../../test-utils/ui-interactions.spec';
import { configureTestSuite } from '../../test-utils/configure-suite';
import {
IgxNumberFilteringOperand,
IgxStringFilteringOperand
} from '../../data-operations/filtering-condition';
import { GridFunctions } from '../../test-utils/grid-functions.spec';
import { FilteringExpressionsTree, IFilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
import { FilteringLogic } from '../../data-operations/filtering-expression.interface';
import {
IgxGridAdvancedFilteringColumnGroupComponent,
IgxGridAdvancedFilteringComponent,
IgxGridExternalAdvancedFilteringComponent,
IgxGridAdvancedFilteringBindingComponent
} from '../../test-utils/grid-samples.spec';
import { ControlsFunction } from '../../test-utils/controls-functions.spec';
import { FormattedValuesFilteringStrategy } from '../../data-operations/filtering-strategy';
import { IgxHierGridExternalAdvancedFilteringComponent } from '../../test-utils/hierarchical-grid-components.spec';
import { IgxHierarchicalGridComponent } from '../hierarchical-grid/public_api';
const ADVANCED_FILTERING_OPERATOR_LINE_AND_CSS_CLASS = 'igx-filter-tree__line--and';
const ADVANCED_FILTERING_OPERATOR_LINE_OR_CSS_CLASS = 'igx-filter-tree__line--or';
const ADVANCED_FILTERING_OPERATOR_LINE_SELECTED_CSS_CLASS = 'igx-filter-tree__line--selected';
const ADVANCED_FILTERING_TOOLBAR_BUTTON_FILTERED_CSS_CLASS = 'igx-grid-toolbar__adv-filter--filtered';
const ADVANCED_FILTERING_EXPRESSION_ITEM_CLASS = 'igx-filter-tree__expression-item';
const CHIP_SELECT_CLASS = '.igx-chip__select';
describe('IgxGrid - Advanced Filtering #grid - ', () => {
configureTestSuite((() => {
return TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
IgxGridAdvancedFilteringColumnGroupComponent,
IgxGridAdvancedFilteringComponent,
IgxGridExternalAdvancedFilteringComponent,
IgxGridAdvancedFilteringBindingComponent,
IgxHierGridExternalAdvancedFilteringComponent
]
});
}));
describe('General tests - ', () => {
let fix: ComponentFixture<IgxGridAdvancedFilteringComponent>;
let grid: IgxGridComponent;
beforeEach(fakeAsync(() => {
fix = TestBed.createComponent(IgxGridAdvancedFilteringComponent);
grid = fix.componentInstance.grid;
fix.detectChanges();
}));
it('Should show/hide Advanced Filtering button in toolbar based on respective input.', fakeAsync(() => {
// Verify Advanced Filtering button in toolbar is visible.
let advFilterButton = GridFunctions.getAdvancedFilteringButton(fix);
expect(advFilterButton !== null && advFilterButton !== undefined).toBe(true, 'Adv.Filter button is not visible.');
grid.allowAdvancedFiltering = false;
fix.detectChanges();
// Verify Advanced Filtering button in toolbar is not visible.
advFilterButton = GridFunctions.getAdvancedFilteringButton(fix);
expect(advFilterButton !== null && advFilterButton !== undefined).toBe(false, 'Adv.Filter button is visible.');
grid.allowAdvancedFiltering = true;
fix.detectChanges();
// Verify Advanced Filtering button in toolbar is visible.
advFilterButton = GridFunctions.getAdvancedFilteringButton(fix);
expect(advFilterButton !== null && advFilterButton !== undefined).toBe(true, 'Adv.Filter button is not visible.');
}));
it('Should correctly initialize the Advanced Filtering dialog.', fakeAsync(() => {
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Verify AF dialog is opened.
expect(GridFunctions.getAdvancedFilteringComponent(fix)).not.toBeNull();
// Verify there are not filters present and that the default text is shown.
expect(grid.advancedFilteringExpressionsTree).toBeUndefined();
expect(GridFunctions.getAdvancedFilteringTreeRootGroup(fix)).toBeNull();
expect(GridFunctions.getAdvancedFilteringEmptyPrompt(fix)).not.toBeNull();
// Close Advanced Filtering dialog.
GridFunctions.clickAdvancedFilteringCancelButton(fix);
tick(200);
fix.detectChanges();
// Verify AF dialog is closed.
expect(GridFunctions.getAdvancedFilteringComponent(fix)).toBeNull();
}));
it('Should open/close Advanced Filtering dialog through API.', fakeAsync(() => {
// Open dialog through API.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Verify AF dialog is opened.
expect(GridFunctions.getAdvancedFilteringComponent(fix)).not.toBeNull();
// Close dialog through API.
grid.closeAdvancedFilteringDialog(false);
tick(100);
fix.detectChanges();
// Verify AF dialog is closed.
expect(GridFunctions.getAdvancedFilteringComponent(fix)).toBeNull();
}));
it('Should close Advanced Filtering dialog through API by respecting \'applyChanges\' argument.', fakeAsync(() => {
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Click the initial 'Add And Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
// Populate edit inputs.
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
selectOperatorInEditModeExpression(fix, 2); // Select 'Starts With' operator.
let input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
UIInteractions.clickAndSendInputElementValue(input, 'ign', fix); // Type filter value.
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Close dialog through API.
grid.closeAdvancedFilteringDialog(true);
tick(100);
fix.detectChanges();
// Verify AF dialog is closed.
expect(GridFunctions.getAdvancedFilteringComponent(fix)).toBeNull();
// Verify the filter changes are applied.
expect(grid.filteredData.length).toEqual(2);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('Ignite UI for Angular');
// Open the dialog again.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Double-click the existing chip to enter edit mode.
GridFunctions.clickAdvancedFilteringTreeExpressionChip(fix, [0], true);
tick(50);
fix.detectChanges();
// Edit the filter value.
input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
UIInteractions.clickAndSendInputElementValue(input, 'some non-existing value', fix); // Type filter value.
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Close dialog through API.
grid.closeAdvancedFilteringDialog(false);
tick(100);
fix.detectChanges();
// Verify AF dialog is closed.
expect(GridFunctions.getAdvancedFilteringComponent(fix)).toBeNull();
// Verify the filter changes are NOT applied.
expect(grid.filteredData.length).toEqual(2);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('Ignite UI for Angular');
}));
it('Should show/hide initial adding buttons depending on the existence of groups.', fakeAsync(() => {
// Open Advanced Filtering dialog.
GridFunctions.clickAdvancedFilteringButton(fix);
fix.detectChanges();
// Verify that the initial buttons are visible.
expect(GridFunctions.getAdvancedFilteringInitialAddGroupButtons(fix).length).toBe(2);
// Click the initial 'Add And Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
// Verify that the initial buttons are not visible.
expect(GridFunctions.getAdvancedFilteringInitialAddGroupButtons(fix).length).toBe(0);
// Discard the new group and verify that the initial buttons are visible.
GridFunctions.clickAdvancedFilteringExpressionCloseButton(fix);
fix.detectChanges();
expect(GridFunctions.getAdvancedFilteringInitialAddGroupButtons(fix).length).toBe(2);
// Click the initial 'Add Or Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 1);
tick(100);
fix.detectChanges();
// Verify that the initial buttons are not visible.
expect(GridFunctions.getAdvancedFilteringInitialAddGroupButtons(fix).length).toBe(0);
}));
it('Should correctly initialize a newly added \'And\' group.', fakeAsync(() => {
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Click the initial 'Add And Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
// Verify there is a new root group, which is empty.
const group = GridFunctions.getAdvancedFilteringTreeRootGroup(fix);
expect(group).not.toBeNull('There is no root group.');
expect(GridFunctions.getAdvancedFilteringTreeChildItems(group).length).toBe(0, 'The group has children.');
// Verify the operator line of the root group is an 'And' line.
verifyOperatorLine(GridFunctions.getAdvancedFilteringTreeRootGroupOperatorLine(fix), 'and');
// Verify the enabled/disabled state of each input of the expression in edit mode.
verifyEditModeExpressionInputStates(fix, true, false, false, false);
// Verify the edit inputs are empty.
verifyEditModeExpressionInputValues(fix, '', '', '');
// Verify adding buttons are disabled.
const buttons = GridFunctions.getAdvancedFilteringTreeRootGroupButtons(fix, 0);
for (const button of buttons) {
ControlsFunction.verifyButtonIsDisabled(button);
}
}));
it('Should correctly initialize a newly added \'Or\' group.', fakeAsync(() => {
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Click the initial 'Add Or Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 1);
tick(100);
fix.detectChanges();
// Verify there is a new root group, which is empty.
const group = GridFunctions.getAdvancedFilteringTreeRootGroup(fix);
expect(group).not.toBeNull('There is no root group.');
expect(GridFunctions.getAdvancedFilteringTreeChildItems(group).length).toBe(0, 'The group has children.');
// Verify the operator line of the root group is an 'Or' line.
verifyOperatorLine(GridFunctions.getAdvancedFilteringTreeRootGroupOperatorLine(fix), 'or');
// Verify the enabled/disabled state of each input of the expression in edit mode.
verifyEditModeExpressionInputStates(fix, true, false, false, false);
// Verify the edit inputs are empty.
verifyEditModeExpressionInputValues(fix, '', '', '');
// Verify adding buttons are disabled.
const buttons = GridFunctions.getAdvancedFilteringTreeRootGroupButtons(fix, 0);
for (const button of buttons) {
ControlsFunction.verifyButtonIsDisabled(button);
}
}));
it('Should add a new group through initial adding button and filter by it.', fakeAsync(() => {
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Click the initial 'Add And Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
// Verify the enabled/disabled state of each input of the expression in edit mode.
verifyEditModeExpressionInputStates(fix, true, false, false, false);
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
verifyEditModeExpressionInputStates(fix, true, true, false, false);
selectOperatorInEditModeExpression(fix, 2); // Select 'Starts With' operator.
verifyEditModeExpressionInputStates(fix, true, true, true, false);
const input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
UIInteractions.clickAndSendInputElementValue(input, 'ign', fix); // Type filter value.
tick();
fix.detectChanges();
verifyEditModeExpressionInputStates(fix, true, true, true, true);
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Verify the new expression has been added to the group.
const group = GridFunctions.getAdvancedFilteringTreeRootGroup(fix);
expect(GridFunctions.getAdvancedFilteringTreeChildExpressions(group).length).toBe(1, 'Incorrect children count.');
// Apply the filters.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
fix.detectChanges();
// Verify the filter results.
expect(grid.filteredData.length).toEqual(2);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('Ignite UI for Angular');
}));
it('Should update the Advanced Filtering button in toolbar when (filtering)/(clear filtering).',
fakeAsync(() => {
// Verify that the advanced filtering button indicates there are no filters.
let advFilterBtn = GridFunctions.getAdvancedFilteringButton(fix);
expect(advFilterBtn.classList.contains(ADVANCED_FILTERING_TOOLBAR_BUTTON_FILTERED_CSS_CLASS))
.toBe(false, 'Button indicates there is active filtering.');
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Click the initial 'Add And Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
// Populate edit inputs.
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
selectOperatorInEditModeExpression(fix, 0); // Select 'Contains' operator.
const input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
UIInteractions.clickAndSendInputElementValue(input, 'angular', fix); // Type filter value.
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Apply the filters.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
fix.detectChanges();
// Verify that the advanced filtering button indicates there are filters.
advFilterBtn = GridFunctions.getAdvancedFilteringButton(fix);
expect(advFilterBtn.classList.contains(ADVANCED_FILTERING_TOOLBAR_BUTTON_FILTERED_CSS_CLASS))
.toBe(true, 'Button indicates there is no active filtering.');
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Clear the filters.
GridFunctions.clickAdvancedFilteringClearFilterButton(fix);
fix.detectChanges();
// Close the dialog.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
fix.detectChanges();
// Verify that the advanced filtering button indicates there are no filters.
advFilterBtn = GridFunctions.getAdvancedFilteringButton(fix);
expect(advFilterBtn.classList.contains(ADVANCED_FILTERING_TOOLBAR_BUTTON_FILTERED_CSS_CLASS))
.toBe(false, 'Button indicates there is active filtering.');
}));
it('The Clear/Cancel/Apply buttons type should be set to "button"', () => {
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Get Clear/Cancel/Apply buttons types.
const clearButtonType = GridFunctions.getAdvancedFilteringClearFilterButton(fix).getAttributeNode('type').value;
const cancelButtonType = GridFunctions.getAdvancedFilteringCancelButton(fix).getAttributeNode('type').value;
const applyButtonType = GridFunctions.getAdvancedFilteringApplyButton(fix).getAttributeNode('type').value;
const expectedButtonType = 'button';
// Verify buttons type is set to "button".
expect(clearButtonType).toBe(expectedButtonType, 'Clear button type is not "button"');
expect(cancelButtonType).toBe(expectedButtonType, 'Cancel button type is not "button"');
expect(applyButtonType).toBe(expectedButtonType, 'Apply button type is not "button"');
});
it('Should correctly display header name in select dropdown and in chip expression.', fakeAsync(() => {
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Click the initial 'Add And Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
// Open column dropdown and verify header name is displayed for first item
GridFunctions.clickAdvancedFilteringColumnSelect(fix);
fix.detectChanges();
const dropdownItems = GridFunctions.getAdvancedFilteringSelectDropdownItems(fix);
expect(dropdownItems[0].innerText).toBe('HeaderID');
selectColumnInEditModeExpression(fix, 0); // Select 'HeaderID' column
selectOperatorInEditModeExpression(fix, 0); // Select 'Contains' operator.
const input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
UIInteractions.clickAndSendInputElementValue(input, 'a', fix); // Type filter value.
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Verify header name in chip text
verifyExpressionChipContent(fix, [0], 'HeaderID', 'Contains', 'a');
// Apply the filters.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
fix.detectChanges();
// Close Advanced Filtering dialog.
GridFunctions.clickAdvancedFilteringCancelButton(fix);
tick(100);
fix.detectChanges();
// Open Advanced Filtering dialog again.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Verify header name in chip text
verifyExpressionChipContent(fix, [0], 'HeaderID', 'Contains', 'a');
}));
it('Should correctly filter by a \'string\' column through UI.', fakeAsync(() => {
// Test prerequisites
grid.height = '800px';
fix.detectChanges();
tick(50);
// Verify no filters are present.
expect(grid.filteredData).toBeNull();
expect(grid.rowList.length).toBe(8);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('NetAdvantage');
// Open Advanced Filtering dialog.
GridFunctions.clickAdvancedFilteringButton(fix);
fix.detectChanges();
// Click the initial 'Add And Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
selectOperatorInEditModeExpression(fix, 2); // Select 'Starts With' operator.
const input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
UIInteractions.clickAndSendInputElementValue(input, 'ign', fix); // Type filter value.
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Apply the filters.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
fix.detectChanges();
// Verify the filter results.
expect(grid.filteredData.length).toEqual(2);
expect(grid.rowList.length).toBe(2);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('Ignite UI for Angular');
}));
it('Should correctly filter by a \'Greater Than\' with \'number\' column through UI.', fakeAsync(() => {
// Test prerequisites
grid.height = '800px';
fix.detectChanges();
tick(50);
// Verify no filters are present.
expect(grid.filteredData).toBeNull();
expect(grid.rowList.length).toBe(8);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('NetAdvantage');
// Open Advanced Filtering dialog.
GridFunctions.clickAdvancedFilteringButton(fix);
fix.detectChanges();
// Click the initial 'Add And Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
selectColumnInEditModeExpression(fix, 2); // Select 'Downloads' column.
selectOperatorInEditModeExpression(fix, 2); // Select 'Greater Than' operator.
const input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
UIInteractions.clickAndSendInputElementValue(input, '20', fix); // Type filter value.
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Apply the filters.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
fix.detectChanges();
// Verify the filter results.
expect(grid.filteredData.length).toEqual(5);
expect(grid.rowList.length).toBe(5);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('NetAdvantage');
}));
it('Should correctly filter by a \'Equals\' with \'number\' column through UI.', fakeAsync(() => {
// Test prerequisites
grid.height = '800px';
fix.detectChanges();
tick(50);
// Verify no filters are present.
expect(grid.filteredData).toBeNull();
expect(grid.rowList.length).toBe(8);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('NetAdvantage');
// Open Advanced Filtering dialog.
GridFunctions.clickAdvancedFilteringButton(fix);
fix.detectChanges();
// Click the initial 'Add And Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
selectColumnInEditModeExpression(fix, 2); // Select 'Downloads' column.
selectOperatorInEditModeExpression(fix, 0); // Select 'Equals' operator.
const input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
UIInteractions.clickAndSendInputElementValue(input, '127', fix); // Type filter value.
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Apply the filters.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
fix.detectChanges();
// Verify the filter results.
expect(grid.filteredData.length).toEqual(1);
expect(grid.rowList.length).toBe(1);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('NetAdvantage');
}));
it('Should correctly filter by a \'boolean\' column through UI.', fakeAsync(() => {
// Test prerequisites
grid.height = '800px';
fix.detectChanges();
tick(50);
// Verify no filters are present.
expect(grid.filteredData).toBeNull();
expect(grid.rowList.length).toBe(8);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('NetAdvantage');
// Open Advanced Filtering dialog.
GridFunctions.clickAdvancedFilteringButton(fix);
fix.detectChanges();
// Click the initial 'Add And Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
selectColumnInEditModeExpression(fix, 3); // Select 'Released' column.
selectOperatorInEditModeExpression(fix, 1); // Select 'True' operator.
verifyEditModeExpressionInputStates(fix, true, true, false, true); // Third input should be disabled for unary operators.
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Apply the filters.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
fix.detectChanges();
// Verify the filter results.
expect(grid.filteredData.length).toEqual(3);
expect(grid.rowList.length).toBe(3);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('NetAdvantage');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe(null);
}));
it('Should correctly filter by a \'date\' column through UI with unary operator.', fakeAsync(() => {
// Test prerequisites
grid.height = '800px';
fix.detectChanges();
tick(50);
// Verify no filters are present.
expect(grid.filteredData).toBeNull();
expect(grid.rowList.length).toBe(8);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('NetAdvantage');
// Open Advanced Filtering dialog.
GridFunctions.clickAdvancedFilteringButton(fix);
fix.detectChanges();
// Click the initial 'Add And Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
selectColumnInEditModeExpression(fix, 4); // Select 'ReleaseDate' column.
selectOperatorInEditModeExpression(fix, 9); // Select 'This Year' operator.
verifyEditModeExpressionInputStates(fix, true, true, false, true); // Third input should be disabled for unary operators.
const input = GridFunctions.getAdvancedFilteringValueInput(fix, true);
input.click();
fix.detectChanges();
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Apply the filters.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
fix.detectChanges();
// Verify the filter results.
const expectedData = fix.componentInstance.data.filter(r =>
r.ReleaseDate && r.ReleaseDate.getFullYear() === (new Date()).getFullYear());
expect(grid.filteredData.length).toEqual(expectedData.length);
expect(grid.rowList.length).toBe(expectedData.length);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe(expectedData[0].ProductName);
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe(expectedData[1].ProductName);
}));
it('Should correctly filter by a \'date\' column through UI with value from calendar.', fakeAsync(() => {
// Test prerequisites
grid.height = '800px';
fix.detectChanges();
tick(50);
// Verify no filters are present.
expect(grid.filteredData).toBeNull();
expect(grid.rowList.length).toBe(8);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('NetAdvantage');
// Open Advanced Filtering dialog.
GridFunctions.clickAdvancedFilteringButton(fix);
fix.detectChanges();
// Click the initial 'Add And Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
selectColumnInEditModeExpression(fix, 4); // Select 'ReleaseDate' column.
selectOperatorInEditModeExpression(fix, 0); // Select 'Equals' operator.
verifyEditModeExpressionInputStates(fix, true, true, true, false);
const input = GridFunctions.getAdvancedFilteringValueInput(fix, true);
input.click();
fix.detectChanges();
// Click on 'today' item in calendar.
const calendar = GridFunctions.getAdvancedFilteringCalendar(fix);
const todayItem = calendar.querySelector('.igx-calendar__date--current');
todayItem.click();
tick(100);
fix.detectChanges();
verifyEditModeExpressionInputStates(fix, true, true, true, true);
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Apply the filters.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
fix.detectChanges();
// Verify the filter results.
expect(grid.filteredData.length).toEqual(1);
expect(grid.rowList.length).toBe(1);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 0).value.toString()).toBe('8');
flush();
}));
it('Should emit the filteringDone event when applying filters.', fakeAsync(() => {
spyOn(grid.filteringDone, 'emit');
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Click the initial 'Add And Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
// Populate edit inputs.
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
selectOperatorInEditModeExpression(fix, 2); // Select 'Starts With' operator.
const input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
UIInteractions.clickAndSendInputElementValue(input, 'ign', fix); // Type filter value.
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Apply the filters.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
tick(100);
fix.detectChanges();
expect(grid.filteringDone.emit).toHaveBeenCalledWith(grid.advancedFilteringExpressionsTree);
}));
it('Applying/Clearing filter through the API should correctly update the UI.', fakeAsync(() => {
// Test prerequisites
grid.height = '800px';
fix.detectChanges();
tick(50);
// Verify the initial state of the grid and that no filters are present.
expect(grid.filteredData).toBeNull();
expect(grid.rowList.length).toBe(8);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('NetAdvantage');
// Apply advanced filter through API.
const tree = new FilteringExpressionsTree(FilteringLogic.And);
tree.filteringOperands.push({
fieldName: 'Downloads', searchVal: 100, condition: IgxNumberFilteringOperand.instance().condition('greaterThan')
});
const orTree = new FilteringExpressionsTree(FilteringLogic.Or);
orTree.filteringOperands.push({
fieldName: 'ProductName', searchVal: 'angular', condition: IgxStringFilteringOperand.instance().condition('contains'),
ignoreCase: true
});
orTree.filteringOperands.push({
fieldName: 'ProductName', searchVal: 'script', condition: IgxStringFilteringOperand.instance().condition('contains'),
ignoreCase: true
});
tree.filteringOperands.push(orTree);
grid.advancedFilteringExpressionsTree = tree;
fix.detectChanges();
// Verify the state of the grid after filtering.
expect(grid.filteredData.length).toBe(2);
expect(grid.rowList.length).toBe(2);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('Some other item with Script');
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Verfiy there is a root group with 'And' operator line and 2 children.
const rootGroup = GridFunctions.getAdvancedFilteringTreeRootGroup(fix);
expect(rootGroup).not.toBeNull();
verifyOperatorLine(GridFunctions.getAdvancedFilteringTreeRootGroupOperatorLine(fix), 'and');
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup).length).toBe(2);
// Verify the contnet of the first child (expression) of the root group.
verifyExpressionChipContent(fix, [0], 'Downloads', 'Greater Than', '100');
// Verify the content of the second child (group) of the root group.
const group = GridFunctions.getAdvancedFilteringTreeItem(fix, [1]);
expect(GridFunctions.getAdvancedFilteringTreeChildItems(group, false).length).toBe(2);
verifyExpressionChipContent(fix, [1, 0], 'ProductName', 'Contains', 'angular');
verifyExpressionChipContent(fix, [1, 1], 'ProductName', 'Contains', 'script');
// Verify the operator line of the child group.
verifyOperatorLine(GridFunctions.getAdvancedFilteringTreeGroupOperatorLine(fix, [1]), 'or');
// Close Advanced Filtering dialog.
GridFunctions.clickAdvancedFilteringCancelButton(fix);
tick(100);
fix.detectChanges();
// Clear filters through API.
grid.advancedFilteringExpressionsTree = null;
fix.detectChanges();
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Verify there are not filters present and that the default text is shown.
expect(grid.advancedFilteringExpressionsTree).toBeNull();
expect(GridFunctions.getAdvancedFilteringTreeRootGroup(fix)).toBeNull();
expect(GridFunctions.getAdvancedFilteringEmptyPrompt(fix)).not.toBeNull();
}));
it('Applying/Clearing filter through the UI should correctly update the API.', fakeAsync(() => {
// Test prerequisites
grid.height = '800px';
fix.detectChanges();
tick(50);
// Verify the initial state of the grid and that no filters are present.
expect(grid.advancedFilteringExpressionsTree).toBeUndefined();
expect(grid.filteredData).toBeNull();
expect(grid.rowList.length).toBe(8);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('NetAdvantage');
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Add a root 'and' group.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
// Populate edit inputs.
selectColumnInEditModeExpression(fix, 2); // Select 'Downloads' column.
selectOperatorInEditModeExpression(fix, 2); // Select 'Greater Than' operator.
let input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
UIInteractions.clickAndSendInputElementValue(input, '100', fix); // Type filter value.
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Add a child 'or' group.
const addOrGroupBtn = GridFunctions.getAdvancedFilteringTreeRootGroupButtons(fix, 0)[2];
addOrGroupBtn.click();
tick(100);
fix.detectChanges();
// Populate edit inputs.
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
selectOperatorInEditModeExpression(fix, 0); // Select 'Contains' operator.
input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
UIInteractions.clickAndSendInputElementValue(input, 'angular', fix); // Type filter value.
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Add new expression to the child group.
const addExpressionBtn = GridFunctions.getAdvancedFilteringTreeGroupButtons(fix, [1], 0)[0];
addExpressionBtn.click();
tick(100);
fix.detectChanges();
// Populate edit inputs.
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
selectOperatorInEditModeExpression(fix, 0); // Select 'Contains' operator.
input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
UIInteractions.clickAndSendInputElementValue(input, 'script', fix); // Type filter value.
// Commit the populated expression.
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
fix.detectChanges();
// Apply the filters.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
tick(100);
fix.detectChanges();
// Verify the state of the grid after the filtering.
expect(grid.advancedFilteringExpressionsTree !== null && grid.advancedFilteringExpressionsTree !== undefined).toBe(true);
expect(grid.filteredData.length).toBe(2);
expect(grid.rowList.length).toBe(2);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('Some other item with Script');
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
tick(100);
fix.detectChanges();
// Clear the filters.
GridFunctions.clickAdvancedFilteringClearFilterButton(fix);
tick(100);
fix.detectChanges();
// Verify that no filters are present.
expect(grid.advancedFilteringExpressionsTree).toBeNull();
expect(grid.filteredData).toBeNull();
expect(grid.rowList.length).toBe(8);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('NetAdvantage');
}));
it('Should discard the newly added group when clicking the \'close\' button of its initial condition.', fakeAsync(() => {
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Click the initial 'Add And Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
// Verify there is a new group and the initial buttons are not visible.
expect(GridFunctions.getAdvancedFilteringTreeRootGroup(fix)).not.toBeNull();
expect(GridFunctions.getAdvancedFilteringInitialAddGroupButtons(fix).length).toBe(0);
// Populate edit inputs
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
selectOperatorInEditModeExpression(fix, 2); // Select 'Starts With' operator.
const input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
UIInteractions.clickAndSendInputElementValue(input, 'ign', fix); // Type filter value.
// Discard the populated expression, so the whole new group gets discarded.
GridFunctions.clickAdvancedFilteringExpressionCloseButton(fix);
fix.detectChanges();
// Verify there are no groups in the dialog and the initial buttons are visible.
expect(GridFunctions.getAdvancedFilteringTreeRootGroup(fix)).toBeNull();
expect(GridFunctions.getAdvancedFilteringInitialAddGroupButtons(fix).length).toBe(2);
}));
it('Should apply filters on Apply button click without prior Commit button click', fakeAsync(() => {
grid.openAdvancedFilteringDialog();
fix.detectChanges();
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
selectOperatorInEditModeExpression(fix, 2); // Select 'Starts With' operator.
const input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
UIInteractions.clickAndSendInputElementValue(input, 'ign', fix); // Type filter value.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
tick(100);
fix.detectChanges();
// Verify the filter results.
expect(grid.filteredData.length).toEqual(2);
expect(grid.rowList.length).toBe(2);
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('Ignite UI for Angular');
}));
it('Should close the dialog on Apply button click if not all expression inputs are set', fakeAsync(() => {
grid.openAdvancedFilteringDialog();
fix.detectChanges();
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
GridFunctions.clickAdvancedFilteringApplyButton(fix);
tick(100);
fix.detectChanges();
// Verify the dialog is closed an no records are filtered
expect(GridFunctions.getAdvancedFilteringComponent(fix)).toBeNull();
expect(grid.filteredData).toBe(null);
grid.openAdvancedFilteringDialog();
fix.detectChanges();
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
tick(100);
fix.detectChanges();
expect(GridFunctions.getAdvancedFilteringComponent(fix)).toBeNull();
expect(grid.filteredData).toBe(null);
grid.openAdvancedFilteringDialog();
fix.detectChanges();
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
selectOperatorInEditModeExpression(fix, 2); // Select 'Starts With' operator.
GridFunctions.clickAdvancedFilteringApplyButton(fix);
tick(100);
fix.detectChanges();
expect(GridFunctions.getAdvancedFilteringComponent(fix)).toBeNull();
expect(grid.filteredData).toBe(null);
}));
it('Column dropdown should contain only filterable columns.', fakeAsync(() => {
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Make the 'Downloads', 'Released' and 'ReleaseDate' columns non-filterable.
grid.getColumnByName('Downloads').filterable = false;
grid.getColumnByName('Released').filterable = false;
grid.getColumnByName('ReleaseDate').filterable = false;
grid.cdr.detectChanges();
tick(100);
// Click the initial 'Add and Group' button.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
// Open column dropdown and verify that only filterable columns are present.
GridFunctions.clickAdvancedFilteringColumnSelect(fix);
fix.detectChanges();
const dropdownItems = GridFunctions.getAdvancedFilteringSelectDropdownItems(fix);
expect(dropdownItems.length).toBe(3);
expect(dropdownItems[0].innerText).toBe('HeaderID');
expect(dropdownItems[1].innerText).toBe('ProductName');
expect(dropdownItems[2].innerText).toBe('Another Field');
}));
it('Operator dropdown should contain operators based on the column\'s datatype (\'string\' or \'number\').', fakeAsync(() => {
// Open Advanced Filtering dialog.
grid.openAdvancedFilteringDialog();
fix.detectChanges();
// Add a new group.
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
tick(100);
fix.detectChanges();
// Select 'string' type column ('ProductName').
selectColumnInEditModeExpression(fix, 1);
// Open the operator dropdown and verify they are 'string' specific.
GridFunctions.clickAdvancedFilteringOperatorSelect(fix);
fix.detectChanges();
let dropdownValues: string[] = GridFunctions.getAdvancedFilteringSelectDropdownItems(fix).map((x: any) => x.innerText);
let expectedValues = ['Contains', 'Does Not Contain', 'Starts With', 'Ends With', 'Equals',
'Does Not Equal', 'Empty', 'Not Empty', 'Null', 'Not Null'];
expect(dropdownValues).toEqual(expectedValues);
// Cl