import { describe, it, expect } from 'vitest';
import { generateIndex } from '../../src/generator/index-generator';

describe('generateIndex', () => {
  it('generates index file with imports and exports', () => {
    const ruleNames = ['no-ui-in-services', 'api-boundary-validation', 'no-cycles'];
    const result = generateIndex(ruleNames);

    // Check imports
    expect(result).toContain("import noUiInServices from './no-ui-in-services';");
    expect(result).toContain("import apiBoundaryValidation from './api-boundary-validation';");
    expect(result).toContain("import noCycles from './no-cycles';");

    // Check rules object
    expect(result).toContain("'no-ui-in-services': noUiInServices,");
    expect(result).toContain("'api-boundary-validation': apiBoundaryValidation,");
    expect(result).toContain("'no-cycles': noCycles,");

    // Check named exports
    expect(result).toContain('export { noUiInServices, apiBoundaryValidation, noCycles };');
  });

  it('handles single rule', () => {
    const ruleNames = ['only-rule'];
    const result = generateIndex(ruleNames);

    expect(result).toContain("import onlyRule from './only-rule';");
    expect(result).toContain("'only-rule': onlyRule,");
    expect(result).toContain('export { onlyRule };');
  });

  it('includes generation header comment', () => {
    const result = generateIndex(['test-rule']);
    expect(result).toContain('Generated by @harness-engineering/linter-gen');
    expect(result).toContain('Do not edit manually');
  });
});
