[ACS-11153] remove the usage of ng reflect from the unit tests (#11666)

* [ACS-11153] Removed usages of ng reflect from card view dateitem and diagram activities

* [ACS-11153] Removed usages of ng-reflect

* [ACS-11153] Added eslint rule
This commit is contained in:
AleksanderSklorz
2026-02-19 07:58:31 +01:00
committed by GitHub
parent 7b574fc0d0
commit 4581f714d7
17 changed files with 1160 additions and 1174 deletions
@@ -27,6 +27,7 @@ import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { addMinutes } from 'date-fns';
import { UnitTestingUtils } from '../../../testing/unit-testing-utils';
import { MatFormField } from '@angular/material/form-field';
describe('CardViewDateItemComponent', () => {
let loader: HarnessLoader;
@@ -372,14 +373,10 @@ describe('CardViewDateItemComponent', () => {
component.editable = true;
fixture.detectChanges();
const matFormField = await testingUtils.getMatFormField();
const host = await matFormField.host();
const floatLabel = await host.getAttribute('ng-reflect-float-label');
expect(floatLabel).toBe('always');
expect(testingUtils.getByDirective(MatFormField).componentInstance.floatLabel).toBe('always');
});
it('should set floatLabel to null when property has no default value and is editable', async () => {
it('should set floatLabel to auto when property has no default value and is editable', async () => {
component.property = new CardViewDateItemModel({
label: 'Date label',
value: new Date('07/10/2017'),
@@ -391,14 +388,10 @@ describe('CardViewDateItemComponent', () => {
component.editable = true;
fixture.detectChanges();
const matFormField = await testingUtils.getMatFormField();
const host = await matFormField.host();
const floatLabel = await host.getAttribute('ng-reflect-float-label');
expect(floatLabel).toBe(null);
expect(testingUtils.getByDirective(MatFormField).componentInstance.floatLabel).toBe('auto');
});
it('should set floatLabel to null when property has null default value and is editable', async () => {
it('should set floatLabel to auto when property has null default value and is editable', async () => {
component.property = new CardViewDateItemModel({
label: 'Date label',
value: new Date('07/10/2017'),
@@ -409,12 +402,7 @@ describe('CardViewDateItemComponent', () => {
});
component.editable = true;
fixture.detectChanges();
const matFormField = await testingUtils.getMatFormField();
const host = await matFormField.host();
const floatLabel = await host.getAttribute('ng-reflect-float-label');
expect(floatLabel).toBe(null);
expect(testingUtils.getByDirective(MatFormField).componentInstance.floatLabel).toBe('auto');
});
});
});
@@ -16,9 +16,10 @@
*/
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { NavbarItemComponent } from './navbar-item.component';
import { UnitTestingUtils } from '../../testing/unit-testing-utils';
import { RouterTestingModule } from '@angular/router/testing';
import { Router } from '@angular/router';
import { UnitTestingUtils } from '@alfresco/adf-core';
describe('NavbarItemComponent', () => {
let component: NavbarItemComponent;
@@ -46,8 +47,11 @@ describe('NavbarItemComponent', () => {
expect(button.textContent).toContain('Test Label');
});
it('should bind routerLink', () => {
it('should navigate to routerLink on click', () => {
const navigateByUrlSpy = spyOn(TestBed.inject(Router), 'navigateByUrl');
button.click();
fixture.detectChanges();
expect(button.getAttribute('ng-reflect-router-link')).toEqual('/expected-route');
expect(navigateByUrlSpy.calls.mostRecent().args[0].toString()).toBe('/expected-route');
});
});
@@ -21,6 +21,7 @@ import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { NavbarComponent } from './navbar.component';
import { UnitTestingUtils } from '../../testing/unit-testing-utils';
import { NavbarItemComponent } from '@alfresco/adf-core';
describe('NavbarComponent', () => {
let component: NavbarComponent;
@@ -45,8 +46,7 @@ describe('NavbarComponent', () => {
];
component.items = testItems;
fixture.detectChanges();
const renderedItems = testingUtils.getAllByCSS('.adf-navbar-item-btn');
expect(renderedItems.length).toBe(testItems.length);
expect(testingUtils.getAllByDirective(NavbarItemComponent).length).toBe(testItems.length);
});
it('should render navbar items with correct label and router-link', () => {
@@ -56,10 +56,10 @@ describe('NavbarComponent', () => {
];
component.items = testItems;
fixture.detectChanges();
const renderedItems = testingUtils.getAllByCSS('.adf-navbar-item-btn').map((item) => item.nativeElement);
const navbarItems = testingUtils.getAllByDirective(NavbarItemComponent);
testItems.forEach((item, index) => {
expect(renderedItems[index].textContent).toContain(item.label);
expect(renderedItems[index].getAttribute('ng-reflect-router-link')).toContain(item.routerLink);
expect(navbarItems[index].componentInstance.label).toBe(item.label);
expect(navbarItems[index].componentInstance.routerLink).toBe(item.routerLink);
});
});
});
@@ -22,6 +22,7 @@ import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { UnitTestingUtils } from '../../../testing/unit-testing-utils';
import { provideRouter } from '@angular/router';
import { MatToolbar } from '@angular/material/toolbar';
describe('HeaderLayoutComponent', () => {
let loader: HarnessLoader;
@@ -56,13 +57,11 @@ describe('HeaderLayoutComponent', () => {
expect(testingUtils.getInnerTextByCSS('.adf-app-title')).toEqual('TEST TITLE');
});
it('color attribute should be present on toolbar', async () => {
it('should have assigned correct color on toolbar', async () => {
component.color = 'primary';
fixture.detectChanges();
const host = await testingUtils.getMatToolbarHost();
expect(await host.getAttribute('ng-reflect-color')).toBe('primary');
expect(testingUtils.getByDirective(MatToolbar).componentInstance.color).toBe('primary');
});
it('should change background color when custom is provided', async () => {
@@ -80,6 +80,10 @@ export class UnitTestingUtils {
return this.debugElement.query(By.directive(directive));
}
getAllByDirective(directive: Type<any>): DebugElement[] {
return this.debugElement.queryAll(By.directive(directive));
}
/** Perform actions */
clickByCSS(selector: string): void {