import { describe, expect, it } from 'vitest';
import {
  LATEX_EDITOR_COMMAND_DEFINITIONS,
  findLatexEditorCommandDefinition,
  getLatexEditorCommandDefinition,
} from './editor-commands';

describe('R14.18 shared LaTeX editor command registry', () => {
  it('uses the same semantic identities for Source toolbar and Visual slash/left+ adapters', () => {
    const required = [
      'bold', 'italic', 'underline', 'section', 'subsection', 'itemize',
      'enumerate', 'inline-math', 'display-math', 'equation', 'figure', 'table',
      'citation', 'reference', 'label', 'footnote', 'hyperlink', 'newline',
    ];
    for (const id of required) {
      const command = getLatexEditorCommandDefinition(id);
      expect(command?.id).toBe(id);
      expect(command?.toolbar).toBe(true);
      expect(command?.slash.length).toBeGreaterThan(0);
    }
  });

  it('maps Visual structure commands through the shared registry rather than duplicate names', () => {
    expect(getLatexEditorCommandDefinition('section')?.visualInsert).toBe('section');
    expect(getLatexEditorCommandDefinition('itemize')?.visualInsert).toBe('bullet-list');
    expect(getLatexEditorCommandDefinition('inline-math')?.visualInsert).toBe('inline-math');
    expect(getLatexEditorCommandDefinition('display-math')?.visualInsert).toBe('display-math');
    expect(getLatexEditorCommandDefinition('label')?.visualInsert).toBe('label');
    expect(getLatexEditorCommandDefinition('newline')?.visualInsert).toBe('newline');
    expect(findLatexEditorCommandDefinition('hard-break')?.id).toBe('newline');
    expect(findLatexEditorCommandDefinition('cite')?.id).toBe('citation');
    expect(new Set(LATEX_EDITOR_COMMAND_DEFINITIONS.map((item) => item.id)).size)
      .toBe(LATEX_EDITOR_COMMAND_DEFINITIONS.length);
  });
});
