import { describe, it, expect, vi } from 'vitest'; import { render, screen } from '@testing-library/react'; import { SiteConnector } from '../src/components/SiteConnector.tsx'; describe('SiteConnector', () => { it('shows the pairing code', () => { render(); expect(screen.getByText('ABCD1234')).toBeInTheDocument(); }); it('shows success state when connected', async () => { render(); expect(await screen.findByText('Site connected')).toBeInTheDocument(); }); it('shows error state when the check fails', async () => { render(); expect(await screen.findByText('Connection failed')).toBeInTheDocument(); }); it('polls until the site is connected', async () => { const checkConnected = vi .fn() .mockResolvedValueOnce({ connected: false }) .mockResolvedValueOnce({ connected: true }); render(); expect(await screen.findByText('Site connected')).toBeInTheDocument(); expect(checkConnected).toHaveBeenCalledTimes(2); }); });