diff --git a/src/components/AppSidebarNav.js b/src/components/AppSidebarNav.js index 2063d9e73..ff0608cb8 100644 --- a/src/components/AppSidebarNav.js +++ b/src/components/AppSidebarNav.js @@ -37,7 +37,7 @@ export const AppSidebarNav = ({ items }) => { ) } const navGroup = (item, index) => { - const { component, name, icon, to, ...rest } = item + const { component, name, icon, to, items, ...rest } = item const Component = component return ( { visible={location.pathname.startsWith(to)} {...rest} > - {item.items?.map((item, index) => - item.items ? navGroup(item, index) : navItem(item, index), + {items?.map((item, index) => + items ? navGroup(item, index) : navItem(item, index), )} ) diff --git a/src/components/AppSidebarNav.test.js b/src/components/AppSidebarNav.test.js new file mode 100644 index 000000000..b9de68951 --- /dev/null +++ b/src/components/AppSidebarNav.test.js @@ -0,0 +1,36 @@ +import React from 'react' +import { CNavGroup, CNavItem } from '@coreui/react' +import { AppSidebarNav } from './AppSidebarNav' +import { HashRouter, Route, Routes } from 'react-router-dom' +import { render } from '@testing-library/react' + +test('renders nav group without items attribute', () => { + const navigation = [ + { + component: CNavGroup, + name: 'Base', + to: '/base', + items: [ + { + component: CNavItem, + name: 'Item', + to: '/base/item', + }, + ], + }, + ] + + const { container } = render( + + + } /> + + , + ) + + /* eslint-disable testing-library/no-container */ + /* eslint-disable testing-library/no-node-access */ + const groupElement = container.querySelector('.nav-group') + expect(groupElement).toBeInTheDocument() + expect(groupElement.hasAttribute('items')).toBeFalsy() +})