import { fireEvent, render, screen, waitFor } from '@testing-library/react' import { describe, expect, it, vi } from 'vitest' import { FeedbackDialog } from './FeedbackDialog' import { TOLARIA_GITHUB_ISSUES_URL } from '../constants/feedback' vi.mock('../utils/url', () => ({ openExternalUrl: vi.fn().mockResolvedValue(undefined), })) const { openExternalUrl } = await import('../utils/url') as typeof import('../utils/url') & { openExternalUrl: ReturnType } describe('FeedbackDialog', () => { it('renders the instructional copy when open', () => { render() expect(screen.getByTestId('feedback-dialog')).toBeInTheDocument() expect(screen.getByText('Share feedback')).toBeInTheDocument() expect(screen.getByText(/best way to share product feedback/i)).toBeInTheDocument() expect(screen.getByText(/check whether a similar one already exists/i)).toBeInTheDocument() }) it('focuses the primary CTA when opened', async () => { render() const cta = screen.getByRole('button', { name: 'Go to Issues' }) await waitFor(() => expect(cta).toHaveFocus()) }) it('opens GitHub Issues without closing the modal', async () => { const onClose = vi.fn() render() fireEvent.click(screen.getByRole('button', { name: 'Go to Issues' })) await waitFor(() => expect(openExternalUrl).toHaveBeenCalledWith(TOLARIA_GITHUB_ISSUES_URL)) expect(onClose).not.toHaveBeenCalled() expect(screen.getByTestId('feedback-dialog')).toBeInTheDocument() }) it('closes when pressing Escape', () => { const onClose = vi.fn() render() fireEvent.keyDown(document, { key: 'Escape' }) expect(onClose).toHaveBeenCalledOnce() }) it('closes when clicking Close', () => { const onClose = vi.fn() render() fireEvent.click(screen.getByRole('button', { name: 'Close' })) expect(onClose).toHaveBeenCalledOnce() }) })