diff --git a/apps/web/src/components/layout/sidebar.test.tsx b/apps/web/src/components/layout/sidebar.test.tsx index fe961f9..9de6981 100644 --- a/apps/web/src/components/layout/sidebar.test.tsx +++ b/apps/web/src/components/layout/sidebar.test.tsx @@ -40,9 +40,13 @@ vi.mock('next-intl', () => ({ }, })); +let mockCollapsed = false; +function mockSidebarCollapsed(value: boolean) { + mockCollapsed = value; +} vi.mock('@/lib/stores/sidebar-store', () => ({ useSidebarStore: () => ({ - isCollapsed: false, + isCollapsed: mockCollapsed, isMobileOpen: false, toggle: vi.fn(), setMobileOpen: vi.fn(), @@ -108,6 +112,7 @@ afterEach(() => { mockPathname = '/'; mockRefreshKey = 0; mockCustomModules = []; + mockCollapsed = false; }); function customModule(overrides: Partial<(typeof mockCustomModules)[number]> = {}) { @@ -325,6 +330,24 @@ describe('Sidebar', () => { expect(screen.queryByText('custom-modules')).toBeNull(); }); + it('eingeklappt stehen Eintraege aus „Eigene Module“ zuletzt', async () => { + mockCustomModules = [ + customModule({ id: 'cm-1', category: 'custom-modules', name: 'Mein Wiki' }), + customModule({ id: 'cm-2', category: 'fleet', name: 'Tankkarte' }), + ]; + mockSidebarCollapsed(true); + const Sidebar = await importSidebar(); + render(); + + const hrefs = () => + Array.from(document.querySelectorAll('aside ul.border-t a')).map((a) => a.getAttribute('href')); + await waitFor(() => { + expect(hrefs()).toContain('/modules/custom/cm-1'); + }); + expect(hrefs().at(-1)).toBe('/modules/custom/cm-1'); + expect(hrefs().indexOf('/modules/custom/cm-2')).toBeLessThan(hrefs().indexOf('/modules/custom/cm-1')); + }); + it('eingebaute Module stehen innerhalb einer Kategorie vor eigenen', async () => { mockCustomModules = [customModule({ category: 'Domain-Tools', name: 'Aaa Eigenes' })]; const Sidebar = await importSidebar(); diff --git a/apps/web/src/components/layout/sidebar.tsx b/apps/web/src/components/layout/sidebar.tsx index cadb256..7123811 100644 --- a/apps/web/src/components/layout/sidebar.tsx +++ b/apps/web/src/components/layout/sidebar.tsx @@ -186,6 +186,17 @@ export function Sidebar() { }); }; + // Eingeklappt in derselben Gruppenfolge wie ausgeklappt — „Eigene Module“ + // also auch hier immer zuletzt. + const collapsedEntries = useMemo( + () => + [...entries].sort( + (a, b) => + Number(a.category === CUSTOM_MODULE_CATEGORY) - Number(b.category === CUSTOM_MODULE_CATEGORY), + ), + [entries], + ); + const filteredCategories = useMemo(() => { const categories = new Map(); for (const entry of entries) { @@ -253,7 +264,7 @@ export function Sidebar() { {/* Eingeklappt: nur die Modul-Kacheln untereinander (Name als Tooltip). */} {isCollapsed && entries.length > 0 && (