/**
 * Tests for Bulk Generation UI
 * Phase 5: Sites Renderer & Bulk Generation
 */
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { builderApi } from '../../../services/siteBuilder.api';

// Mock API
vi.mock('../../../services/siteBuilder.api');

describe('Bulk Generation', () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it('generates all pages when button clicked', async () => {
    // Test: Bulk page generation works
    const mockGenerate = vi.fn().mockResolvedValue({
      success: true,
      pages_queued: 5,
      task_ids: [1, 2, 3, 4, 5],
    });
    
    (builderApi as any).generateAllPages = mockGenerate;

    // This would be tested in the actual component
    expect(mockGenerate).toBeDefined();
  });

  it('tracks progress during generation', async () => {
    // Test: Progress tracking works
    const mockProgress = {
      pages_queued: 5,
      task_ids: [1, 2, 3, 4, 5],
      celery_task_id: 'task-123',
    };

    expect(mockProgress.pages_queued).toBe(5);
    expect(mockProgress.task_ids).toHaveLength(5);
  });

  it('creates tasks for selected pages only', async () => {
    // Test: Selected pages can be generated
    const selectedPageIds = [1, 3, 5];
    const mockGenerate = vi.fn().mockResolvedValue({
      success: true,
      pages_queued: 3,
      task_ids: selectedPageIds,
    });

    expect(selectedPageIds).toHaveLength(3);
  });

  it('force regenerates when option selected', async () => {
    // Test: Force regenerate works
    const mockGenerate = vi.fn().mockResolvedValue({
      success: true,
      pages_queued: 5,
      task_ids: [1, 2, 3, 4, 5],
    });

    await mockGenerate(1, { force: true });
    expect(mockGenerate).toHaveBeenCalledWith(1, { force: true });
  });
});

