Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/components/Layout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function renderLayout(initialPath = '/') {
describe('Layout Integration', () => {
beforeEach(() => {
document.body.style.overflow = ''
sessionStorage.clear()
})

it('renders skip link and main branding', () => {
Expand Down Expand Up @@ -148,6 +149,29 @@ describe('Layout Integration', () => {
expect(drawer).toHaveAttribute('aria-hidden', 'true')
})

it('preserves sidebar collapse state across route changes', () => {
renderLayout('/dashboard')
const hamburger = screen.getByRole('button', { name: /open navigation menu/i })
const drawer = document.getElementById('mobile-nav-drawer') as HTMLElement

// Open the drawer
fireEvent.click(hamburger)
expect(drawer).toHaveAttribute('aria-hidden', 'false')

// Navigate to a different route via a desktop nav link (not inside the drawer)
// Desktop nav links are outside the drawer and don't trigger onClick={close}
const desktopDashboardLink = screen
.getAllByRole('link', { name: /dashboard/i })
.find((link) => !drawer.contains(link))
expect(desktopDashboardLink).toBeDefined()
if (desktopDashboardLink) {
fireEvent.click(desktopDashboardLink)
}

// The drawer should remain open after route change
expect(drawer).toHaveAttribute('aria-hidden', 'false')
})

// --- BottomNav integration ---

it('renders BottomNav inside the layout', () => {
Expand All @@ -161,4 +185,4 @@ describe('Layout Integration', () => {
const tabs = Array.from(bottomNav.querySelectorAll('a'))
expect(tabs).toHaveLength(5)
})
})
})
1 change: 1 addition & 0 deletions src/components/navigation/MobileNav.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function getDrawer() {
describe('MobileNav', () => {
beforeEach(() => {
document.body.style.overflow = ''
sessionStorage.clear()
})

// --- render ---
Expand Down
7 changes: 0 additions & 7 deletions src/components/navigation/MobileNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ export default function MobileNav() {

useScrollPreserver({ isActive: isOpen })

// Close on route change (SPA navigation) — but state survives full page reloads via sessionStorage
const prevPath = useRef(location.pathname)
if (prevPath.current !== location.pathname) {
prevPath.current = location.pathname
if (isOpen) setIsOpen(false)
}

// Persist collapse state across full page reloads
useEffect(() => {
try {
Expand Down