/**
 * Tests for Site Integration UI
 * Phase 6: Site Integration & Multi-Destination Publishing
 */
import { describe, it, expect, vi } from 'vitest';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import PlatformSelector from '../../components/integration/PlatformSelector';
import IntegrationStatus from '../../components/integration/IntegrationStatus';

describe('Site Integration', () => {
  it('platform selector allows selecting platform', () => {
    // Test: Site integrations work correctly
    const handleChange = vi.fn();
    const { container } = render(
      <PlatformSelector value="wordpress" onChange={handleChange} />
    );

    const select = container.querySelector('select');
    expect(select).toBeDefined();
  });

  it('integration status displays sync status', () => {
    // Test: Site integrations work correctly
    const { container } = render(
      <IntegrationStatus
        syncEnabled={true}
        syncStatus="success"
        lastSyncAt="2025-01-18T10:00:00Z"
      />
    );

    expect(container).toBeDefined();
  });

  it('publishing settings save correctly', async () => {
    // Test: Publishing settings work
    const mockSave = vi.fn().mockResolvedValue({ success: true });
    
    await mockSave({
      defaultDestinations: ['sites', 'wordpress'],
      autoPublishEnabled: true,
    });

    expect(mockSave).toHaveBeenCalled();
  });

  it('multi-destination publishing works', async () => {
    // Test: Multi-destination publishing works
    const destinations = ['sites', 'wordpress', 'shopify'];
    const mockPublish = vi.fn().mockResolvedValue({
      success: true,
      results: destinations.map(d => ({ destination: d, success: true })),
    });

    const result = await mockPublish(1, destinations);
    expect(result.success).toBe(true);
    expect(result.results).toHaveLength(3);
  });
});

