/** * Docs visibility gating. * * Two super-admin toggles decide whether the user documentation site and the * API documentation surface exist for visitors. When one is off, its links * must disappear everywhere — not just from the nav — and the setting must * default to ON so a slow or failed settings fetch never hides documentation * that is actually enabled. */ import { render, screen } from '@testing-library/react'; import { MemoryRouter } from 'react-router'; import { beforeEach, describe, expect, it, vi } from 'vitest'; const docsVisibilityMock = vi.fn(); vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (k: string) => k }) })); vi.mock('@/components/auth/AuthProvider', () => ({ useAuth: () => ({ user: null }) })); vi.mock('@/hooks/api', () => ({ useAuthSettings: () => ({ data: undefined }), useDocsVisibility: () => docsVisibilityMock(), // GitHubStarsButton deps: unconfigured here, so it renders nothing — // the gate itself is exercised in nav-no-phone-home.test.tsx. getGitHubRepoUrl: () => '', useGitHubStars: () => ({ data: undefined }), })); import { Nav } from '@/components/Nav'; import Footer from '@/components/sections/footer'; import Hero from '@/components/sections/hero'; function setVisibility(userDocsEnabled: boolean, apiDocsEnabled: boolean) { docsVisibilityMock.mockReturnValue({ userDocsEnabled, apiDocsEnabled, isLoading: false }); } /** Every href rendered in the tree, so assertions can be about links, not labels. */ function renderedHrefs(container: HTMLElement): string[] { return [...container.querySelectorAll('a[href]')].map((a) => a.getAttribute('href') ?? ''); } beforeEach(() => { docsVisibilityMock.mockReset(); }); describe('Nav docs links', () => { it('renders both docs links when both surfaces are enabled', () => { setVisibility(true, true); const { container } = render(