test: add unit tests for ContentHeroComponent and handle ResizeObserver unavailability

Entire-Checkpoint: c6e522b4276c
This commit is contained in:
4gray committed 2026-04-19 23:39:16 +02:00
1 parent 3f79b01a9d
commit ecb070d08e
2 files changed
+45

No files matched your search

@@ -0,0 +1,41 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { ContentHeroComponent } from './content-hero.component';
describe('ContentHeroComponent', () => {
let fixture: ComponentFixture<ContentHeroComponent>;
const originalResizeObserver = globalThis.ResizeObserver;
afterEach(() => {
Object.defineProperty(globalThis, 'ResizeObserver', {
configurable: true,
writable: true,
value: originalResizeObserver,
});
});
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ContentHeroComponent, TranslateModule.forRoot()],
}).compileComponents();
fixture = TestBed.createComponent(ContentHeroComponent);
});
it('renders description content when ResizeObserver is unavailable', () => {
Object.defineProperty(globalThis, 'ResizeObserver', {
configurable: true,
writable: true,
value: undefined,
});
fixture.componentRef.setInput('title', 'Fallback_Title');
fixture.componentRef.setInput('description', 'Plain description');
expect(() => fixture.detectChanges()).not.toThrow();
const host = fixture.nativeElement as HTMLElement;
expect(host.textContent).toContain('Fallback Title');
expect(host.textContent).toContain('Plain description');
});
});
@@ -110,6 +110,10 @@ export class ContentHeroComponent {
private observeOverflow(el: HTMLElement): void {
this.resizeObserver?.disconnect();
if (typeof ResizeObserver === 'undefined') {
this.measureOverflow(el);
return;
}
this.resizeObserver = new ResizeObserver(() => this.measureOverflow(el));
this.resizeObserver.observe(el);
}