import { describe, it, expect } from 'vitest';
import BLOCK_DEFINITIONS from './index';

describe('BLOCK_DEFINITIONS', () => {
  const expectedTypes = [
    'paragraph',
    'heading1',
    'heading2',
    'heading3',
    'heading4',
    'heading5',
    'heading6',
    'bulletList',
    'numberedList',
    'blockquote',
    'codeBlock',
    'image',
    'file',
    'linkButton',
    'table',
    'columns1',
    'columns2',
    'columns3',
    'horizontalRule',
  ];

  it('19 種類すべての type を含む', () => {
    expect(Object.keys(BLOCK_DEFINITIONS).sort()).toEqual([...expectedTypes].sort());
  });

  it.each(expectedTypes)('%s が BlockDefinition の必須プロパティを満たす', (name) => {
    const def = BLOCK_DEFINITIONS[name];
    expect(def).toBeDefined();
    expect(typeof def.label).toBe('string');
    expect(def.label.length).toBeGreaterThan(0);
    expect(typeof def.icon).toBe('string');
    expect(def.icon.length).toBeGreaterThan(0);
    expect(typeof def.description).toBe('string');
    expect(typeof def.isTextMenu).toBe('boolean');
    expect(Array.isArray(def.aliases)).toBe(true);
    expect(typeof def.createActions).toBe('function');
  });

  it.each(expectedTypes)('%s.createActions が 4 つの関数を返す', (name) => {
    const def = BLOCK_DEFINITIONS[name];
    const cmd = {
      name,
      label: def.label,
      description: def.description,
      iconName: def.icon,
      isTextMenu: def.isTextMenu,
      isDisabled: () => false,
    };
    const actions = def.createActions(cmd, { recordUsage: () => {} });

    expect(typeof actions.action).toBe('function');
    expect(typeof actions.convert).toBe('function');
    expect(typeof actions.isDisabled).toBe('function');
    expect(typeof actions.isActive).toBe('function');
  });

  it('テキスト系 type の isTextMenu は true', () => {
    const textTypes = [
      'paragraph',
      'heading1',
      'heading2',
      'heading3',
      'heading4',
      'heading5',
      'heading6',
      'bulletList',
      'numberedList',
    ];
    for (const name of textTypes) {
      expect(BLOCK_DEFINITIONS[name].isTextMenu).toBe(true);
    }
  });

  it('ブロック系 type の isTextMenu は false', () => {
    const blockTypes = [
      'blockquote',
      'codeBlock',
      'image',
      'file',
      'linkButton',
      'table',
      'columns1',
      'columns2',
      'columns3',
      'horizontalRule',
    ];
    for (const name of blockTypes) {
      expect(BLOCK_DEFINITIONS[name].isTextMenu).toBe(false);
    }
  });
});
