import { describe, expect, it } from 'vitest';

import { ucfId } from '../ucf-id.js';

describe('ucfId', () => {
  const filePath = 'src/components/Button.tsx';
  const componentName = 'Button';
  const framework = 'react' as const;
  const sourceCommit = 'a'.repeat(40);

  it('returns a 16-character hex string', () => {
    const id = ucfId(filePath, componentName, framework, sourceCommit);
    expect(id).toHaveLength(16);
    expect(id).toMatch(/^[0-9a-f]{16}$/);
  });

  it('is idempotent across calls', () => {
    const a = ucfId(filePath, componentName, framework, sourceCommit);
    const b = ucfId(filePath, componentName, framework, sourceCommit);
    expect(a).toBe(b);
  });

  it('changes when filePath differs', () => {
    const a = ucfId('src/Button.tsx', componentName, framework, sourceCommit);
    const b = ucfId('src/IconButton.tsx', componentName, framework, sourceCommit);
    expect(a).not.toBe(b);
  });

  it('changes when componentName differs', () => {
    const a = ucfId(filePath, 'Button', framework, sourceCommit);
    const b = ucfId(filePath, 'PrimaryButton', framework, sourceCommit);
    expect(a).not.toBe(b);
  });

  it('changes when framework differs', () => {
    const a = ucfId(filePath, componentName, 'react', sourceCommit);
    const b = ucfId(filePath, componentName, 'vue', sourceCommit);
    expect(a).not.toBe(b);
  });

  it('changes when sourceCommit differs', () => {
    const a = ucfId(filePath, componentName, framework, 'a'.repeat(40));
    const b = ucfId(filePath, componentName, framework, 'b'.repeat(40));
    expect(a).not.toBe(b);
  });
});
