import { describe, test, expect } from 'vitest';
import { StarRating } from './StarRating';

const toHtml = (StarRating as any).toHtml;

describe('StarRating.toHtml accessibility (F2.2)', () => {
  test('wrapper has role="img" and a "Rating: N out of maxStars" aria-label', () => {
    const { html } = toHtml({ rating: 4.5, maxStars: 5 }, '');
    expect(html).toMatch(/<span role="img" aria-label="Rating: 4\.5 out of 5"/);
  });

  test('individual star glyphs are aria-hidden', () => {
    const { html } = toHtml({ rating: 3, maxStars: 5 }, '');
    const glyphs = html.match(/<i class="fa fa-star"[^>]*>/g) || [];
    expect(glyphs.length).toBeGreaterThan(0);
    glyphs.forEach((tag: string) => expect(tag).toContain('aria-hidden="true"'));
  });

  test('respects custom maxStars in the aria-label', () => {
    const { html } = toHtml({ rating: 2, maxStars: 10 }, '');
    expect(html).toContain('aria-label="Rating: 2 out of 10"');
  });
});
