import { describe, it, expect } from 'vitest';
import { formatEmDashes } from '@/lib/text';

describe('formatEmDashes', () => {
  it('converts a double hyphen to an em-dash entity', () => {
    expect(formatEmDashes('True--his quick action ensured his coat remained immaculate.')).toBe(
      'True&mdash;his quick action ensured his coat remained immaculate.'
    );
  });

  it('converts every occurrence, not just the first', () => {
    expect(formatEmDashes('one--two--three')).toBe('one&mdash;two&mdash;three');
  });

  it('leaves a single hyphen alone', () => {
    expect(formatEmDashes('a well-known high-end velvet coat')).toBe(
      'a well-known high-end velvet coat'
    );
  });

  it('leaves text with no double hyphen untouched', () => {
    expect(formatEmDashes('Kikotu feels a surge of rage.')).toBe('Kikotu feels a surge of rage.');
  });

  it('preserves the <br> markup story packages carry', () => {
    expect(
      formatEmDashes('Evaluate this:<br />Somewhat true--the foliage repelled the rain.')
    ).toBe('Evaluate this:<br />Somewhat true&mdash;the foliage repelled the rain.');
  });

  it('returns an empty string for null or undefined', () => {
    expect(formatEmDashes(null)).toBe('');
    expect(formatEmDashes(undefined)).toBe('');
    expect(formatEmDashes()).toBe('');
  });
});
