import { TestBed } from '@angular/core/testing'; import { provideRouter } from '@angular/router'; import { AppLayoutComponent } from './app-layout'; describe('AppLayoutComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ imports: [AppLayoutComponent], providers: [provideRouter([])], }).compileComponents(); }); it('should create the component', () => { const fixture = TestBed.createComponent(AppLayoutComponent); const component = fixture.componentInstance; expect(component).toBeTruthy(); }); it('should toggle menu', () => { const fixture = TestBed.createComponent(AppLayoutComponent); const component = fixture.componentInstance; expect(component.isOpen()).toBe(false); component.toggleMenu(); expect(component.isOpen()).toBe(true); component.toggleMenu(); expect(component.isOpen()).toBe(false); }); it('should close menu', () => { const fixture = TestBed.createComponent(AppLayoutComponent); const component = fixture.componentInstance; component.toggleMenu(); expect(component.isOpen()).toBe(true); component.closeMenu(); expect(component.isOpen()).toBe(false); }); it('should have navigation items', () => { const fixture = TestBed.createComponent(AppLayoutComponent); const component = fixture.componentInstance; expect(component.navigationItems.length).toBeGreaterThan(0); expect(component.navigationItems[0].path).toBe('/'); }); it('should render nav element', async () => { const fixture = TestBed.createComponent(AppLayoutComponent); await fixture.whenStable(); const compiled = fixture.nativeElement as HTMLElement; expect(compiled.querySelector('nav')).toBeTruthy(); }); it('should set aria-expanded on toggle button', async () => { const fixture = TestBed.createComponent(AppLayoutComponent); await fixture.whenStable(); const compiled = fixture.nativeElement as HTMLElement; const button = compiled.querySelector('button'); expect(button?.getAttribute('aria-expanded')).toBe('false'); fixture.componentInstance.toggleMenu(); fixture.detectChanges(); expect(button?.getAttribute('aria-expanded')).toBe('true'); }); });