diff --git a/frontend/__tests__/unit/pages/Header.test.tsx b/frontend/__tests__/unit/pages/Header.test.tsx index 092454557c..98b7f3da2e 100644 --- a/frontend/__tests__/unit/pages/Header.test.tsx +++ b/frontend/__tests__/unit/pages/Header.test.tsx @@ -104,30 +104,25 @@ jest.mock('components/UserMenu', () => { }) // Mock constants -jest.mock('utils/constants', () => ({ - desktopViewMinWidth: 768, - headerLinks: [ - { - text: 'Home', - href: '/', - }, - { - text: 'About', - href: '/about', - }, - { - text: 'Services', - submenu: [ - { text: 'Web Development', href: '/services/web' }, - { text: 'Mobile Development', href: '/services/mobile' }, - ], - }, - { - text: 'Contact', - href: '/contact', - }, - ], -})) +jest.mock('utils/constants', () => { + const actual = jest.requireActual('utils/constants') + return { + ...actual, + desktopViewMinWidth: 768, + headerLinks: [ + { text: 'Home', href: '/' }, + { text: 'About', href: '/about' }, + { + text: 'Services', + submenu: [ + { text: 'Web Development', href: '/services/web' }, + { text: 'Mobile Development', href: '/services/mobile' }, + ], + }, + { text: 'Contact', href: '/contact' }, + ], + } +}) // Mock utility function jest.mock('utils/utility', () => ({ @@ -223,8 +218,9 @@ describe('Header Component', () => { const brandTexts = screen.getAllByText('Nest') expect(brandTexts.length).toBe(2) // One in desktop header, one in mobile menu - const userMenu = screen.getByTestId('user-menu') - expect(userMenu).toHaveAttribute('data-github-auth', 'true') + const userMenus = screen.getAllByTestId('user-menu') + expect(userMenus.length).toBeGreaterThanOrEqual(1) + expect(userMenus[0]).toHaveAttribute('data-github-auth', 'true') }) it('renders successfully with GitHub auth disabled', () => { @@ -238,8 +234,9 @@ describe('Header Component', () => { const brandTexts = screen.getAllByText('Nest') expect(brandTexts.length).toBe(2) - const userMenu = screen.getByTestId('user-menu') - expect(userMenu).toHaveAttribute('data-github-auth', 'false') + const userMenus = screen.getAllByTestId('user-menu') + expect(userMenus.length).toBeGreaterThanOrEqual(1) + expect(userMenus[0]).toHaveAttribute('data-github-auth', 'false') }) }) @@ -453,7 +450,9 @@ describe('Header Component', () => { it('renders UserMenu component', () => { renderWithSession(
) - expect(screen.getByTestId('user-menu')).toBeInTheDocument() + const userMenus = screen.getAllByTestId('user-menu') + expect(userMenus.length).toBeGreaterThanOrEqual(1) + expect(userMenus[0]).toBeInTheDocument() }) it('renders ModeToggle component', () => { @@ -593,13 +592,17 @@ describe('Header Component', () => { it('passes isGitHubAuthEnabled prop to UserMenu correctly when true', () => { renderWithSession(
) - expect(screen.getByTestId('user-menu')).toHaveAttribute('data-github-auth', 'true') + const userMenus = screen.getAllByTestId('user-menu') + expect(userMenus.length).toBeGreaterThanOrEqual(1) + expect(userMenus[0]).toHaveAttribute('data-github-auth', 'true') }) it('passes isGitHubAuthEnabled prop to UserMenu correctly when false', () => { renderWithSession(
) - expect(screen.getByTestId('user-menu')).toHaveAttribute('data-github-auth', 'false') + const userMenus = screen.getAllByTestId('user-menu') + expect(userMenus.length).toBeGreaterThanOrEqual(1) + expect(userMenus[0]).toHaveAttribute('data-github-auth', 'false') }) }) diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx index da728e905c..f01500362f 100644 --- a/frontend/src/components/Header.tsx +++ b/frontend/src/components/Header.tsx @@ -1,6 +1,5 @@ 'use client' import { Button } from '@heroui/button' -import { useIsMobile } from 'hooks/useIsMobile' import Image from 'next/image' import Link from 'next/link' import { usePathname } from 'next/navigation' @@ -22,7 +21,6 @@ import UserMenu from 'components/UserMenu' export default function Header({ isGitHubAuthEnabled }: { readonly isGitHubAuthEnabled: boolean }) { const pathname = usePathname() - const isMobile = useIsMobile() const [mobileMenuOpen, setMobileMenuOpen] = useState(false) const toggleMobileMenu = () => setMobileMenuOpen(!mobileMenuOpen) @@ -58,7 +56,7 @@ export default function Header({ isGitHubAuthEnabled }: { readonly isGitHubAuthE return (
-