// #region DatasetPreviewTest [C:2] [TYPE Module] [SEMANTICS test, datasets, detail, preview, component]
// @BRIEF Contract-focused unit tests for DatasetPreview.svelte component.
// @LAYER Test
import { describe, it, expect } from 'vitest';
import fs from 'node:fs';
import path from 'node:path';

const COMPONENT_PATH = path.resolve(process.cwd(), 'src/routes/datasets/DatasetPreview.svelte');

describe('DatasetPreview Component', () => {
  it('component file exists', () => {
    expect(fs.existsSync(COMPONENT_PATH)).toBe(true);
  });

  it('shows no-selection placeholder', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('no_selection');
    expect(src).toContain('!dataset');
  });

  it('shows loading skeleton', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('isLoading');
    expect(src).toContain('animate-pulse');
    expect(src).toContain('aria-busy');
  });

  it('shows error state with retry', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('error');
    expect(src).toContain('onretry');
    expect(src).toContain('retry');
  });

  it('renders header with table_name, schema, counts', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('table_name');
    expect(src).toContain('schema');
    expect(src).toContain('column_count');
    expect(src).toContain('metric_count');
  });

  it('renders linked dashboards as clickable pills', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('linked_dashboards');
    expect(src).toContain('dashboards/');
  });

  it('includes ColumnsTable and MetricsTable', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('ColumnsTable');
    expect(src).toContain('MetricsTable');
  });

  it('is presentational — receives dataset, isLoading, error props', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('$props()');
    expect(src).toContain('dataset = null');
    expect(src).toContain('isLoading = false');
    expect(src).toContain('error = null');
  });
});
