From 686e0785905aeba8059a6e5c3a05100dd0473d5b Mon Sep 17 00:00:00 2001 From: Ehsan Rezaei Date: Wed, 9 Sep 2026 12:05:41 +0200 Subject: [PATCH] AAE-51237 Fixing tests to pass with zoneless default behaviour of Angular 21 --- .../breadcrumb/dropdown-breadcrumb.component.spec.ts | 2 +- .../src/lib/testing/global-testing.module.ts | 4 ++-- .../card-view-item-dispatcher.component.ts | 1 - .../components/datatable/datatable.component.spec.ts | 12 ++++++------ lib/core/src/lib/testing/global-testing.module.ts | 4 ++-- lib/extensions/src/test.ts | 4 ++-- lib/insights/src/test.ts | 11 ++++++++--- .../src/lib/testing/global-testing.module.ts | 4 ++-- .../src/lib/testing/global-testing.module.ts | 4 ++-- 9 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/content-services/src/lib/breadcrumb/dropdown-breadcrumb.component.spec.ts b/lib/content-services/src/lib/breadcrumb/dropdown-breadcrumb.component.spec.ts index f3d3a2dfb9..58a02f794d 100644 --- a/lib/content-services/src/lib/breadcrumb/dropdown-breadcrumb.component.spec.ts +++ b/lib/content-services/src/lib/breadcrumb/dropdown-breadcrumb.component.spec.ts @@ -59,7 +59,7 @@ describe('DropdownBreadcrumb', () => { }; const clickOnTheFirstOption = () => { - const option: any = document.querySelector(`[data-automation-class="dropdown-breadcrumb-path-option"]`); + const option: any = fixture.nativeElement.querySelector(`[data-automation-class="dropdown-breadcrumb-path-option"]`); option.click(); }; diff --git a/lib/content-services/src/lib/testing/global-testing.module.ts b/lib/content-services/src/lib/testing/global-testing.module.ts index 4546a33a80..a27cf9b0af 100644 --- a/lib/content-services/src/lib/testing/global-testing.module.ts +++ b/lib/content-services/src/lib/testing/global-testing.module.ts @@ -16,12 +16,12 @@ */ import { NoopTranslateModule } from '@alfresco/adf-core'; -import { NgModule } from '@angular/core'; +import { NgModule, provideZoneChangeDetection } from '@angular/core'; import { BrowserTestingModule } from '@angular/platform-browser/testing'; import { provideNoopAnimations } from '@angular/platform-browser/animations'; @NgModule({ imports: [BrowserTestingModule, NoopTranslateModule], - providers: [provideNoopAnimations()] + providers: [provideNoopAnimations(), provideZoneChangeDetection()] }) export class GlobalTestingModule {} diff --git a/lib/core/src/lib/card-view/components/card-view-item-dispatcher/card-view-item-dispatcher.component.ts b/lib/core/src/lib/card-view/components/card-view-item-dispatcher/card-view-item-dispatcher.component.ts index bb89e33497..5878fa2b4b 100644 --- a/lib/core/src/lib/card-view/components/card-view-item-dispatcher/card-view-item-dispatcher.component.ts +++ b/lib/core/src/lib/card-view/components/card-view-item-dispatcher/card-view-item-dispatcher.component.ts @@ -89,7 +89,6 @@ export class CardViewItemDispatcherComponent implements OnChanges { this.componentReference.instance[changeName] = change.currentValue; }); - // Writing to `.instance` does not mark the view dirty, which zoneless change detection requires. this.componentReference.changeDetectorRef.markForCheck(); this.proxy('ngOnChanges', changes); diff --git a/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts b/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts index acbfc23637..b6f7499c01 100644 --- a/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts +++ b/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts @@ -766,7 +766,7 @@ describe('DataTable', () => { it('should initialize default adapter', () => { const table = TestBed.createComponent(DataTableComponent).componentInstance; expect(table.data).toBeUndefined(); - table.ngOnChanges({ data: new SimpleChange('123', {}, true) }); + table.ngOnChanges({ data: new SimpleChange(null, {}, true) }); expect(table.data).toEqual(jasmine.any(ObjectDataTableAdapter)); }); @@ -1023,7 +1023,7 @@ describe('DataTable', () => { it('should allow "select all" calls with no rows', () => { dataTable.multiselect = true; - dataTable.ngOnChanges({ data: new SimpleChange('123', {}, true) }); + dataTable.ngOnChanges({ data: new SimpleChange(null, {}, true) }); dataTable.onSelectAllClick({ checked: true } as MatCheckboxChange); expect(dataTable.isSelectAllChecked).toBe(true); @@ -1053,7 +1053,7 @@ describe('DataTable', () => { const rows = data.getRows(); dataTable.multiselect = true; - dataTable.ngOnChanges({ data: new SimpleChange('123', data, true) }); + dataTable.ngOnChanges({ data: new SimpleChange(null, data, true) }); expect(rows[0].isSelected).toBe(false); expect(rows[1].isSelected).toBe(false); @@ -1181,13 +1181,13 @@ describe('DataTable', () => { }); it('should require adapter sorting to evaluate sorting state', () => { - dataTable.ngOnChanges({ data: new SimpleChange('123', {}, true) }); + dataTable.ngOnChanges({ data: new SimpleChange(null, {}, true) }); spyOn(dataTable.data, 'getSorting').and.returnValue(null); expect(dataTable.isColumnSorted({} as DataColumn, 'asc')).toBeFalsy(); }); it('should evaluate column sorting state', () => { - dataTable.ngOnChanges({ data: new SimpleChange('123', {}, true) }); + dataTable.ngOnChanges({ data: new SimpleChange(null, {}, true) }); spyOn(dataTable.data, 'getSorting').and.returnValue(new DataSorting('column_1', 'asc')); expect(dataTable.isColumnSorted({ key: 'column_1' } as DataColumn, 'asc')).toBeTruthy(); expect(dataTable.isColumnSorted({ key: 'column_2' } as DataColumn, 'desc')).toBeFalsy(); @@ -1267,7 +1267,7 @@ describe('DataTable', () => { }; dataTable.getRowActions(row, column); - dataTable.ngOnChanges({ data: new SimpleChange('123', {}, true) }); + dataTable.ngOnChanges({ data: new SimpleChange(null, {}, true) }); dataTable.getRowActions(row, column); expect(emitted).toBe(2); diff --git a/lib/core/src/lib/testing/global-testing.module.ts b/lib/core/src/lib/testing/global-testing.module.ts index fce6081c83..1b0466d2cd 100644 --- a/lib/core/src/lib/testing/global-testing.module.ts +++ b/lib/core/src/lib/testing/global-testing.module.ts @@ -16,12 +16,12 @@ */ import { NoopTranslateModule } from './noop-translate.module'; -import { NgModule } from '@angular/core'; +import { NgModule, provideZoneChangeDetection } from '@angular/core'; import { BrowserTestingModule } from '@angular/platform-browser/testing'; import { provideNoopAnimations } from '@angular/platform-browser/animations'; @NgModule({ imports: [BrowserTestingModule, NoopTranslateModule], - providers: [provideNoopAnimations()] + providers: [provideNoopAnimations(), provideZoneChangeDetection()] }) export class GlobalTestingModule {} diff --git a/lib/extensions/src/test.ts b/lib/extensions/src/test.ts index 8dd0067eef..a4ecce8eee 100644 --- a/lib/extensions/src/test.ts +++ b/lib/extensions/src/test.ts @@ -20,9 +20,9 @@ import 'zone.js'; import 'zone.js/testing'; import { getTestBed } from '@angular/core/testing'; -import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; +import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing'; // First, initialize the Angular testing environment. -getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), { +getTestBed().initTestEnvironment(BrowserTestingModule, platformBrowserTesting(), { teardown: { destroyAfterEach: true } }); diff --git a/lib/insights/src/test.ts b/lib/insights/src/test.ts index b8421bd9aa..dbddde8e52 100644 --- a/lib/insights/src/test.ts +++ b/lib/insights/src/test.ts @@ -19,15 +19,20 @@ import 'zone.js'; import 'zone.js/testing'; -import { getTestBed } from '@angular/core/testing'; -import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; +import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing'; +import { TestBed, getTestBed } from '@angular/core/testing'; +import { provideZoneChangeDetection } from '@angular/core'; import * as ChartJs from 'chart.js/auto'; import Raphael from 'raphael'; // First, initialize the Angular testing environment. -getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), { +getTestBed().initTestEnvironment(BrowserTestingModule, platformBrowserTesting(), { teardown: { destroyAfterEach: false } }); +beforeEach(() => { + TestBed.configureTestingModule({ providers: [provideZoneChangeDetection()] }); +}); + (window as any).Chart = (window as any).Chart || ChartJs.Chart; (window as any).Raphael = (window as any).Raphael || Raphael; diff --git a/lib/process-services-cloud/src/lib/testing/global-testing.module.ts b/lib/process-services-cloud/src/lib/testing/global-testing.module.ts index 48f2fd9e74..487c93c521 100644 --- a/lib/process-services-cloud/src/lib/testing/global-testing.module.ts +++ b/lib/process-services-cloud/src/lib/testing/global-testing.module.ts @@ -17,11 +17,11 @@ import { BrowserTestingModule } from '@angular/platform-browser/testing'; import { NoopTranslateModule } from '@alfresco/adf-core'; -import { NgModule } from '@angular/core'; +import { NgModule, provideZoneChangeDetection } from '@angular/core'; import { provideNoopAnimations } from '@angular/platform-browser/animations'; @NgModule({ imports: [BrowserTestingModule, NoopTranslateModule], - providers: [provideNoopAnimations()] + providers: [provideNoopAnimations(), provideZoneChangeDetection()] }) export class GlobalTestingModule {} diff --git a/lib/process-services/src/lib/testing/global-testing.module.ts b/lib/process-services/src/lib/testing/global-testing.module.ts index 48f2fd9e74..487c93c521 100644 --- a/lib/process-services/src/lib/testing/global-testing.module.ts +++ b/lib/process-services/src/lib/testing/global-testing.module.ts @@ -17,11 +17,11 @@ import { BrowserTestingModule } from '@angular/platform-browser/testing'; import { NoopTranslateModule } from '@alfresco/adf-core'; -import { NgModule } from '@angular/core'; +import { NgModule, provideZoneChangeDetection } from '@angular/core'; import { provideNoopAnimations } from '@angular/platform-browser/animations'; @NgModule({ imports: [BrowserTestingModule, NoopTranslateModule], - providers: [provideNoopAnimations()] + providers: [provideNoopAnimations(), provideZoneChangeDetection()] }) export class GlobalTestingModule {}