Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ describe('IgxDateRangePicker', () => {
const elementRef = { nativeElement: null };

let onChangeFn: ReturnType<typeof vi.fn>;
let _onTouchedFn: ReturnType<typeof vi.fn>;
let onTouchedFn: ReturnType<typeof vi.fn>;
let onValidatorChangeFn: ReturnType<typeof vi.fn>;

beforeEach(async () => {
onChangeFn = vi.fn().mockName('NgControl.onChange');
_onTouchedFn = vi.fn().mockName('NgControl.onTouched');
onTouchedFn = vi.fn().mockName('NgControl.onTouched');
onValidatorChangeFn = vi.fn().mockName('NgControl.onValidatorChange');

await TestBed.configureTestingModule({
Expand Down Expand Up @@ -162,6 +162,16 @@ describe('IgxDateRangePicker', () => {
dateRange.setDisabledState(false);
expect(dateRange.disabled).toBe(false);
});

it('calls the onTouched callback on input blur and leaves the validity state untouched when no form control is bound', () => {
dateRange.registerOnTouched(onTouchedFn);
const input = fixture.debugElement.query(By.css(CSS_CLASS_INPUT));

input.nativeElement.dispatchEvent(new FocusEvent('blur'));

expect(onTouchedFn).toHaveBeenCalledTimes(1);
expect(dateRange.inputDirective.valid).toBe(IgxInputState.INITIAL);
});
});

describe('clear()', () => {
Expand Down Expand Up @@ -997,6 +1007,21 @@ describe('IgxDateRangePicker', () => {
detectChanges();
});

it('should clear the calendar selection when the value is cleared while it\'s open', async () => {
dateRange.value = { start: new Date(2025, 1, 3), end: new Date(2025, 1, 5) };
dateRange.open();
await vi.runAllTimersAsync();
detectChanges();

const rangeCalendar = (dateRange as any).calendar;
expect(rangeCalendar.selectedDates.length).toBeGreaterThan(0);

dateRange.value = null;
detectChanges();

expect(rangeCalendar.selectedDates).toEqual([]);
});

it('should set initial validity state when the form group is disabled', () => {
const fix = TestBed.createComponent(DateRangeReactiveFormComponent);
fix.detectChanges();
Expand Down Expand Up @@ -2227,6 +2252,40 @@ describe('IgxDateRangePicker', () => {
expect(dateRange['_calendar'].disabledDates).toEqual(disabledDates);
});

it('should disable calendar dates when min and/or max values as dates are provided', async () => {
fixture = TestBed.createComponent(DateRangeDefaultComponent);
fixture.componentInstance.minValue = new Date(2000, 10, 1);
fixture.componentInstance.maxValue = new Date(2000, 10, 20);
fixture.detectChanges();
dateRange = fixture.componentInstance.dateRange;

dateRange.open();
await vi.runAllTimersAsync();
fixture.detectChanges();

expect(dateRange['_calendar'].disabledDates).toEqual([
{ type: DateRangeType.Before, dateRange: [new Date(2000, 10, 1)] },
{ type: DateRangeType.After, dateRange: [new Date(2000, 10, 20)] }
]);
});

it('should disable calendar dates when min and/or max values as strings are provided', async () => {
fixture = TestBed.createComponent(DateRangeDefaultComponent);
fixture.componentInstance.minValue = '2000-10-01T00:00:00';
fixture.componentInstance.maxValue = '2000-10-30T00:00:00';
fixture.detectChanges();
dateRange = fixture.componentInstance.dateRange;

dateRange.open();
await vi.runAllTimersAsync();
fixture.detectChanges();

expect(dateRange['_calendar'].disabledDates).toEqual([
{ type: DateRangeType.Before, dateRange: [new Date(2000, 9, 1)] },
{ type: DateRangeType.After, dateRange: [new Date(2000, 9, 30)] }
]);
});

it('should initialize activeDate with current date, when not set', async () => {
fixture = TestBed.createComponent(DateRangeDefaultComponent);
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3167,6 +3167,71 @@ describe('igxDrag touch, mouse, pointerLost and shadow root coverage', () => {
});
})

describe('igxDrag window auto-scroll', () => {
let fix: ComponentFixture<TestDragDropComponent>;
let spacer: HTMLElement;
const extraScrollHeight = 100;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [TestDragDropComponent]
}).compileComponents();
});

beforeEach(() => {
// Makes the document a fixed amount taller than the viewport so the window can scroll.
spacer = document.createElement('div');
spacer.style.cssText = `position: absolute; top: 0; left: 0; width: 1px; height: ${window.innerHeight + extraScrollHeight}px;`;
document.body.appendChild(spacer);
window.scrollTo(0, 0);

fix = TestBed.createComponent(TestDragDropComponent);
fix.detectChanges();
});

afterEach(() => {
spacer.remove();
window.scrollTo(0, 0);
});

/** Starts dragging `drag` and moves its ghost within the scroll threshold of the viewport bottom. */
const dragToViewportBottom = async (drag: IgxDragDirective) => {
const element = drag.element.nativeElement;
const rect = getElemRects(element);
const startingX = (rect.left + rect.right) / 2;
const startingY = (rect.top + rect.bottom) / 2;

UIInteractions.simulatePointerEvent('pointerdown', element, startingX, startingY);
await nextFrame();
UIInteractions.simulatePointerEvent('pointermove', element, startingX, window.innerHeight - 10);
expect(drag.ghostElement).toBeTruthy();
};

it('should stop scrolling the window when destroyed while auto-scrolling', async () => {
const firstDrag = fix.componentInstance.dragElems.first;
await dragToViewportBottom(firstDrag);
await vi.waitFor(() => expect(window.scrollY).toBeGreaterThan(0));

// Each scroll step is queued for the next animation frame. Destroying right after one is queued
// runs that step without a ghost, which must not throw.
const step = (firstDrag as any).onScrollContainerStep.bind(firstDrag);
const stepQueued = new Promise<void>(resolve => {
vi.spyOn(firstDrag as any, 'onScrollContainerStep').mockImplementationOnce((direction) => {
step(direction);
resolve();
});
});
await stepQueued;
fix.destroy();
expect(firstDrag.ghostElement).toBeNull();

await nextFrame();
const scrollY = window.scrollY;
await wait(100);
expect(window.scrollY).toBe(scrollY);
});
})

const getDragDirsRects = (dragDirs: QueryList<IgxDragDirective>) => {
const dragDirsRects = [];
dragDirs.forEach((dragDir) => {
Expand Down
18 changes: 12 additions & 6 deletions projects/igniteui-angular/grids/grid/src/column-moving.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('IgxGrid - Column Moving #grid', () => {
const COLUMN_HEADER_CLASS = '.igx-grid-th';
const COLUMN_GROUP_HEADER_CLASS = '.igx-grid-thead__title';
const COLUMN_RESIZE_CLASS = '.igx-grid-th__resize-line';
const GHOST_CLASS = 'igx-grid__drag-ghost-image';

let fixture;
let grid: IgxGridComponent;
Expand Down Expand Up @@ -425,11 +426,14 @@ describe('IgxGrid - Column Moving #grid', () => {
await nextFrame();
UIInteractions.simulatePointerEvent('pointermove', header, 270, 71);
await wait();
expect(document.querySelector(`.${GHOST_CLASS}`)).not.toBeNull();

// step 2 - hit ESCAPE over the headers area and verify column moving is canceled
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
document.dispatchEvent(new KeyboardEvent('keyup', { key: 'Escape' }));
// The moving directive listens for keydown on the window.
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
document.dispatchEvent(new KeyboardEvent('keyup', { key: 'Escape', bubbles: true }));
fixture.detectChanges();
expect(document.querySelector(`.${GHOST_CLASS}`), 'ESCAPE should end the drag').toBeNull();

UIInteractions.simulatePointerEvent('pointerup', header, 270, 71);
await wait();
Expand Down Expand Up @@ -690,14 +694,16 @@ describe('IgxGrid - Column Moving #grid', () => {
await wait();

UIInteractions.simulatePointerEvent('pointermove', header, 156, 71);
await wait();
// The drag directive drops pointer moves within the same animation frame.
await nextFrame();

if (fixture.componentInstance.source.field === 'ID') {
fixture.componentInstance.cancel = true;
}
expect(fixture.componentInstance.source.field).toBe('ID');
expect(document.querySelector(`.${GHOST_CLASS}`)).not.toBeNull();
fixture.componentInstance.cancel = true;

UIInteractions.simulatePointerEvent('pointermove', header, 330, 75);
await nextFrame();
expect(document.querySelector(`.${GHOST_CLASS}`), 'canceling columnMoving should end the drag').toBeNull();
UIInteractions.simulatePointerEvent('pointerup', header, 330, 75);
await wait();
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7732,9 +7732,6 @@ export abstract class IgxGridBaseDirective implements GridType,
for (const col of columnsInView) {
if (!col.autoSize && col.headerCell) {
const cellsContentWidths: number[] = [];
if (col._cells.length !== this.rowList.length) {
this.rowList.forEach(x => x.cdr.detectChanges());
}
const cells = this._dataRowList.map(x => x.cells.find(c => c.column === col));
cells.forEach((cell) => cellsContentWidths.push(cell?.nativeElement?.offsetWidth || 0));
let maxForCells = Math.max(...cellsContentWidths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,34 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {

expect(console.error).not.toHaveBeenCalled();
});

it('Should show the templated ESF again when reopened after the custom dialog was cancelled.', async () => {
const esfComponent = grid.excelStyleFilteringComponent;
const esf: HTMLElement = esfComponent.element.nativeElement;
await GridFunctions.clickExcelFilterIconFromCode(fix, grid, 'Downloads');
expect(esf.isConnected).toBe(true);
const originalDisplay = getComputedStyle(esf).display;
expect(originalDisplay).not.toBe('none');

GridFunctions.clickExcelFilterCascadeButton(fix);
fix.detectChanges();
GridFunctions.clickOperatorFromCascadeMenu(fix, 0);
await fix.whenStable();
fix.detectChanges();
expect(GridFunctions.getExcelStyleCustomFilteringDialog(fix)).not.toBeNull();
expect(getComputedStyle(esf).display).toBe('none');

GridFunctions.clickCancelExcelStyleCustomFiltering(fix);
await fix.whenStable();
fix.detectChanges();

// The ESF declared in the grid template is one instance reused for every opening, so it stays hidden
// unless reopening undoes the hiding done for the dialog.
await GridFunctions.clickExcelFilterIconFromCode(fix, grid, 'ProductName');
expect(esfComponent.column.field).toBe('ProductName');
expect(esf.isConnected).toBe(true);
expect(getComputedStyle(esf).display).toBe(originalDisplay);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SampleTestData } from '../../../test-utils/sample-test-data.spec';
import { By } from '@angular/platform-browser';
import { QueryBuilderFunctions } from '../../../query-builder/src/query-builder/query-builder-functions.spec';
import { IFilteringEventArgs, IgxGridNavigationService, IgxGridToolbarAdvancedFilteringComponent } from 'igniteui-angular/grids/core';
import { FilteringExpressionsTree, FilteringLogic, FormattedValuesFilteringStrategy, IGridResourceStrings, IgxNumberFilteringOperand, IgxStringFilteringOperand } from 'igniteui-angular/core';
import { changei18n, FilteringExpressionsTree, FilteringLogic, FormattedValuesFilteringStrategy, GridResourceStringsEN, IGridResourceStrings, IgxNumberFilteringOperand, IgxStringFilteringOperand } from 'igniteui-angular/core';
import { QueryBuilderSelectors } from 'igniteui-angular/query-builder/src/query-builder/query-builder.common';
import { IgxDateTimeEditorDirective } from 'igniteui-angular/directives';
import { IGridCreatedEventArgs, IgxHierarchicalGridComponent, IgxRowIslandComponent } from 'igniteui-angular/grids/hierarchical-grid';
Expand Down Expand Up @@ -1381,6 +1381,37 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
expect(addingButtons[0].innerText).toBe('add\nMy condition');
expect(addingButtons[1].innerText).toBe('add\nMy group');
});

it('Should update the opened Advanced Filtering dialog when the resource strings change globally.', async () => {
const fix = TestBed.createComponent(IgxGridAdvancedFilteringComponent);
const grid: IgxGridComponent = fix.componentInstance.grid;
const tree = new FilteringExpressionsTree(FilteringLogic.And);
tree.filteringOperands.push({
fieldName: 'ProductName',
condition: IgxStringFilteringOperand.instance().condition('contains'),
searchVal: 'angular',
ignoreCase: true
});
grid.advancedFilteringExpressionsTree = tree;
fix.detectChanges();

grid.openAdvancedFilteringDialog();
fix.detectChanges();
const getAddConditionButtonText = () =>
(QueryBuilderFunctions.getQueryBuilderTreeRootGroupButtons(fix, 0)[0] as HTMLElement).querySelector('span').innerText;
expect(getAddConditionButtonText()).toBe('Condition');

try {
// The dialog passes the grid's advanced filtering strings to the query builder as custom strings,
// which the query builder does not refresh by itself.
changei18n({ igx_grid_advanced_filter_add_condition_root: 'Bedingung' });
fix.detectChanges();

expect(getAddConditionButtonText()).toBe('Bedingung');
} finally {
changei18n(GridResourceStringsEN);
}
});
});

describe('Column groups - ', () => {
Expand Down
26 changes: 26 additions & 0 deletions projects/igniteui-angular/grids/pivot-grid/src/pivot-grid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import {
changei18n,
ColumnPinningPosition,
FilteringExpressionsTree,
FilteringLogic,
GridColumnDataType,
GridResourceStringsEN,
GridSummaryCalculationMode,
IDataCloneStrategy,
IgxStringFilteringOperand,
Expand Down Expand Up @@ -2604,6 +2606,30 @@ describe('IgxPivotGrid #pivotGrid', () => {
expect(dateDimension.resourceStrings.igx_grid_pivot_date_dimension_total).toBe('Custom total');
});

it('should regenerate the date dimension columns when the resource strings change globally.', async () => {
const pivotGrid = fixture.componentInstance.pivotGrid;
// The grid subscribes to resource changes only after its initial columns are generated.
await fixture.whenStable();
pivotGrid.pivotConfiguration = {
columns: [new IgxPivotDateDimension({ memberName: 'Date', enabled: true }, { years: false, months: false, fullDate: false })],
rows: [{ memberName: 'SellerName', enabled: true }],
values: [fixture.componentInstance.pivotConfigHierarchy.values[0]]
};
fixture.detectChanges();
expect(pivotGrid.columns.map(x => x.header)).toEqual(['All Periods']);

try {
changei18n({ igx_grid_pivot_date_dimension_total: 'Alle Perioden' });
// The columns are regenerated asynchronously after the resource change.
await vi.waitFor(() => expect(pivotGrid.columns.map(x => x.header)).toEqual(['Alle Perioden']));
fixture.detectChanges();

expect(GridFunctions.getColumnHeaderTitleByIndex(fixture, 0).innerText).toBe('Alle Perioden');
} finally {
changei18n(GridResourceStringsEN);
}
});

it('should sort row dimensions with date values.', () => {
const pivotGrid = fixture.componentInstance.pivotGrid;
pivotGrid.pivotConfiguration.rows = [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1471,9 +1471,13 @@ describe('IgxTreeGrid - Selection #tGrid', () => {
searchVal: 299
}
];
const filtered = filteringDone(treeGrid);
treeGrid.filter('ID', null, expressionTree);
// Let the pipes filter the rows before filteringDone fires, as change detection does in an app;
// otherwise 317 still has visible children when its cascade state is updated.
fix.detectChanges();

await nextFrame();
await filtered;
fix.detectChanges();

expect(getVisibleSelectedRows(fix).length).toBe(1);
Expand Down
Loading
Loading