[ACS-8582] Introduce UnitTestingUtils class and transform existing tests in core library (#10571)

* [ACS-8582] Add UnitTestingUtils class, adapt first batch of unit tests

* [ACS-8582] Extend UnitTestingUtils, cover second batch of unit tests

* [ACS-8582] Extend UnitTestingUtils, cover third batch of unit tests

* [ACS-8582] Extend UnitTestingUtils, cover final batch of unit tests

* [ci:force]

* [ci:force]

* [ACS-8582] CR fixes

* [ACS-8582] CR fixes
This commit is contained in:
MichalKinas
2025-01-28 12:27:08 +01:00
committed by GitHub
parent c4b3b9f3d4
commit e6278109d8
76 changed files with 2068 additions and 1954 deletions

View File

@@ -20,7 +20,7 @@ import { Component } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideMockFeatureFlags } from '../mocks/features-service-mock.factory';
import { FeaturesDirective } from './features.directive';
import { By } from '@angular/platform-browser';
import { UnitTestingUtils } from '../../../../src/lib/testing/unit-testing-utils';
@Component({
template: `
@@ -46,6 +46,7 @@ class TestWithDisabledFlagComponent {
describe('FeaturesDirective', () => {
let enabledFixture: ComponentFixture<TestWithEnabledFlagComponent>;
let disabledFixture: ComponentFixture<TestWithDisabledFlagComponent>;
let testingUtils: UnitTestingUtils;
beforeEach(async () => {
TestBed.configureTestingModule({
@@ -66,16 +67,20 @@ describe('FeaturesDirective', () => {
disabledFixture = TestBed.createComponent(TestWithDisabledFlagComponent);
disabledFixture.detectChanges();
testingUtils = new UnitTestingUtils(enabledFixture.debugElement);
await enabledFixture.whenStable();
await disabledFixture.whenStable();
});
it('should render the element with enabled features', () => {
expect(enabledFixture.debugElement.query(By.css('#underFeatureFlag'))).toBeDefined();
expect(enabledFixture.debugElement.query(By.css('#underFeatureFlag')).nativeElement).toBeDefined();
const enabledFixtureElement = testingUtils.getByCSS('#underFeatureFlag');
expect(enabledFixtureElement).toBeDefined();
expect(enabledFixtureElement.nativeElement).toBeDefined();
});
it('should not render the element with disabled features', () => {
expect(disabledFixture.debugElement.query(By.css('#underFeatureFlag'))).toBeNull();
testingUtils.setDebugElement(disabledFixture.debugElement);
expect(testingUtils.getByCSS('#underFeatureFlag')).toBeNull();
});
});

View File

@@ -18,9 +18,9 @@
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { provideMockFeatureFlags } from '../mocks/features-service-mock.factory';
import { NotFeaturesDirective } from './not-features.directive';
import { UnitTestingUtils } from '../../../../src/lib/testing/unit-testing-utils';
@Component({
template: `
@@ -47,6 +47,7 @@ class TestWithDisabledFlagComponent {
describe('NotFeaturesDirective', () => {
let enabledFixture: ComponentFixture<TestWithEnabledFlagComponent>;
let disabledFixture: ComponentFixture<TestWithDisabledFlagComponent>;
let testingUtils: UnitTestingUtils;
beforeEach(async () => {
TestBed.configureTestingModule({
@@ -66,14 +67,18 @@ describe('NotFeaturesDirective', () => {
disabledFixture = TestBed.createComponent(TestWithDisabledFlagComponent);
disabledFixture.detectChanges();
testingUtils = new UnitTestingUtils(disabledFixture.debugElement);
});
it('should render the element with disabled features', () => {
expect(disabledFixture.debugElement.query(By.css('#underFeatureFlag'))).toBeDefined();
expect(disabledFixture.debugElement.query(By.css('#underFeatureFlag')).nativeElement).toBeDefined();
const disabledFixtureElement = testingUtils.getByCSS('#underFeatureFlag');
expect(disabledFixtureElement).toBeDefined();
expect(disabledFixtureElement.nativeElement).toBeDefined();
});
it('should not render the element with enabled features', () => {
expect(enabledFixture.debugElement.query(By.css('#underFeatureFlag'))).toBeNull();
testingUtils.setDebugElement(enabledFixture.debugElement);
expect(testingUtils.getByCSS('#underFeatureFlag')).toBeNull();
});
});