import '@testing-library/jest-dom/vitest';
import { fireEvent, render, screen } from '@testing-library/svelte';
import { describe, expect, it, vi } from 'vitest';
import SuggestionList from './SuggestionList.svelte';

describe('SuggestionList', () => {
  it('requires explicit selection before confirmation', async () => {
    const onConfirm = vi.fn();
    render(SuggestionList, {
      props: {
        suggestions: [{ kind: 'task', title: '跟进报价', body: '联系客户' }],
        onConfirm,
      },
    });

    await fireEvent.click(screen.getByText('创建选中项'));
    expect(onConfirm).toHaveBeenCalledWith([]);

    await fireEvent.click(screen.getByLabelText('选择 跟进报价'));
    await fireEvent.click(screen.getByText('创建选中项'));
    expect(onConfirm).toHaveBeenLastCalledWith([
      { kind: 'task', title: '跟进报价', body: '联系客户' },
    ]);
  });
});
