// #region DatasetListTest [C:2] [TYPE Module] [SEMANTICS test, datasets, cards, component]
// @BRIEF Contract-focused unit tests for DatasetList.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/DatasetList.svelte');

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

  it('renders cards with table_name, schema, column_count, metric_count', () => {
    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('has progress bar with color logic', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('getProgressClass');
    expect(src).toContain('bg-green-500');
    expect(src).toContain('bg-yellow-400');
    expect(src).toContain('bg-blue-400');
    expect(src).toContain('mappedFields');
  });

  it('has pagination controls', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('onpagechange');
    expect(src).toContain('totalPages');
    expect(src).toContain('page');
    expect(src).toContain('pageSize');
  });

  it('has search input', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('onsearch');
    expect(src).toContain('search_placeholder');
  });

  it('has checkboxes for bulk selection', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('checkbox');
    expect(src).toContain('oncheckbox');
    expect(src).toContain('selectedIds');
  });

  it('has quick-action icon buttons (map, docs)', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('map_columns_tip');
    expect(src).toContain('generate_docs_tip');
    expect(src).toContain('<svg');  // icon-based, not text
  });

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

  it('shows empty state when no datasets', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('empty');
    expect(src).toContain('datasets.length === 0');
  });
});
