import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import EntryCreateForm from './index';

// CategorySelect は SWR 経由のカテゴリー取得を持つため、Button の置き換え確認に不要な
// 非同期処理を避けるためスタブ化する
vi.mock('../../../category/components/category-select/category-select', () => ({
  default: () => <div data-testid="category-select-stub" />,
}));

describe('EntryCreateForm', () => {
  it('送信ボタンが Button コンポーネント由来の acms-admin-btn / acms-admin-btn-success クラスで描画される', () => {
    render(<EntryCreateForm blogId={1} />);

    const submitButton = screen.getByRole('button', { name: 'entry_index.entry_create_form.submit' });
    expect(submitButton).toHaveClass('acms-admin-btn', 'acms-admin-btn-success');
    expect(submitButton).toHaveAttribute('type', 'submit');
  });

  it('隠しフィールドに blogId 等の既存値が維持される', () => {
    render(<EntryCreateForm blogId={42} categoryId={7} />);

    const form = document.getElementById('entry-create-form') as HTMLFormElement;
    expect(form).toBeTruthy();
    expect((form.elements.namedItem('bid') as HTMLInputElement).value).toBe('42');
    expect((form.elements.namedItem('admin') as HTMLInputElement).value).toBe('entry_editor');
  });
});
