import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { ShareLinkUnlock } from '@/components/share-link-unlock'; const replace = vi.fn(); const refresh = vi.fn(); vi.mock('next/navigation', () => ({ useRouter: () => ({ replace, refresh, push: vi.fn(), back: vi.fn(), prefetch: vi.fn() }), })); // next/link needs the App Router context to mount. The link is incidental to // the validation branches under test, so stub it down to an anchor. vi.mock('next/link', () => ({ default: ({ href, children }: { href: string; children: React.ReactNode }) => ( {children} ), })); let fetchMock: ReturnType; /** * A password input has no ARIA role, so `getByRole` cannot reach it whatever the * markup does. `getByLabelText` can, and it only works because the field now has a * visually hidden