/**
 * Tests for WordPressPlaygroundPreview.
 * Verifies the Site Editor toolbar button renders and stays disabled until
 * the Playground client reaches the 'ready' phase. The boot effect's theme
 * fetch is stubbed to reject under jsdom, which the component catches (error
 * phase) — the toolbar renders regardless of phase.
 */
import { render, screen } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';

vi.mock('@/contexts/LanguageContext', () => ({
    useTranslation: () => ({ t: (s: string) => s }),
}));
vi.mock('@/components/Preview/RevisionHistoryPanel', () => ({
    RevisionHistoryPanel: () => null,
}));
vi.mock('@/components/Preview/BuildingAnimation', () => ({
    BuildingAnimation: () => null,
}));

import { WordPressPlaygroundPreview } from './WordPressPlaygroundPreview';

describe('WordPressPlaygroundPreview', () => {
    beforeEach(() => {
        // The boot effect fetches the theme zip first; stub it so the test
        // never hits the network and resolves the phase deterministically.
        vi.stubGlobal('fetch', vi.fn().mockRejectedValue(new Error('stubbed')));
    });

    it('renders a Site Editor button, disabled until Playground is ready', () => {
        render(<WordPressPlaygroundPreview themeZipUrl="/preview/x/wp-theme.zip" />);
        const btn = screen.getByTitle('Edit in Site Editor');
        expect(btn).toBeDisabled();
    });
});
