// #region StatsBarTest [C:2] [TYPE Module] [SEMANTICS test, datasets, statsbar, component]
// @BRIEF Contract-focused unit tests for StatsBar.svelte component.
// @LAYER Test
// @RELATION BINDS_TO -> [EXT:spec:StatsBar:Component]
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/StatsBar.svelte');

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

  it('renders 4 metric tiles', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('all');
    expect(src).toContain('without_mapping');
    expect(src).toContain('with_mapping');
    expect(src).toContain('linked_to_dashboards');
  });

  it('dispatches onfilter on tile click', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('onfilter');
    expect(src).toContain('handleTileClick');
    expect(src).toContain('activeFilter === tile.key');
  });

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

  it('uses aria-pressed for active state', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('aria-pressed');
  });

  it('uses $props for reactivity', () => {
    const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
    expect(src).toContain('$props()');
    expect(src).toContain('stats = null');
    expect(src).toContain('activeFilter');
  });
});
