M5-T06: add Energy device management UI and sidebar entry
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
/**
|
||||
* Tests for AppSidebar (M5-T01).
|
||||
* Tests for AppSidebar (M5-T01, updated M5-T06).
|
||||
*
|
||||
* Strategy: render AppSidebar inside a minimal AppShell (required by
|
||||
* AppShell.Navbar) + MemoryRouter so useLocation() works.
|
||||
*
|
||||
* Coverage:
|
||||
* 1. All three nav items render (Home, Records, Config).
|
||||
* 1. All four nav items render (Home, Records, Energy, Config).
|
||||
* 2. Home nav item is active when pathname is '/'.
|
||||
* 3. Records nav item is active when pathname is '/records'.
|
||||
* 4. Config nav item is active when pathname is '/config'.
|
||||
* 5. Home is NOT active when on '/records'.
|
||||
* 6. Energy nav item is active when on '/energy'.
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
@@ -76,10 +77,11 @@ describe('AppSidebar', () => {
|
||||
// 1. All nav items render
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
it('renders Home, Records, and Config nav items', () => {
|
||||
it('renders Home, Records, Energy, and Config nav items', () => {
|
||||
renderSidebar('/')
|
||||
expect(screen.getByTestId('nav-home')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('nav-records')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('nav-energy')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('nav-config')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -123,4 +125,14 @@ describe('AppSidebar', () => {
|
||||
const homeLink = screen.getByTestId('nav-home')
|
||||
expect(homeLink).not.toHaveAttribute('data-active', 'true')
|
||||
})
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 6. Energy active on '/energy'
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
it('marks Energy nav item as active when on "/energy"', () => {
|
||||
renderSidebar('/energy')
|
||||
const energyLink = screen.getByTestId('nav-energy')
|
||||
expect(energyLink).toHaveAttribute('data-active', 'true')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
/**
|
||||
* AppSidebar — vertical sidebar navigation for all protected pages.
|
||||
*
|
||||
* Nav items: Home / Records / Config
|
||||
* Nav items: Home / Records / Energy / Config
|
||||
* Utilities: ColorSchemeToggle + LogoutButton (at bottom)
|
||||
*
|
||||
* Current route is highlighted via useLocation().
|
||||
* Mobile: burger button toggles the navbar open/closed (handled by AppShell context).
|
||||
*
|
||||
* NOTE: Energy nav item is intentionally absent — added in M5-T06 once /energy exists.
|
||||
*/
|
||||
|
||||
import { NavLink, Stack, Divider, Tooltip, ActionIcon, useMantineColorScheme, useComputedColorScheme, AppShell, Text, Group } from '@mantine/core'
|
||||
import { Link, useLocation, useNavigate } from 'react-router-dom'
|
||||
import { Home, List, Settings, Sun, Moon, LogOut } from 'react-feather'
|
||||
import { Home, List, Settings, Sun, Moon, LogOut, Zap } from 'react-feather'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import apiClient from '../api/client'
|
||||
|
||||
@@ -40,6 +38,12 @@ const NAV_ENTRIES: NavEntry[] = [
|
||||
icon: <List size={18} />,
|
||||
testId: 'nav-records',
|
||||
},
|
||||
{
|
||||
to: '/energy',
|
||||
label: 'Energy',
|
||||
icon: <Zap size={18} />,
|
||||
testId: 'nav-energy',
|
||||
},
|
||||
{
|
||||
to: '/config',
|
||||
label: 'Config',
|
||||
|
||||
Reference in New Issue
Block a user