import { describe, it, expect, vi } from 'vitest' import { render, screen, fireEvent } from '@testing-library/react' import { TelemetryConsentDialog } from './TelemetryConsentDialog' const dragRegionMouseDown = vi.fn() vi.mock('../hooks/useDragRegion', () => ({ useDragRegion: () => ({ onMouseDown: dragRegionMouseDown }), })) describe('TelemetryConsentDialog', () => { it('renders the consent dialog', () => { render() expect(screen.getByText('Help improve Tolaria')).toBeDefined() expect(screen.getByText(/anonymous crash reports/i)).toBeDefined() }) it('calls onAccept when Allow button is clicked', () => { const onAccept = vi.fn() render() fireEvent.click(screen.getByTestId('telemetry-accept')) expect(onAccept).toHaveBeenCalledOnce() }) it('calls onDecline when No thanks button is clicked', () => { const onDecline = vi.fn() render() fireEvent.click(screen.getByTestId('telemetry-decline')) expect(onDecline).toHaveBeenCalledOnce() }) it('shows a details section explaining what data is shared', () => { render() expect(screen.getByText(/no vault content, note titles/i)).toBeDefined() }) it('focuses the first action for keyboard users', () => { render() expect(screen.getByTestId('telemetry-decline')).toHaveFocus() }) it('uses the surrounding surface as a drag region and excludes the dialog card', () => { render() const shell = screen.getByTestId('telemetry-consent-shell') fireEvent.mouseDown(shell) expect(dragRegionMouseDown).toHaveBeenCalledOnce() expect(shell.querySelector('[data-no-drag]')).not.toBeNull() }) })