feat(ui): New sidebar & search UI (#831)

This commit is contained in:
Alex
2026-05-04 09:46:48 +01:00
committed by GitHub
parent c9b2a5734e
commit f3138a88c5
182 changed files with 8318 additions and 4660 deletions
@@ -5,7 +5,7 @@ import { provideRouter, Router } from '@angular/router';
import { TranslocoTestingModule } from '@jsverse/transloco';
import { AppLayoutComponent } from './app.layout.component';
import { AppMenuComponent } from '../layout-menu/app.menu.component';
import { AppTopBarComponent } from '../layout-topbar/app.topbar.component';
import { AppMobileTopbarComponent } from '../layout-mobile-topbar/app.mobile-topbar.component';
import { LocalStorageService } from '../../service/local-storage.service';
import { LayoutService } from '../layout.service';
@@ -17,11 +17,11 @@ import { LayoutService } from '../layout.service';
class StubMenuComponent {}
@Component({
selector: 'app-topbar',
selector: 'app-mobile-topbar',
standalone: true,
template: '',
})
class StubTopBarComponent {}
class StubMobileTopbarComponent {}
@Component({
standalone: true,
@@ -34,11 +34,21 @@ describe('AppLayoutComponent', () => {
let router: Router;
let layoutService: LayoutService;
const localStorageValues: Record<string, unknown> = {};
const localStorageService = {
get: vi.fn(() => 225),
get: vi.fn((key: string) => localStorageValues[key]),
set: vi.fn((key: string, value: unknown) => {
localStorageValues[key] = value;
}),
};
beforeEach(async () => {
for (const key of Object.keys(localStorageValues)) {
delete localStorageValues[key];
}
localStorageValues['sidebarWidth'] = 225;
localStorageService.get.mockClear();
localStorageService.set.mockClear();
TestBed.resetTestingModule();
TestBed.configureTestingModule({
imports: [
@@ -56,10 +66,10 @@ describe('AppLayoutComponent', () => {
TestBed.overrideComponent(AppLayoutComponent, {
remove: {
imports: [AppMenuComponent, AppTopBarComponent],
imports: [AppMenuComponent, AppMobileTopbarComponent],
},
add: {
imports: [StubMenuComponent, StubTopBarComponent],
imports: [StubMenuComponent, StubMobileTopbarComponent],
},
});
@@ -79,35 +89,110 @@ describe('AppLayoutComponent', () => {
});
it('closes the mobile sidebar when the mask is clicked', () => {
layoutService.mobileSidebarOpen.set(true);
layoutService.mobileDrawerOpen.set(true);
fixture.detectChanges();
const mask = fixture.nativeElement.querySelector('.layout-mask') as HTMLDivElement;
mask.click();
fixture.detectChanges();
expect(layoutService.mobileSidebarOpen()).toBe(false);
expect(layoutService.mobileDrawerOpen()).toBe(false);
});
it('toggles the body scroll lock with mobile sidebar state', () => {
layoutService.mobileSidebarOpen.set(true);
layoutService.mobileDrawerOpen.set(true);
fixture.detectChanges();
expect(document.body.classList.contains('blocked-scroll')).toBe(true);
layoutService.mobileSidebarOpen.set(false);
layoutService.mobileDrawerOpen.set(false);
fixture.detectChanges();
expect(document.body.classList.contains('blocked-scroll')).toBe(false);
});
it('closes the mobile sidebar on navigation', async () => {
layoutService.mobileSidebarOpen.set(true);
layoutService.mobileDrawerOpen.set(true);
fixture.detectChanges();
await router.navigateByUrl('/next');
fixture.detectChanges();
expect(layoutService.mobileSidebarOpen()).toBe(false);
expect(layoutService.mobileDrawerOpen()).toBe(false);
});
it('uses an explicit sidebar-hidden shell state when the desktop sidebar is hidden', () => {
layoutService.isDesktop.set(true);
layoutService.sidebarVisible.set(false);
fixture.detectChanges();
const wrapper = fixture.nativeElement.querySelector('.layout-wrapper') as HTMLDivElement;
const sidebar = fixture.nativeElement.querySelector('.layout-sidebar') as HTMLElement;
expect(wrapper.classList.contains('layout-sidebar-hidden')).toBe(true);
expect(sidebar.getAttribute('aria-hidden')).toBe('true');
expect(sidebar.hasAttribute('inert')).toBe(true);
});
it('keeps the mobile drawer reachable when the desktop sidebar preference is hidden', () => {
layoutService.isDesktop.set(false);
layoutService.sidebarVisible.set(false);
layoutService.mobileDrawerOpen.set(true);
fixture.detectChanges();
const wrapper = fixture.nativeElement.querySelector('.layout-wrapper') as HTMLDivElement;
const sidebar = fixture.nativeElement.querySelector('.layout-sidebar') as HTMLElement;
expect(wrapper.classList.contains('layout-sidebar-hidden')).toBe(false);
expect(sidebar.getAttribute('aria-hidden')).toBeNull();
expect(sidebar.hasAttribute('inert')).toBe(false);
});
it('cleans up an active sidebar resize when the component is destroyed', () => {
const component = fixture.componentInstance;
layoutService.sidebarCollapsed.set(false);
layoutService.isDesktop.set(true);
component.startResize(new MouseEvent('mousedown', { clientX: 200 }));
expect(document.body.classList.contains('layout-resizing-cursor')).toBe(true);
fixture.destroy();
document.dispatchEvent(new MouseEvent('mousemove', { clientX: 260 }));
expect(document.body.classList.contains('layout-resizing-cursor')).toBe(false);
expect(layoutService.sidebarWidth()).toBe(225);
});
it('supports keyboard resizing for the desktop sidebar handle', () => {
layoutService.sidebarCollapsed.set(false);
layoutService.isDesktop.set(true);
layoutService.sidebarWidth.set(225);
fixture.detectChanges();
const handle = fixture.nativeElement.querySelector('.layout-sidebar-resize-handle') as HTMLDivElement;
handle.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight' }));
fixture.detectChanges();
expect(layoutService.sidebarWidth()).toBe(241);
expect(localStorageService.set).not.toHaveBeenCalledWith('sidebarWidth', 241);
handle.dispatchEvent(new KeyboardEvent('keyup', { key: 'ArrowRight' }));
fixture.detectChanges();
expect(localStorageService.set).toHaveBeenCalledWith('sidebarWidth', 241);
expect(handle.getAttribute('role')).toBe('slider');
expect(handle.getAttribute('tabindex')).toBe('0');
});
it('uses the collapsed rail width while preserving the stored expanded width', () => {
layoutService.sidebarWidth.set(225);
layoutService.sidebarCollapsed.set(true);
layoutService.isDesktop.set(true);
fixture.detectChanges();
const wrapper = fixture.nativeElement.querySelector('.layout-wrapper') as HTMLDivElement;
expect(document.documentElement.style.getPropertyValue('--sidebar-width')).toBe('var(--sidebar-collapsed-width)');
expect(wrapper.style.getPropertyValue('--sidebar-stored-width')).toBe('225px');
});
});