import { describe, it, expect, vi } from 'vitest';
import React from 'react';
import { render, screen } from '@testing-library/react';
vi.mock('next/navigation', () => ({
usePathname: () => '/',
useRouter: () => ({
push: () => {},
replace: () => {},
prefetch: () => {},
}),
}));
vi.mock('next/link', () => {
const ActualLink = ({ href, children, ...rest }: any) => (
{children}
);
return { default: ActualLink };
});
vi.mock('../../../apps/website/components/profile/UserPill', () => {
return {
__esModule: true,
default: function MockUserPill() {
return (
);
},
};
});
vi.mock('../../../apps/website/lib/auth/AuthContext', () => {
const React = require('react');
const AuthContext = React.createContext({
session: null,
loading: false,
login: () => {},
logout: async () => {},
refreshSession: async () => {},
});
const AuthProvider = ({ value, children }: { value: any; children: React.ReactNode }) => (
{children}
);
const useAuth = () => React.useContext(AuthContext);
return {
__esModule: true,
AuthProvider,
useAuth,
};
});
import { AuthProvider } from '../../../apps/website/lib/auth/AuthContext';
import { AlphaNav } from '../../../apps/website/components/alpha/AlphaNav';
describe('AlphaNav', () => {
it('hides Dashboard link and uses Home when unauthenticated', () => {
render(
{},
logout: async () => {},
refreshSession: async () => {},
}}
>
,
);
const dashboardLinks = screen.queryAllByText('Dashboard');
expect(dashboardLinks.length).toBe(0);
const homeLink = screen.getByText('Home');
expect(homeLink).toBeInTheDocument();
});
it('shows Dashboard link and hides Home when authenticated', () => {
render(
{},
logout: async () => {},
refreshSession: async () => {},
}}
>
,
);
const dashboard = screen.getByText('Dashboard');
expect(dashboard).toBeInTheDocument();
expect((dashboard as HTMLAnchorElement).getAttribute('href')).toBe('/dashboard');
const homeLink = screen.queryByText('Home');
expect(homeLink).toBeNull();
});
});